Index: net/http/disk_based_cert_cache.cc |
diff --git a/net/http/disk_based_cert_cache.cc b/net/http/disk_based_cert_cache.cc |
index 606407999e65eb9339f67504aca2f1fb924573bf..df9f7ae2c9950ebf580c35dae0f6f5215efd34bf 100644 |
--- a/net/http/disk_based_cert_cache.cc |
+++ b/net/http/disk_based_cert_cache.cc |
@@ -9,6 +9,7 @@ |
#include "base/bind.h" |
#include "base/callback_helpers.h" |
#include "base/memory/ref_counted.h" |
+#include "base/metrics/histogram.h" |
#include "base/stl_util.h" |
#include "base/strings/string_number_conversions.h" |
#include "net/base/io_buffer.h" |
@@ -24,7 +25,8 @@ const size_t kMemoryCacheMaxSize = 30; |
// Used to obtain a unique cache key for a certificate in the form of |
// "cert:<hash>". |
-std::string GetCacheKeyToCert(const X509Certificate::OSCertHandle cert_handle) { |
+std::string GetCacheKeyForCert( |
+ const X509Certificate::OSCertHandle cert_handle) { |
SHA1HashValue fingerprint = |
X509Certificate::CalculateFingerprint(cert_handle); |
@@ -32,6 +34,14 @@ std::string GetCacheKeyToCert(const X509Certificate::OSCertHandle cert_handle) { |
base::HexEncode(fingerprint.data, arraysize(fingerprint.data)); |
} |
+void RecordMemCacheHit(bool hit) { |
+ UMA_HISTOGRAM_BOOLEAN("DiskBasedCertCache.MemCacheHit", hit); |
+} |
+ |
+void RecordDiskCacheHit(bool hit) { |
+ UMA_HISTOGRAM_BOOLEAN("DiskBasedCertCache.DiskCacheHit", hit); |
+} |
+ |
} // namespace |
// WriteWorkers represent pending Set jobs in the DiskBasedCertCache. Each |
@@ -123,7 +133,8 @@ DiskBasedCertCache::WriteWorker::WriteWorker( |
} |
DiskBasedCertCache::WriteWorker::~WriteWorker() { |
- X509Certificate::FreeOSCertHandle(cert_handle_); |
+ if (cert_handle_) |
+ X509Certificate::FreeOSCertHandle(cert_handle_); |
if (entry_) |
entry_->Close(); |
} |
@@ -428,8 +439,14 @@ int DiskBasedCertCache::ReadWorker::DoOpen() { |
} |
int DiskBasedCertCache::ReadWorker::DoOpenComplete(int rv) { |
- if (rv < 0) |
+ if (rv < 0) { |
+ // Errors other than CACHE_MISS are not recorded as either a hit |
wtc
2014/07/09 21:07:36
Nit: I prefer either the original "cache miss" or
|
+ // or a miss. |
+ if (rv == ERR_CACHE_MISS) |
+ RecordDiskCacheHit(false); |
return rv; |
+ } |
+ RecordDiskCacheHit(true); |
state_ = STATE_READ; |
return OK; |
@@ -506,10 +523,12 @@ void DiskBasedCertCache::Get(const std::string& key, const GetCallback& cb) { |
// list in the MRU cache. |
MRUCertCache::iterator mru_it = mru_cert_cache_.Get(key); |
if (mru_it != mru_cert_cache_.end()) { |
+ RecordMemCacheHit(true); |
++mem_cache_hits_; |
cb.Run(mru_it->second); |
return; |
} |
+ RecordMemCacheHit(false); |
++mem_cache_misses_; |
ReadWorkerMap::iterator it = read_worker_map_.find(key); |
@@ -533,7 +552,7 @@ void DiskBasedCertCache::Set(const X509Certificate::OSCertHandle cert_handle, |
const SetCallback& cb) { |
DCHECK(!cb.is_null()); |
DCHECK(cert_handle); |
- std::string key = GetCacheKeyToCert(cert_handle); |
+ std::string key = GetCacheKeyForCert(cert_handle); |
WriteWorkerMap::iterator it = write_worker_map_.find(key); |