| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "net/base/x509_certificate.h" | 5 #include "net/base/x509_certificate.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 typedef std::map<SHA1Fingerprint, X509Certificate*, SHA1FingerprintLessThan> | 57 typedef std::map<SHA1Fingerprint, X509Certificate*, SHA1FingerprintLessThan> |
| 58 CertMap; | 58 CertMap; |
| 59 | 59 |
| 60 // Obtain an instance of X509CertificateCache via a LazyInstance. | 60 // Obtain an instance of X509CertificateCache via a LazyInstance. |
| 61 X509CertificateCache() {} | 61 X509CertificateCache() {} |
| 62 ~X509CertificateCache() {} | 62 ~X509CertificateCache() {} |
| 63 friend struct base::DefaultLazyInstanceTraits<X509CertificateCache>; | 63 friend struct base::DefaultLazyInstanceTraits<X509CertificateCache>; |
| 64 | 64 |
| 65 // You must acquire this lock before using any private data of this object. | 65 // You must acquire this lock before using any private data of this object. |
| 66 // You must not block while holding this lock. | 66 // You must not block while holding this lock. |
| 67 Lock lock_; | 67 base::Lock lock_; |
| 68 | 68 |
| 69 // The certificate cache. You must acquire |lock_| before using |cache_|. | 69 // The certificate cache. You must acquire |lock_| before using |cache_|. |
| 70 CertMap cache_; | 70 CertMap cache_; |
| 71 | 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(X509CertificateCache); | 72 DISALLOW_COPY_AND_ASSIGN(X509CertificateCache); |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 base::LazyInstance<X509CertificateCache, | 75 base::LazyInstance<X509CertificateCache, |
| 76 base::LeakyLazyInstanceTraits<X509CertificateCache> > | 76 base::LeakyLazyInstanceTraits<X509CertificateCache> > |
| 77 g_x509_certificate_cache(base::LINKER_INITIALIZED); | 77 g_x509_certificate_cache(base::LINKER_INITIALIZED); |
| 78 | 78 |
| 79 // Insert |cert| into the cache. The cache does NOT AddRef |cert|. | 79 // Insert |cert| into the cache. The cache does NOT AddRef |cert|. |
| 80 // Any existing certificate with the same fingerprint will be replaced. | 80 // Any existing certificate with the same fingerprint will be replaced. |
| 81 void X509CertificateCache::Insert(X509Certificate* cert) { | 81 void X509CertificateCache::Insert(X509Certificate* cert) { |
| 82 AutoLock lock(lock_); | 82 base::AutoLock lock(lock_); |
| 83 | 83 |
| 84 DCHECK(!IsNullFingerprint(cert->fingerprint())) << | 84 DCHECK(!IsNullFingerprint(cert->fingerprint())) << |
| 85 "Only insert certs with real fingerprints."; | 85 "Only insert certs with real fingerprints."; |
| 86 cache_[cert->fingerprint()] = cert; | 86 cache_[cert->fingerprint()] = cert; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 // Remove |cert| from the cache. The cache does not assume that |cert| is | 89 // Remove |cert| from the cache. The cache does not assume that |cert| is |
| 90 // already in the cache. | 90 // already in the cache. |
| 91 void X509CertificateCache::Remove(X509Certificate* cert) { | 91 void X509CertificateCache::Remove(X509Certificate* cert) { |
| 92 AutoLock lock(lock_); | 92 base::AutoLock lock(lock_); |
| 93 | 93 |
| 94 CertMap::iterator pos(cache_.find(cert->fingerprint())); | 94 CertMap::iterator pos(cache_.find(cert->fingerprint())); |
| 95 if (pos == cache_.end()) | 95 if (pos == cache_.end()) |
| 96 return; // It is not an error to remove a cert that is not in the cache. | 96 return; // It is not an error to remove a cert that is not in the cache. |
| 97 cache_.erase(pos); | 97 cache_.erase(pos); |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 // Find a certificate in the cache with the given fingerprint. If one does | 100 // Find a certificate in the cache with the given fingerprint. If one does |
| 101 // not exist, this method returns NULL. | 101 // not exist, this method returns NULL. |
| 102 X509Certificate* X509CertificateCache::Find( | 102 X509Certificate* X509CertificateCache::Find( |
| 103 const SHA1Fingerprint& fingerprint) { | 103 const SHA1Fingerprint& fingerprint) { |
| 104 AutoLock lock(lock_); | 104 base::AutoLock lock(lock_); |
| 105 | 105 |
| 106 CertMap::iterator pos(cache_.find(fingerprint)); | 106 CertMap::iterator pos(cache_.find(fingerprint)); |
| 107 if (pos == cache_.end()) | 107 if (pos == cache_.end()) |
| 108 return NULL; | 108 return NULL; |
| 109 | 109 |
| 110 return pos->second; | 110 return pos->second; |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 } // namespace | 113 } // namespace |
| 114 | 114 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 339 |
| 340 bool X509Certificate::HasIntermediateCertificates(const OSCertHandles& certs) { | 340 bool X509Certificate::HasIntermediateCertificates(const OSCertHandles& certs) { |
| 341 for (size_t i = 0; i < certs.size(); ++i) { | 341 for (size_t i = 0; i < certs.size(); ++i) { |
| 342 if (!HasIntermediateCertificate(certs[i])) | 342 if (!HasIntermediateCertificate(certs[i])) |
| 343 return false; | 343 return false; |
| 344 } | 344 } |
| 345 return true; | 345 return true; |
| 346 } | 346 } |
| 347 | 347 |
| 348 } // namespace net | 348 } // namespace net |
| OLD | NEW |