| OLD | NEW |
| (Empty) |
| 1 // Copyright 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 // DiskBasedCertCache is used to store and retrieve X.509 certificates from the | |
| 23 // cache. Each individual certificate is stored separately from its certificate | |
| 24 // chain. No more than one copy (per certificate) will be stored on disk. | |
| 25 class NET_EXPORT_PRIVATE DiskBasedCertCache { | |
| 26 public: | |
| 27 typedef base::Callback<void(const X509Certificate::OSCertHandle cert_handle)> | |
| 28 GetCallback; | |
| 29 typedef base::Callback<void(const std::string&)> SetCallback; | |
| 30 | |
| 31 // Initializes a new DiskBasedCertCache that will use |backend|, which has | |
| 32 // previously been initialized, to store the certificate in the cache. | |
| 33 explicit DiskBasedCertCache(disk_cache::Backend* backend); | |
| 34 ~DiskBasedCertCache(); | |
| 35 | |
| 36 // Fetches the certificate associated with |key|. If the certificate is | |
| 37 // found within the cache, |cb| will be called with the certificate. | |
| 38 // Otherwise, |cb| will be called with NULL. Callers that wish to store | |
| 39 // a reference to the certificate need to use X509Certificate::DupOSCertHandle | |
| 40 // inside |cb|. | |
| 41 void Get(const std::string& key, const GetCallback& cb); | |
| 42 | |
| 43 // 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 // string, then |cert_handle| was not stored. | |
| 46 void Set(const X509Certificate::OSCertHandle cert_handle, | |
| 47 const SetCallback& cb); | |
| 48 | |
| 49 private: | |
| 50 class ReadWorker; | |
| 51 class WriteWorker; | |
| 52 | |
| 53 // ReadWorkerMap and WriteWorkerMap map cache keys to their | |
| 54 // corresponding Workers. | |
| 55 typedef base::hash_map<std::string, ReadWorker*> ReadWorkerMap; | |
| 56 typedef base::hash_map<std::string, WriteWorker*> WriteWorkerMap; | |
| 57 | |
| 58 // FinishedReadOperation and FinishedWriteOperation are used by callbacks | |
| 59 // given to the workers to signal the DiskBasedCertCache they have completed | |
| 60 // their work. | |
| 61 void FinishedReadOperation(const std::string& key); | |
| 62 void FinishedWriteOperation(const std::string& key); | |
| 63 | |
| 64 ReadWorkerMap read_worker_map_; | |
| 65 WriteWorkerMap write_worker_map_; | |
| 66 | |
| 67 disk_cache::Backend* backend_; | |
| 68 base::WeakPtrFactory<DiskBasedCertCache> weak_factory_; | |
| 69 DISALLOW_COPY_AND_ASSIGN(DiskBasedCertCache); | |
| 70 }; | |
| 71 | |
| 72 } // namespace net | |
| 73 | |
| 74 #endif // NET_HTTP_DISK_BASED_CERT_CACHE_H | |
| OLD | NEW |