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 // These functions intended for testing purposes only. | |
wtc
2014/07/02 20:51:50
Nit: please document what they return.
Ryan Sleevi
2014/07/02 21:49:58
For testing, we prefer to use friend classes to a
rvargas (doing something else)
2014/07/02 22:14:39
nit: If it is important that the methods should be
| |
51 int MemCacheHits() { return mem_cache_hits_; } | |
52 int MemCacheMisses() { return mem_cache_misses_; } | |
wtc
2014/07/02 20:51:50
1. These methods should be declared const.
2. The
Ryan Sleevi
2014/07/02 21:49:58
http://www.chromium.org/developers/coding-style#TO
| |
53 | |
49 private: | 54 private: |
50 class ReadWorker; | 55 class ReadWorker; |
51 class WriteWorker; | 56 class WriteWorker; |
52 | 57 |
58 // A functor used to free an OSCertHandle. Used by the MRUCertCache. | |
59 class CertFree { | |
60 public: | |
61 void operator()(X509Certificate::OSCertHandle cert_handle) { | |
62 X509Certificate::FreeOSCertHandle(cert_handle); | |
63 } | |
64 }; | |
Ryan Sleevi
2014/07/02 21:49:58
You should be able to just declare this class, and
| |
65 | |
66 // An in-memory cache that is used to prevent redundant reads and writes | |
67 // to and from the disk cache. | |
68 typedef base::MRUCacheBase<std::string, | |
69 X509Certificate::OSCertHandle, | |
70 CertFree> MRUCertCache; | |
71 | |
53 // ReadWorkerMap and WriteWorkerMap map cache keys to their | 72 // ReadWorkerMap and WriteWorkerMap map cache keys to their |
54 // corresponding Workers. | 73 // corresponding Workers. |
55 typedef base::hash_map<std::string, ReadWorker*> ReadWorkerMap; | 74 typedef base::hash_map<std::string, ReadWorker*> ReadWorkerMap; |
56 typedef base::hash_map<std::string, WriteWorker*> WriteWorkerMap; | 75 typedef base::hash_map<std::string, WriteWorker*> WriteWorkerMap; |
57 | 76 |
58 // FinishedReadOperation and FinishedWriteOperation are used by callbacks | 77 // FinishedReadOperation and FinishedWriteOperation are used by callbacks |
59 // given to the workers to signal the DiskBasedCertCache they have completed | 78 // given to the workers to signal the DiskBasedCertCache they have completed |
60 // their work. | 79 // their work. |
61 void FinishedReadOperation(const std::string& key); | 80 void FinishedReadOperation(const std::string& key, |
62 void FinishedWriteOperation(const std::string& key); | 81 X509Certificate::OSCertHandle cert_handle); |
82 void FinishedWriteOperation(const std::string& key, | |
83 X509Certificate::OSCertHandle cert_handle); | |
84 | |
85 disk_cache::Backend* backend_; | |
63 | 86 |
64 ReadWorkerMap read_worker_map_; | 87 ReadWorkerMap read_worker_map_; |
65 WriteWorkerMap write_worker_map_; | 88 WriteWorkerMap write_worker_map_; |
89 MRUCertCache mru_cert_cache_; | |
wtc
2014/07/02 20:51:50
Ricardo: does the disk cache already have an inter
rvargas (doing something else)
2014/07/02 22:14:39
no, it doesn't
| |
66 | 90 |
67 disk_cache::Backend* backend_; | 91 int mem_cache_hits_; |
92 int mem_cache_misses_; | |
93 | |
68 base::WeakPtrFactory<DiskBasedCertCache> weak_factory_; | 94 base::WeakPtrFactory<DiskBasedCertCache> weak_factory_; |
69 DISALLOW_COPY_AND_ASSIGN(DiskBasedCertCache); | 95 DISALLOW_COPY_AND_ASSIGN(DiskBasedCertCache); |
70 }; | 96 }; |
71 | 97 |
72 } // namespace net | 98 } // namespace net |
73 | 99 |
74 #endif // NET_HTTP_DISK_BASED_CERT_CACHE_H | 100 #endif // NET_HTTP_DISK_BASED_CERT_CACHE_H |
OLD | NEW |