OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_HTTP_DISK_BASED_CERT_CACHE_H | |
6 #define NET_HTTP_DISK_BASED_CERT_CACHE_H | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/containers/hash_tables.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "net/base/net_export.h" | |
14 #include "net/cert/x509_certificate.h" | |
15 | |
16 namespace disk_cache { | |
17 class Backend; | |
18 } // namespace disk_cache | |
19 | |
20 namespace net { | |
21 | |
22 class NET_EXPORT_PRIVATE DiskBasedCertCache { | |
wtc
2014/06/20 01:27:07
Please add a comment to summarize what this class
| |
23 public: | |
24 typedef base::Callback<void(const X509Certificate::OSCertHandle cert_handle)> | |
25 GetCallback; | |
26 typedef base::Callback<void(const std::string&)> SetCallback; | |
27 | |
28 // Constructor takes in a previously initialized backend, which is then | |
29 // used to store the certificates in the cache. | |
30 explicit DiskBasedCertCache(disk_cache::Backend* backend); | |
31 ~DiskBasedCertCache(); | |
32 | |
33 // Fetches the certificate associated with |key|. If the certificate is | |
34 // found within the cache, |cb| will be called with the certificate. | |
35 // Otherwise, |cb| will be called with NULL. Callers that wish to store | |
36 // a copy should use X509Certificate::DupOSCertHandle. | |
wtc
2014/06/20 01:27:07
"store a copy" is not clear. I suggest something t
| |
37 void Get(const std::string& key, const GetCallback& cb); | |
38 | |
39 // Stores |cert_handle| in the cache. If |cert_handle| is successfully stored, | |
40 // |cb| will be called with the key. If |cb| is called with an empty | |
41 // string, then |cert_handle| was not stored. | |
42 void Set(const X509Certificate::OSCertHandle cert_handle, | |
43 const SetCallback& cb); | |
44 | |
45 private: | |
46 class ReadWorker; | |
47 class WriteWorker; | |
48 | |
49 typedef base::hash_map<std::string, ReadWorker*> ReadWorkerMap; | |
50 typedef base::hash_map<std::string, WriteWorker*> WriteWorkerMap; | |
wtc
2014/06/20 01:27:07
Nit: document what the std::string is. (I guess it
| |
51 | |
52 // FinishedReadOperation and FinishedWriteOperation are used by callbacks | |
53 // given to the workers to signal the DiskBasedCertCache they have completed | |
54 // their work. The workers are then deleted and removed from their respective | |
55 // hash maps. | |
56 void FinishedReadOperation(const std::string& key); | |
57 void FinishedWriteOperation(const std::string& key); | |
58 | |
59 ReadWorkerMap read_worker_map_; | |
60 WriteWorkerMap write_worker_map_; | |
61 | |
62 disk_cache::Backend* backend_; | |
63 base::WeakPtrFactory<DiskBasedCertCache> weak_factory_; | |
64 DISALLOW_COPY_AND_ASSIGN(DiskBasedCertCache); | |
65 }; | |
66 | |
67 } // namespace net | |
68 | |
69 #endif // NET_HTTP_DISK_BASED_CERT_CACHE_H | |
OLD | NEW |