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_
11 #include "base/containers/scoped_ptr_map.h"
12 #include "base/macros.h"
13 #include "base/synchronization/lock.h"
14 #include "chrome/browser/chromeos/certificate_provider/certificate_info.h"
17 class SHA256HashValueLessThan
;
18 class X509Certificate
;
19 struct SHA256HashValue
;
23 namespace certificate_provider
{
25 class ThreadSafeCertificateMap
{
28 MapValue(const CertificateInfo
& cert_info
, const std::string
& extension_id
);
31 CertificateInfo cert_info
;
32 std::string extension_id
;
34 using FingerprintToCertAndExtensionMap
=
35 base::ScopedPtrMap
<net::SHA256HashValue
,
37 net::SHA256HashValueLessThan
>;
39 ThreadSafeCertificateMap();
40 ~ThreadSafeCertificateMap();
42 // Updates the stored certificates with the given mapping from extension ids
44 void Update(const std::map
<std::string
, CertificateInfoList
>&
45 extension_to_certificates
);
47 // Looks up the given certificate. If the certificate was added by any
48 // previous Update() call, returns true.
49 // If this certificate was provided in the most recent Update() call,
50 // |is_currently_provided| will be set to true, |extension_id| be set to that
51 // extension's id and |info| will be set to the stored info. Otherwise, if
52 // this certificate was not provided in the the most recent Update() call,
53 // sets |is_currently_provided| to false and doesn't modify |info| and
55 bool LookUpCertificate(const net::X509Certificate
& cert
,
56 bool* is_currently_provided
,
57 CertificateInfo
* info
,
58 std::string
* extension_id
);
60 // Remove every association of stored certificates to the given extension.
61 // The certificates themselves will be remembered.
62 void RemoveExtension(const std::string
& extension_id
);
66 FingerprintToCertAndExtensionMap fingerprint_to_cert_and_extension_
;
68 DISALLOW_COPY_AND_ASSIGN(ThreadSafeCertificateMap
);
71 } // namespace certificate_provider
72 } // namespace chromeos
74 #endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_THREAD_SAFE_CERTIFICATE_MAP_H_