Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 NET_HTTP_DISK_BASED_CERT_CACHE_H | 5 #ifndef NET_HTTP_DISK_BASED_CERT_CACHE_H |
| 6 #define NET_HTTP_DISK_BASED_CERT_CACHE_H | 6 #define NET_HTTP_DISK_BASED_CERT_CACHE_H |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/containers/mru_cache.h" | |
| 12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 13 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
| 14 #include "net/cert/x509_certificate.h" | 15 #include "net/cert/x509_certificate.h" |
| 15 | 16 |
| 16 namespace disk_cache { | 17 namespace disk_cache { |
| 17 class Backend; | 18 class Backend; |
| 18 } // namespace disk_cache | 19 } // namespace disk_cache |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 | 22 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 39 // a reference to the certificate need to use X509Certificate::DupOSCertHandle | 40 // a reference to the certificate need to use X509Certificate::DupOSCertHandle |
| 40 // inside |cb|. | 41 // inside |cb|. |
| 41 void Get(const std::string& key, const GetCallback& cb); | 42 void Get(const std::string& key, const GetCallback& cb); |
| 42 | 43 |
| 43 // Stores |cert_handle| in the cache. If |cert_handle| is successfully stored, | 44 // Stores |cert_handle| in the cache. If |cert_handle| is successfully stored, |
| 44 // |cb| will be called with the key. If |cb| is called with an empty | 45 // |cb| will be called with the key. If |cb| is called with an empty |
| 45 // string, then |cert_handle| was not stored. | 46 // string, then |cert_handle| was not stored. |
| 46 void Set(const X509Certificate::OSCertHandle cert_handle, | 47 void Set(const X509Certificate::OSCertHandle cert_handle, |
| 47 const SetCallback& cb); | 48 const SetCallback& cb); |
| 48 | 49 |
| 50 // Returns the number of in-memory MRU cache hits that have occured | |
|
wtc
2014/07/03 02:37:13
Nit: occured => occurred
Also on line 54.
| |
| 51 // on Set and Get operations. Intended for test purposes only. | |
| 52 size_t mem_cache_hits_for_testing() const { return mem_cache_hits_; } | |
| 53 | |
| 54 // Returns the number of in-memory MRU cache misses that have occured | |
| 55 // on Set and Get operations. Intended for test purposes only. | |
| 56 size_t mem_cache_misses_for_testing() const { return mem_cache_misses_; } | |
| 57 | |
| 49 private: | 58 private: |
| 50 class ReadWorker; | 59 class ReadWorker; |
| 51 class WriteWorker; | 60 class WriteWorker; |
| 52 | 61 |
| 62 // A functor used to free an OSCertHandle. Used by the MRUCertCache. | |
| 63 struct CertFree { | |
| 64 void operator()(X509Certificate::OSCertHandle cert_handle); | |
| 65 }; | |
| 66 | |
| 67 // An in-memory cache that is used to prevent redundant reads and writes | |
| 68 // to and from the disk cache. | |
| 69 typedef base::MRUCacheBase<std::string, | |
| 70 X509Certificate::OSCertHandle, | |
| 71 CertFree> MRUCertCache; | |
| 72 | |
| 53 // ReadWorkerMap and WriteWorkerMap map cache keys to their | 73 // ReadWorkerMap and WriteWorkerMap map cache keys to their |
| 54 // corresponding Workers. | 74 // corresponding Workers. |
| 55 typedef base::hash_map<std::string, ReadWorker*> ReadWorkerMap; | 75 typedef base::hash_map<std::string, ReadWorker*> ReadWorkerMap; |
| 56 typedef base::hash_map<std::string, WriteWorker*> WriteWorkerMap; | 76 typedef base::hash_map<std::string, WriteWorker*> WriteWorkerMap; |
| 57 | 77 |
| 58 // FinishedReadOperation and FinishedWriteOperation are used by callbacks | 78 // FinishedReadOperation and FinishedWriteOperation are used by callbacks |
| 59 // given to the workers to signal the DiskBasedCertCache they have completed | 79 // given to the workers to signal the DiskBasedCertCache they have completed |
| 60 // their work. | 80 // their work. |
| 61 void FinishedReadOperation(const std::string& key); | 81 void FinishedReadOperation(const std::string& key, |
| 62 void FinishedWriteOperation(const std::string& key); | 82 X509Certificate::OSCertHandle cert_handle); |
| 83 void FinishedWriteOperation(const std::string& key, | |
| 84 X509Certificate::OSCertHandle cert_handle); | |
| 85 | |
| 86 disk_cache::Backend* backend_; | |
| 63 | 87 |
| 64 ReadWorkerMap read_worker_map_; | 88 ReadWorkerMap read_worker_map_; |
| 65 WriteWorkerMap write_worker_map_; | 89 WriteWorkerMap write_worker_map_; |
| 90 MRUCertCache mru_cert_cache_; | |
| 66 | 91 |
| 67 disk_cache::Backend* backend_; | 92 int mem_cache_hits_; |
| 93 int mem_cache_misses_; | |
| 94 | |
| 68 base::WeakPtrFactory<DiskBasedCertCache> weak_factory_; | 95 base::WeakPtrFactory<DiskBasedCertCache> weak_factory_; |
| 69 DISALLOW_COPY_AND_ASSIGN(DiskBasedCertCache); | 96 DISALLOW_COPY_AND_ASSIGN(DiskBasedCertCache); |
| 70 }; | 97 }; |
| 71 | 98 |
| 72 } // namespace net | 99 } // namespace net |
| 73 | 100 |
| 74 #endif // NET_HTTP_DISK_BASED_CERT_CACHE_H | 101 #endif // NET_HTTP_DISK_BASED_CERT_CACHE_H |
| OLD | NEW |