Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / chromeos / certificate_provider / thread_safe_certificate_map.h
blob15f04429a34f8ed6064fc043580e9bc99deec5c9
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_THREAD_SAFE_CERTIFICATE_MAP_H_
6 #define CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_THREAD_SAFE_CERTIFICATE_MAP_H_
8 #include <map>
9 #include <string>
11 #include "base/macros.h"
12 #include "base/synchronization/lock.h"
13 #include "chrome/browser/chromeos/certificate_provider/certificate_info.h"
15 namespace net {
16 class SHA256HashValueLessThan;
17 class X509Certificate;
18 struct SHA256HashValue;
21 namespace chromeos {
22 namespace certificate_provider {
24 class ThreadSafeCertificateMap {
25 public:
26 using FingerprintToCertMap = std::map<net::SHA256HashValue,
27 CertificateInfo,
28 net::SHA256HashValueLessThan>;
29 using ExtensionToFingerprintsMap =
30 std::map<std::string, FingerprintToCertMap>;
32 ThreadSafeCertificateMap();
33 ~ThreadSafeCertificateMap();
35 // Replaces the stored certificates by the given certificates.
36 void Update(const std::map<std::string, CertificateInfoList>&
37 extension_to_certificates);
39 // Looks up the given certificate. If found, it returns true and sets
40 // |extension_id| to the extension id for which this certificate was
41 // registered and sets |info| to the stored info. Otherwise returns false and
42 // doesn't modify |info| and |extension_id|.
43 bool LookUpCertificate(const net::X509Certificate& cert,
44 CertificateInfo* info,
45 std::string* extension_id);
47 // Remove all certificates that are currently registered for the given
48 // extension.
49 void RemoveExtension(const std::string& extension_id);
51 private:
52 base::Lock lock_;
53 ExtensionToFingerprintsMap extension_to_certificates_;
55 DISALLOW_COPY_AND_ASSIGN(ThreadSafeCertificateMap);
58 } // namespace certificate_provider
59 } // namespace chromeos
61 #endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_THREAD_SAFE_CERTIFICATE_MAP_H_