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

Side by Side Diff: net/http/disk_based_cert_cache.h

Issue 361513003: Improving and adding an in-memory MRU cache to DiskBasedCertCache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@DBCC_Implement
Patch Set: Improved documentation. Created 6 years, 5 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
« no previous file with comments | « no previous file | net/http/disk_based_cert_cache.cc » ('j') | net/http/disk_based_cert_cache.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 21 matching lines...) Expand all
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
49 private: 50 private:
50 class ReadWorker; 51 class ReadWorker;
51 class WriteWorker; 52 class WriteWorker;
52 53
54 // A functor used to free an OSCertHandle. Used by the MRUCertCache.
55 class CertFree {
56 public:
57 void operator()(X509Certificate::OSCertHandle cert_handle) {
58 X509Certificate::FreeOSCertHandle(cert_handle);
59 }
60 };
61
62 // An in-memory cache that is used to prevent redundant reads and writes
63 // to and from the disk cache.
64 class MRUCertCache : public base::MRUCacheBase<std::string,
wtc 2014/07/01 02:11:31 Since MRUCertCache doesn't have any new method or
65 X509Certificate::OSCertHandle,
66 CertFree> {
67 private:
68 typedef base::MRUCacheBase<std::string,
69 X509Certificate::OSCertHandle,
70 CertFree> ParentType;
71
72 public:
73 // |max_size| is the maximum number of OSCertHandles to be stored
74 // at one time.
75 explicit MRUCertCache(typename ParentType::size_type max_size)
76 : ParentType(max_size) {}
77
78 private:
79 DISALLOW_COPY_AND_ASSIGN(MRUCertCache);
80 };
81
53 // ReadWorkerMap and WriteWorkerMap map cache keys to their 82 // ReadWorkerMap and WriteWorkerMap map cache keys to their
54 // corresponding Workers. 83 // corresponding Workers.
55 typedef base::hash_map<std::string, ReadWorker*> ReadWorkerMap; 84 typedef base::hash_map<std::string, ReadWorker*> ReadWorkerMap;
56 typedef base::hash_map<std::string, WriteWorker*> WriteWorkerMap; 85 typedef base::hash_map<std::string, WriteWorker*> WriteWorkerMap;
57 86
58 // FinishedReadOperation and FinishedWriteOperation are used by callbacks 87 // FinishedReadOperation and FinishedWriteOperation are used by callbacks
59 // given to the workers to signal the DiskBasedCertCache they have completed 88 // given to the workers to signal the DiskBasedCertCache they have completed
60 // their work. 89 // their work. FinishedReadOperation also stores the retrieved OSCertHandle
61 void FinishedReadOperation(const std::string& key); 90 // in |mru_cert_cache_|.
91 void FinishedReadOperation(const std::string& key,
92 X509Certificate::OSCertHandle cert_handle);
62 void FinishedWriteOperation(const std::string& key); 93 void FinishedWriteOperation(const std::string& key);
63 94
95 disk_cache::Backend* backend_;
96
64 ReadWorkerMap read_worker_map_; 97 ReadWorkerMap read_worker_map_;
65 WriteWorkerMap write_worker_map_; 98 WriteWorkerMap write_worker_map_;
99 MRUCertCache mru_cert_cache_;
66 100
67 disk_cache::Backend* backend_;
68 base::WeakPtrFactory<DiskBasedCertCache> weak_factory_; 101 base::WeakPtrFactory<DiskBasedCertCache> weak_factory_;
69 DISALLOW_COPY_AND_ASSIGN(DiskBasedCertCache); 102 DISALLOW_COPY_AND_ASSIGN(DiskBasedCertCache);
70 }; 103 };
71 104
72 } // namespace net 105 } // namespace net
73 106
74 #endif // NET_HTTP_DISK_BASED_CERT_CACHE_H 107 #endif // NET_HTTP_DISK_BASED_CERT_CACHE_H
OLDNEW
« no previous file with comments | « no previous file | net/http/disk_based_cert_cache.cc » ('j') | net/http/disk_based_cert_cache.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698