Chromium Code Reviews| 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 #include "net/http/disk_based_cert_cache.h" | 5 #include "net/http/disk_based_cert_cache.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/metrics/histogram.h" | |
| 12 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
| 15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 16 #include "net/disk_cache/disk_cache.h" | 17 #include "net/disk_cache/disk_cache.h" |
| 17 | 18 |
| 18 namespace net { | 19 namespace net { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 23 // TODO(brandonsalmon): remove when more data no longer needed. | |
| 24 void RecordHistogram(int rv) { | |
| 25 bool already_existed = (rv < 0); | |
| 26 UMA_HISTOGRAM_BOOLEAN( | |
| 27 "DiskBasedCertCache.WritePreviouslyExisted", already_existed); | |
|
Ryan Sleevi
2014/06/26 19:56:02
You will need to update histograms.xml to ad this
brandonsalmon
2014/06/26 22:04:42
What do I need to do to update this? I tried and g
| |
| 28 } | |
| 29 | |
| 22 // Used to obtain a unique cache key for a certificate in the form of | 30 // Used to obtain a unique cache key for a certificate in the form of |
| 23 // "cert:<hash>". | 31 // "cert:<hash>". |
| 24 std::string GetCacheKeyToCert(const X509Certificate::OSCertHandle cert_handle) { | 32 std::string GetCacheKeyToCert( |
| 33 const X509Certificate::OSCertHandle cert_handle) { | |
|
Ryan Sleevi
2014/06/26 19:56:02
Seems like this fit before - why the change?
| |
| 25 SHA1HashValue fingerprint = | 34 SHA1HashValue fingerprint = |
| 26 X509Certificate::CalculateFingerprint(cert_handle); | 35 X509Certificate::CalculateFingerprint(cert_handle); |
| 27 | 36 |
| 28 return "cert:" + | 37 return "cert:" + |
| 29 base::HexEncode(fingerprint.data, arraysize(fingerprint.data)); | 38 base::HexEncode(fingerprint.data, arraysize(fingerprint.data)); |
| 30 } | 39 } |
| 31 | 40 |
| 32 } // namespace | 41 } // namespace |
|
Ryan Sleevi
2014/06/26 19:56:02
This was correct the way it was before (two spaces
| |
| 33 | 42 |
| 34 // WriteWorkers represent pending Set jobs in the DiskBasedCertCache. Each | 43 // WriteWorkers represent pending Set jobs in the DiskBasedCertCache. Each |
| 35 // certificate requested to be cached is assigned a Writeworker on a one-to-one | 44 // certificate requested to be cached is assigned a Writeworker on a one-to-one |
| 36 // basis. The same certificate should not have multiple WriteWorkers at the same | 45 // basis. The same certificate should not have multiple WriteWorkers at the same |
| 37 // time; instead, add a user callback to the existing WriteWorker. | 46 // time; instead, add a user callback to the existing WriteWorker. |
| 38 class DiskBasedCertCache::WriteWorker { | 47 class DiskBasedCertCache::WriteWorker { |
| 39 public: | 48 public: |
| 40 // |backend| is the backend to store |certificate| in, using | 49 // |backend| is the backend to store |certificate| in, using |
| 41 // |key| as the key for the disk_cache::Entry. | 50 // |key| as the key for the disk_cache::Entry. |
| 42 // |cleanup_callback| is called to clean up this ReadWorker, | 51 // |cleanup_callback| is called to clean up this ReadWorker, |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 int DiskBasedCertCache::WriteWorker::DoCreate() { | 193 int DiskBasedCertCache::WriteWorker::DoCreate() { |
| 185 state_ = STATE_CREATE_COMPLETE; | 194 state_ = STATE_CREATE_COMPLETE; |
| 186 | 195 |
| 187 return backend_->CreateEntry(key_, &entry_, io_callback_); | 196 return backend_->CreateEntry(key_, &entry_, io_callback_); |
| 188 } | 197 } |
| 189 | 198 |
| 190 int DiskBasedCertCache::WriteWorker::DoCreateComplete(int rv) { | 199 int DiskBasedCertCache::WriteWorker::DoCreateComplete(int rv) { |
| 191 // An error here usually signifies that the entry already exists. | 200 // An error here usually signifies that the entry already exists. |
| 192 // If this occurs, it is necessary to instead open the previously | 201 // If this occurs, it is necessary to instead open the previously |
| 193 // existing entry. | 202 // existing entry. |
| 203 RecordHistogram(rv); | |
|
Ryan Sleevi
2014/06/26 19:56:02
Sanity check: What would you expect to use this in
brandonsalmon
2014/06/26 22:04:42
I added this because it seemed important to gather
| |
| 194 if (rv < 0) { | 204 if (rv < 0) { |
| 195 state_ = STATE_OPEN; | 205 state_ = STATE_OPEN; |
| 196 return OK; | 206 return OK; |
| 197 } | 207 } |
| 198 | 208 |
| 199 state_ = STATE_WRITE; | 209 state_ = STATE_WRITE; |
| 200 return OK; | 210 return OK; |
| 201 } | 211 } |
| 202 | 212 |
| 203 int DiskBasedCertCache::WriteWorker::DoOpen() { | 213 int DiskBasedCertCache::WriteWorker::DoOpen() { |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 | 548 |
| 539 void DiskBasedCertCache::FinishedWriteOperation(const std::string& key) { | 549 void DiskBasedCertCache::FinishedWriteOperation(const std::string& key) { |
| 540 write_worker_map_.erase(key); | 550 write_worker_map_.erase(key); |
| 541 } | 551 } |
| 542 | 552 |
| 543 void DiskBasedCertCache::FinishedReadOperation(const std::string& key) { | 553 void DiskBasedCertCache::FinishedReadOperation(const std::string& key) { |
| 544 read_worker_map_.erase(key); | 554 read_worker_map_.erase(key); |
| 545 } | 555 } |
| 546 | 556 |
| 547 } // namespace net | 557 } // namespace net |
| OLD | NEW |