Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: chrome/browser/chromeos/certificate_provider/thread_safe_certificate_map.h

Issue 1330003002: CertificateProviderService: Expose certificate lookup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scoped_ptr_map
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_THREAD_SAFE_CERTIFICATE_MAP _H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_THREAD_SAFE_CERTIFICATE_MAP _H_
6 #define CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_THREAD_SAFE_CERTIFICATE_MAP _H_ 6 #define CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_THREAD_SAFE_CERTIFICATE_MAP _H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/containers/scoped_ptr_map.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
13 #include "chrome/browser/chromeos/certificate_provider/certificate_info.h" 14 #include "chrome/browser/chromeos/certificate_provider/certificate_info.h"
14 15
15 namespace net { 16 namespace net {
16 class SHA256HashValueLessThan; 17 class SHA256HashValueLessThan;
17 class X509Certificate; 18 class X509Certificate;
18 struct SHA256HashValue; 19 struct SHA256HashValue;
19 } 20 }
20 21
21 namespace chromeos { 22 namespace chromeos {
22 namespace certificate_provider { 23 namespace certificate_provider {
23 24
24 class ThreadSafeCertificateMap { 25 class ThreadSafeCertificateMap {
25 public: 26 public:
26 using FingerprintToCertMap = std::map<net::SHA256HashValue, 27 struct MapValue {
27 CertificateInfo, 28 MapValue(const CertificateInfo& cert_info, const std::string& extension_id);
28 net::SHA256HashValueLessThan>; 29 ~MapValue();
29 using ExtensionToFingerprintsMap = 30
30 std::map<std::string, FingerprintToCertMap>; 31 CertificateInfo cert_info;
32 std::string extension_id;
33 };
34 using FingerprintToCertAndExtensionMap =
35 base::ScopedPtrMap<net::SHA256HashValue,
36 scoped_ptr<MapValue>,
37 net::SHA256HashValueLessThan>;
31 38
32 ThreadSafeCertificateMap(); 39 ThreadSafeCertificateMap();
33 ~ThreadSafeCertificateMap(); 40 ~ThreadSafeCertificateMap();
34 41
35 // Replaces the stored certificates by the given certificates. 42 // Updates the stored certificates with the given mapping from extension ids
43 // to certificates.
36 void Update(const std::map<std::string, CertificateInfoList>& 44 void Update(const std::map<std::string, CertificateInfoList>&
37 extension_to_certificates); 45 extension_to_certificates);
38 46
39 // Looks up the given certificate. If found, it returns true and sets 47 // Looks up the given certificate. If the certificate was added by any
40 // |extension_id| to the extension id for which this certificate was 48 // previous Update() call, returns true.
41 // registered and sets |info| to the stored info. Otherwise returns false and 49 // If this certificate was provided in the most recent Update() call,
42 // doesn't modify |info| and |extension_id|. 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
54 // |extension_id|.
43 bool LookUpCertificate(const net::X509Certificate& cert, 55 bool LookUpCertificate(const net::X509Certificate& cert,
56 bool* is_currently_provided,
44 CertificateInfo* info, 57 CertificateInfo* info,
45 std::string* extension_id); 58 std::string* extension_id);
46 59
47 // Remove all certificates that are currently registered for the given 60 // Remove every association of stored certificates to the given extension.
48 // extension. 61 // The certificates themselves will be remembered.
49 void RemoveExtension(const std::string& extension_id); 62 void RemoveExtension(const std::string& extension_id);
50 63
51 private: 64 private:
52 base::Lock lock_; 65 base::Lock lock_;
53 ExtensionToFingerprintsMap extension_to_certificates_; 66 FingerprintToCertAndExtensionMap fingerprint_to_cert_and_extension_;
54 67
55 DISALLOW_COPY_AND_ASSIGN(ThreadSafeCertificateMap); 68 DISALLOW_COPY_AND_ASSIGN(ThreadSafeCertificateMap);
56 }; 69 };
57 70
58 } // namespace certificate_provider 71 } // namespace certificate_provider
59 } // namespace chromeos 72 } // namespace chromeos
60 73
61 #endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_THREAD_SAFE_CERTIFICATE_ MAP_H_ 74 #endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_THREAD_SAFE_CERTIFICATE_ MAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698