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

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

Issue 432053002: DiskBasedCertCache method name change + readability fixes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Forgot to remove line. Created 6 years, 4 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 | « net/http/disk_based_cert_cache.h ('k') | net/http/disk_based_cert_cache_unittest.cc » ('j') | no next file with comments »
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 #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"
(...skipping 21 matching lines...) Expand all
32 32
33 return "cert:" + 33 return "cert:" +
34 base::HexEncode(fingerprint.data, arraysize(fingerprint.data)); 34 base::HexEncode(fingerprint.data, arraysize(fingerprint.data));
35 } 35 }
36 36
37 enum CacheResult { 37 enum CacheResult {
38 MEMORY_CACHE_HIT = 0, 38 MEMORY_CACHE_HIT = 0,
39 DISK_CACHE_HIT, 39 DISK_CACHE_HIT,
40 DISK_CACHE_ENTRY_CORRUPT, 40 DISK_CACHE_ENTRY_CORRUPT,
41 DISK_CACHE_ERROR, 41 DISK_CACHE_ERROR,
42 CACHE_MISS,
43 CACHE_RESULT_MAX 42 CACHE_RESULT_MAX
44 }; 43 };
45 44
46 void RecordCacheResult(CacheResult result) { 45 void RecordCacheResult(CacheResult result) {
47 UMA_HISTOGRAM_ENUMERATION( 46 UMA_HISTOGRAM_ENUMERATION(
48 "DiskBasedCertCache.CertIoCacheResult", result, CACHE_RESULT_MAX); 47 "DiskBasedCertCache.CertIoCacheResult", result, CACHE_RESULT_MAX);
49 } 48 }
50 49
51 } // namespace 50 } // namespace
52 51
53 // WriteWorkers represent pending Set jobs in the DiskBasedCertCache. Each 52 // WriteWorkers represent pending SetCertificate jobs in the DiskBasedCertCache.
54 // certificate requested to be cached is assigned a Writeworker on a one-to-one 53 // Each certificate requested to be stored is assigned a WriteWorker.
55 // basis. The same certificate should not have multiple WriteWorkers at the same 54 // The same certificate should not have multiple WriteWorkers at the same
56 // time; instead, add a user callback to the existing WriteWorker. 55 // time; instead, add a user callback to the existing WriteWorker.
57 class DiskBasedCertCache::WriteWorker { 56 class DiskBasedCertCache::WriteWorker {
58 public: 57 public:
59 // |backend| is the backend to store |certificate| in, using 58 // |backend| is the backend to store |certificate| in, using
60 // |key| as the key for the disk_cache::Entry. 59 // |key| as the key for the disk_cache::Entry.
61 // |cleanup_callback| is called to clean up this ReadWorker, 60 // |cleanup_callback| is called to clean up this ReadWorker,
62 // regardless of success or failure. 61 // regardless of success or failure.
63 WriteWorker(disk_cache::Backend* backend, 62 WriteWorker(disk_cache::Backend* backend,
64 const std::string& key, 63 const std::string& key,
65 X509Certificate::OSCertHandle cert_handle, 64 X509Certificate::OSCertHandle cert_handle,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 104
106 // Invokes all of the |user_callbacks_| 105 // Invokes all of the |user_callbacks_|
107 void RunCallbacks(int rv); 106 void RunCallbacks(int rv);
108 107
109 disk_cache::Backend* backend_; 108 disk_cache::Backend* backend_;
110 const X509Certificate::OSCertHandle cert_handle_; 109 const X509Certificate::OSCertHandle cert_handle_;
111 std::string key_; 110 std::string key_;
112 bool canceled_; 111 bool canceled_;
113 112
114 disk_cache::Entry* entry_; 113 disk_cache::Entry* entry_;
115 State state_; 114 State next_state_;
116 scoped_refptr<IOBuffer> buffer_; 115 scoped_refptr<IOBuffer> buffer_;
117 int io_buf_len_; 116 int io_buf_len_;
118 117
119 base::Closure cleanup_callback_; 118 base::Closure cleanup_callback_;
120 std::vector<SetCallback> user_callbacks_; 119 std::vector<SetCallback> user_callbacks_;
121 CompletionCallback io_callback_; 120 CompletionCallback io_callback_;
122 }; 121 };
123 122
124 DiskBasedCertCache::WriteWorker::WriteWorker( 123 DiskBasedCertCache::WriteWorker::WriteWorker(
125 disk_cache::Backend* backend, 124 disk_cache::Backend* backend,
126 const std::string& key, 125 const std::string& key,
127 X509Certificate::OSCertHandle cert_handle, 126 X509Certificate::OSCertHandle cert_handle,
128 const base::Closure& cleanup_callback) 127 const base::Closure& cleanup_callback)
129 : backend_(backend), 128 : backend_(backend),
130 cert_handle_(X509Certificate::DupOSCertHandle(cert_handle)), 129 cert_handle_(X509Certificate::DupOSCertHandle(cert_handle)),
131 key_(key), 130 key_(key),
132 canceled_(false), 131 canceled_(false),
133 entry_(NULL), 132 entry_(NULL),
134 state_(STATE_NONE), 133 next_state_(STATE_NONE),
135 io_buf_len_(0), 134 io_buf_len_(0),
136 cleanup_callback_(cleanup_callback), 135 cleanup_callback_(cleanup_callback),
137 io_callback_( 136 io_callback_(
138 base::Bind(&WriteWorker::OnIOComplete, base::Unretained(this))) { 137 base::Bind(&WriteWorker::OnIOComplete, base::Unretained(this))) {
139 } 138 }
140 139
141 DiskBasedCertCache::WriteWorker::~WriteWorker() { 140 DiskBasedCertCache::WriteWorker::~WriteWorker() {
142 if (cert_handle_) 141 if (cert_handle_)
143 X509Certificate::FreeOSCertHandle(cert_handle_); 142 X509Certificate::FreeOSCertHandle(cert_handle_);
144 if (entry_) 143 if (entry_)
145 entry_->Close(); 144 entry_->Close();
146 } 145 }
147 146
148 void DiskBasedCertCache::WriteWorker::Start() { 147 void DiskBasedCertCache::WriteWorker::Start() {
149 DCHECK_EQ(STATE_NONE, state_); 148 DCHECK_EQ(STATE_NONE, next_state_);
150 state_ = STATE_CREATE; 149 next_state_ = STATE_CREATE;
151 int rv = DoLoop(OK); 150 int rv = DoLoop(OK);
152 151
153 if (rv == ERR_IO_PENDING) 152 if (rv == ERR_IO_PENDING)
154 return; 153 return;
155 154
156 Finish(rv); 155 Finish(rv);
157 } 156 }
158 157
159 void DiskBasedCertCache::WriteWorker::AddCallback( 158 void DiskBasedCertCache::WriteWorker::AddCallback(
160 const SetCallback& user_callback) { 159 const SetCallback& user_callback) {
(...skipping 13 matching lines...) Expand all
174 rv = DoLoop(rv); 173 rv = DoLoop(rv);
175 174
176 if (rv == ERR_IO_PENDING) 175 if (rv == ERR_IO_PENDING)
177 return; 176 return;
178 177
179 Finish(rv); 178 Finish(rv);
180 } 179 }
181 180
182 int DiskBasedCertCache::WriteWorker::DoLoop(int rv) { 181 int DiskBasedCertCache::WriteWorker::DoLoop(int rv) {
183 do { 182 do {
184 State next_state = state_; 183 State state = next_state_;
185 state_ = STATE_NONE; 184 next_state_ = STATE_NONE;
186 switch (next_state) { 185 switch (state) {
187 case STATE_CREATE: 186 case STATE_CREATE:
188 rv = DoCreate(); 187 rv = DoCreate();
189 break; 188 break;
190 case STATE_CREATE_COMPLETE: 189 case STATE_CREATE_COMPLETE:
191 rv = DoCreateComplete(rv); 190 rv = DoCreateComplete(rv);
192 break; 191 break;
193 case STATE_OPEN: 192 case STATE_OPEN:
194 rv = DoOpen(); 193 rv = DoOpen();
195 break; 194 break;
196 case STATE_OPEN_COMPLETE: 195 case STATE_OPEN_COMPLETE:
197 rv = DoOpenComplete(rv); 196 rv = DoOpenComplete(rv);
198 break; 197 break;
199 case STATE_WRITE: 198 case STATE_WRITE:
200 rv = DoWrite(); 199 rv = DoWrite();
201 break; 200 break;
202 case STATE_WRITE_COMPLETE: 201 case STATE_WRITE_COMPLETE:
203 rv = DoWriteComplete(rv); 202 rv = DoWriteComplete(rv);
204 break; 203 break;
205 case STATE_NONE: 204 case STATE_NONE:
206 NOTREACHED(); 205 NOTREACHED();
207 break; 206 break;
208 } 207 }
209 } while (rv != ERR_IO_PENDING && state_ != STATE_NONE); 208 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
210 209
211 return rv; 210 return rv;
212 } 211 }
213 212
214 int DiskBasedCertCache::WriteWorker::DoCreate() { 213 int DiskBasedCertCache::WriteWorker::DoCreate() {
215 state_ = STATE_CREATE_COMPLETE; 214 next_state_ = STATE_CREATE_COMPLETE;
216 215
217 return backend_->CreateEntry(key_, &entry_, io_callback_); 216 return backend_->CreateEntry(key_, &entry_, io_callback_);
218 } 217 }
219 218
220 int DiskBasedCertCache::WriteWorker::DoCreateComplete(int rv) { 219 int DiskBasedCertCache::WriteWorker::DoCreateComplete(int rv) {
221 // An error here usually signifies that the entry already exists. 220 // An error here usually signifies that the entry already exists.
222 // If this occurs, it is necessary to instead open the previously 221 // If this occurs, it is necessary to instead open the previously
223 // existing entry. 222 // existing entry.
224 if (rv < 0) { 223 if (rv < 0) {
225 state_ = STATE_OPEN; 224 next_state_ = STATE_OPEN;
226 return OK; 225 return OK;
227 } 226 }
228 227
229 state_ = STATE_WRITE; 228 next_state_ = STATE_WRITE;
230 return OK; 229 return OK;
231 } 230 }
232 231
233 int DiskBasedCertCache::WriteWorker::DoOpen() { 232 int DiskBasedCertCache::WriteWorker::DoOpen() {
234 state_ = STATE_OPEN_COMPLETE; 233 next_state_ = STATE_OPEN_COMPLETE;
235 return backend_->OpenEntry(key_, &entry_, io_callback_); 234 return backend_->OpenEntry(key_, &entry_, io_callback_);
236 } 235 }
237 236
238 int DiskBasedCertCache::WriteWorker::DoOpenComplete(int rv) { 237 int DiskBasedCertCache::WriteWorker::DoOpenComplete(int rv) {
239 if (rv < 0) 238 if (rv < 0)
240 return rv; 239 return rv;
241 240
242 state_ = STATE_WRITE; 241 next_state_ = STATE_WRITE;
243 return OK; 242 return OK;
244 } 243 }
245 244
246 int DiskBasedCertCache::WriteWorker::DoWrite() { 245 int DiskBasedCertCache::WriteWorker::DoWrite() {
247 std::string write_data; 246 std::string write_data;
248 bool encoded = X509Certificate::GetDEREncoded(cert_handle_, &write_data); 247 bool encoded = X509Certificate::GetDEREncoded(cert_handle_, &write_data);
249 248
250 if (!encoded) 249 if (!encoded)
251 return ERR_FAILED; 250 return ERR_FAILED;
252 251
253 buffer_ = new IOBuffer(write_data.size()); 252 buffer_ = new IOBuffer(write_data.size());
254 io_buf_len_ = write_data.size(); 253 io_buf_len_ = write_data.size();
255 memcpy(buffer_->data(), write_data.data(), io_buf_len_); 254 memcpy(buffer_->data(), write_data.data(), io_buf_len_);
256 255
257 state_ = STATE_WRITE_COMPLETE; 256 next_state_ = STATE_WRITE_COMPLETE;
258 257
259 return entry_->WriteData(0 /* index */, 258 return entry_->WriteData(0 /* index */,
260 0 /* offset */, 259 0 /* offset */,
261 buffer_, 260 buffer_,
262 write_data.size(), 261 write_data.size(),
263 io_callback_, 262 io_callback_,
264 true /* truncate */); 263 true /* truncate */);
265 } 264 }
266 265
267 int DiskBasedCertCache::WriteWorker::DoWriteComplete(int rv) { 266 int DiskBasedCertCache::WriteWorker::DoWriteComplete(int rv) {
(...skipping 16 matching lines...) Expand all
284 key = key_; 283 key = key_;
285 284
286 for (std::vector<SetCallback>::const_iterator it = user_callbacks_.begin(); 285 for (std::vector<SetCallback>::const_iterator it = user_callbacks_.begin();
287 it != user_callbacks_.end(); 286 it != user_callbacks_.end();
288 ++it) { 287 ++it) {
289 it->Run(key); 288 it->Run(key);
290 } 289 }
291 user_callbacks_.clear(); 290 user_callbacks_.clear();
292 } 291 }
293 292
294 // ReadWorkers represent pending Get jobs in the DiskBasedCertCache. Each 293 // ReadWorkers represent pending GetCertificate jobs in the DiskBasedCertCache.
295 // certificate requested to be retrieved from the cache is assigned a ReadWorker 294 // Each certificate requested to be retrieved from the cache is assigned a
296 // on a one-to-one basis. The same |key| should not have multiple ReadWorkers 295 // ReadWorker. The same |key| should not have multiple ReadWorkers at the
297 // at the same time; instead, call AddCallback to add a user_callback_ to 296 // same time; instead, call AddCallback to add a user callback to the
298 // the the existing ReadWorker. 297 // existing ReadWorker.
299 class DiskBasedCertCache::ReadWorker { 298 class DiskBasedCertCache::ReadWorker {
300 public: 299 public:
301 // |backend| is the backend to read |certificate| from, using 300 // |backend| is the backend to read |certificate| from, using
302 // |key| as the key for the disk_cache::Entry. 301 // |key| as the key for the disk_cache::Entry.
303 // |cleanup_callback| is called to clean up this ReadWorker, 302 // |cleanup_callback| is called to clean up this ReadWorker,
304 // regardless of success or failure. 303 // regardless of success or failure.
305 ReadWorker(disk_cache::Backend* backend, 304 ReadWorker(disk_cache::Backend* backend,
306 const std::string& key, 305 const std::string& key,
307 const GetCallback& cleanup_callback); 306 const GetCallback& cleanup_callback);
308 307
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // Invokes all of |user_callbacks_| 340 // Invokes all of |user_callbacks_|
342 void RunCallbacks(); 341 void RunCallbacks();
343 342
344 disk_cache::Backend* backend_; 343 disk_cache::Backend* backend_;
345 X509Certificate::OSCertHandle cert_handle_; 344 X509Certificate::OSCertHandle cert_handle_;
346 std::string key_; 345 std::string key_;
347 bool canceled_; 346 bool canceled_;
348 347
349 disk_cache::Entry* entry_; 348 disk_cache::Entry* entry_;
350 349
351 State state_; 350 State next_state_;
352 scoped_refptr<IOBuffer> buffer_; 351 scoped_refptr<IOBuffer> buffer_;
353 int io_buf_len_; 352 int io_buf_len_;
354 353
355 GetCallback cleanup_callback_; 354 GetCallback cleanup_callback_;
356 std::vector<GetCallback> user_callbacks_; 355 std::vector<GetCallback> user_callbacks_;
357 CompletionCallback io_callback_; 356 CompletionCallback io_callback_;
358 }; 357 };
359 358
360 DiskBasedCertCache::ReadWorker::ReadWorker(disk_cache::Backend* backend, 359 DiskBasedCertCache::ReadWorker::ReadWorker(disk_cache::Backend* backend,
361 const std::string& key, 360 const std::string& key,
362 const GetCallback& cleanup_callback) 361 const GetCallback& cleanup_callback)
363 : backend_(backend), 362 : backend_(backend),
364 cert_handle_(NULL), 363 cert_handle_(NULL),
365 key_(key), 364 key_(key),
366 canceled_(false), 365 canceled_(false),
367 entry_(NULL), 366 entry_(NULL),
368 state_(STATE_NONE), 367 next_state_(STATE_NONE),
369 io_buf_len_(0), 368 io_buf_len_(0),
370 cleanup_callback_(cleanup_callback), 369 cleanup_callback_(cleanup_callback),
371 io_callback_( 370 io_callback_(
372 base::Bind(&ReadWorker::OnIOComplete, base::Unretained(this))) { 371 base::Bind(&ReadWorker::OnIOComplete, base::Unretained(this))) {
373 } 372 }
374 373
375 DiskBasedCertCache::ReadWorker::~ReadWorker() { 374 DiskBasedCertCache::ReadWorker::~ReadWorker() {
376 if (entry_) 375 if (entry_)
377 entry_->Close(); 376 entry_->Close();
378 if (cert_handle_) 377 if (cert_handle_)
379 X509Certificate::FreeOSCertHandle(cert_handle_); 378 X509Certificate::FreeOSCertHandle(cert_handle_);
380 } 379 }
381 380
382 void DiskBasedCertCache::ReadWorker::Start() { 381 void DiskBasedCertCache::ReadWorker::Start() {
383 DCHECK_EQ(STATE_NONE, state_); 382 DCHECK_EQ(STATE_NONE, next_state_);
384 state_ = STATE_OPEN; 383 next_state_ = STATE_OPEN;
385 int rv = DoLoop(OK); 384 int rv = DoLoop(OK);
386 385
387 if (rv == ERR_IO_PENDING) 386 if (rv == ERR_IO_PENDING)
388 return; 387 return;
389 388
390 Finish(rv); 389 Finish(rv);
391 } 390 }
392 391
393 void DiskBasedCertCache::ReadWorker::AddCallback( 392 void DiskBasedCertCache::ReadWorker::AddCallback(
394 const GetCallback& user_callback) { 393 const GetCallback& user_callback) {
(...skipping 13 matching lines...) Expand all
408 rv = DoLoop(rv); 407 rv = DoLoop(rv);
409 408
410 if (rv == ERR_IO_PENDING) 409 if (rv == ERR_IO_PENDING)
411 return; 410 return;
412 411
413 Finish(rv); 412 Finish(rv);
414 } 413 }
415 414
416 int DiskBasedCertCache::ReadWorker::DoLoop(int rv) { 415 int DiskBasedCertCache::ReadWorker::DoLoop(int rv) {
417 do { 416 do {
418 State next_state = state_; 417 State state = next_state_;
419 state_ = STATE_NONE; 418 next_state_ = STATE_NONE;
420 switch (next_state) { 419 switch (state) {
421 case STATE_OPEN: 420 case STATE_OPEN:
422 rv = DoOpen(); 421 rv = DoOpen();
423 break; 422 break;
424 case STATE_OPEN_COMPLETE: 423 case STATE_OPEN_COMPLETE:
425 rv = DoOpenComplete(rv); 424 rv = DoOpenComplete(rv);
426 break; 425 break;
427 case STATE_READ: 426 case STATE_READ:
428 rv = DoRead(); 427 rv = DoRead();
429 break; 428 break;
430 case STATE_READ_COMPLETE: 429 case STATE_READ_COMPLETE:
431 rv = DoReadComplete(rv); 430 rv = DoReadComplete(rv);
432 break; 431 break;
433 case STATE_NONE: 432 case STATE_NONE:
434 NOTREACHED(); 433 NOTREACHED();
435 break; 434 break;
436 } 435 }
437 } while (rv != ERR_IO_PENDING && state_ != STATE_NONE); 436 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
438 437
439 return rv; 438 return rv;
440 } 439 }
441 440
442 int DiskBasedCertCache::ReadWorker::DoOpen() { 441 int DiskBasedCertCache::ReadWorker::DoOpen() {
443 state_ = STATE_OPEN_COMPLETE; 442 next_state_ = STATE_OPEN_COMPLETE;
444 return backend_->OpenEntry(key_, &entry_, io_callback_); 443 return backend_->OpenEntry(key_, &entry_, io_callback_);
445 } 444 }
446 445
447 int DiskBasedCertCache::ReadWorker::DoOpenComplete(int rv) { 446 int DiskBasedCertCache::ReadWorker::DoOpenComplete(int rv) {
448 if (rv < 0) { 447 if (rv < 0) {
wtc 2014/08/04 22:44:42 It seems useful to be able to distinguish between
rvargas (doing something else) 2014/08/04 22:59:48 What would you do with specific codes other than l
449 // Errors other than ERR_CACHE_MISS are not recorded as either a hit 448 RecordCacheResult(DISK_CACHE_ERROR);
450 // or a miss.
451 RecordCacheResult(rv == ERR_CACHE_MISS ? CACHE_MISS : DISK_CACHE_ERROR);
452 return rv; 449 return rv;
453 } 450 }
454 451
455 state_ = STATE_READ; 452 next_state_ = STATE_READ;
456 return OK; 453 return OK;
457 } 454 }
458 455
459 int DiskBasedCertCache::ReadWorker::DoRead() { 456 int DiskBasedCertCache::ReadWorker::DoRead() {
460 state_ = STATE_READ_COMPLETE; 457 next_state_ = STATE_READ_COMPLETE;
461 io_buf_len_ = entry_->GetDataSize(0 /* index */); 458 io_buf_len_ = entry_->GetDataSize(0 /* index */);
462 buffer_ = new IOBuffer(io_buf_len_); 459 buffer_ = new IOBuffer(io_buf_len_);
463 return entry_->ReadData( 460 return entry_->ReadData(
464 0 /* index */, 0 /* offset */, buffer_, io_buf_len_, io_callback_); 461 0 /* index */, 0 /* offset */, buffer_, io_buf_len_, io_callback_);
465 } 462 }
466 463
467 int DiskBasedCertCache::ReadWorker::DoReadComplete(int rv) { 464 int DiskBasedCertCache::ReadWorker::DoReadComplete(int rv) {
468 // The cache should return the entire buffer length. If it does not, 465 // The cache should return the entire buffer length. If it does not,
469 // it is probably indicative of an issue other than corruption. 466 // it is probably indicative of an issue other than corruption.
470 if (rv < io_buf_len_) { 467 if (rv < io_buf_len_) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 ++it) { 515 ++it) {
519 it->second->Cancel(); 516 it->second->Cancel();
520 } 517 }
521 for (ReadWorkerMap::iterator it = read_worker_map_.begin(); 518 for (ReadWorkerMap::iterator it = read_worker_map_.begin();
522 it != read_worker_map_.end(); 519 it != read_worker_map_.end();
523 ++it) { 520 ++it) {
524 it->second->Cancel(); 521 it->second->Cancel();
525 } 522 }
526 } 523 }
527 524
528 void DiskBasedCertCache::Get(const std::string& key, const GetCallback& cb) { 525 void DiskBasedCertCache::GetCertificate(const std::string& key,
526 const GetCallback& cb) {
529 DCHECK(!key.empty()); 527 DCHECK(!key.empty());
530 528
531 // If the handle is already in the MRU cache, just return that (via callback). 529 // If the handle is already in the MRU cache, just return that (via callback).
532 // Note, this will also bring the cert_handle to the front of the recency 530 // Note, this will also bring the cert_handle to the front of the recency
533 // list in the MRU cache. 531 // list in the MRU cache.
534 MRUCertCache::iterator mru_it = mru_cert_cache_.Get(key); 532 MRUCertCache::iterator mru_it = mru_cert_cache_.Get(key);
535 if (mru_it != mru_cert_cache_.end()) { 533 if (mru_it != mru_cert_cache_.end()) {
536 RecordCacheResult(MEMORY_CACHE_HIT); 534 RecordCacheResult(MEMORY_CACHE_HIT);
537 ++mem_cache_hits_; 535 ++mem_cache_hits_;
538 cb.Run(mru_it->second); 536 cb.Run(mru_it->second);
(...skipping 11 matching lines...) Expand all
550 weak_factory_.GetWeakPtr(), 548 weak_factory_.GetWeakPtr(),
551 key)); 549 key));
552 read_worker_map_[key] = worker; 550 read_worker_map_[key] = worker;
553 worker->AddCallback(cb); 551 worker->AddCallback(cb);
554 worker->Start(); 552 worker->Start();
555 } else { 553 } else {
556 it->second->AddCallback(cb); 554 it->second->AddCallback(cb);
557 } 555 }
558 } 556 }
559 557
560 void DiskBasedCertCache::Set(const X509Certificate::OSCertHandle cert_handle, 558 void DiskBasedCertCache::SetCertificate(
561 const SetCallback& cb) { 559 const X509Certificate::OSCertHandle cert_handle,
560 const SetCallback& cb) {
562 DCHECK(!cb.is_null()); 561 DCHECK(!cb.is_null());
563 DCHECK(cert_handle); 562 DCHECK(cert_handle);
564 std::string key = GetCacheKeyForCert(cert_handle); 563 std::string key = GetCacheKeyForCert(cert_handle);
565 564
566 WriteWorkerMap::iterator it = write_worker_map_.find(key); 565 WriteWorkerMap::iterator it = write_worker_map_.find(key);
567 566
568 if (it == write_worker_map_.end()) { 567 if (it == write_worker_map_.end()) {
569 WriteWorker* worker = 568 WriteWorker* worker =
570 new WriteWorker(backend_, 569 new WriteWorker(backend_,
571 key, 570 key,
(...skipping 20 matching lines...) Expand all
592 591
593 void DiskBasedCertCache::FinishedWriteOperation( 592 void DiskBasedCertCache::FinishedWriteOperation(
594 const std::string& key, 593 const std::string& key,
595 X509Certificate::OSCertHandle cert_handle) { 594 X509Certificate::OSCertHandle cert_handle) {
596 write_worker_map_.erase(key); 595 write_worker_map_.erase(key);
597 if (!key.empty()) 596 if (!key.empty())
598 mru_cert_cache_.Put(key, X509Certificate::DupOSCertHandle(cert_handle)); 597 mru_cert_cache_.Put(key, X509Certificate::DupOSCertHandle(cert_handle));
599 } 598 }
600 599
601 } // namespace net 600 } // namespace net
OLDNEW
« no previous file with comments | « net/http/disk_based_cert_cache.h ('k') | net/http/disk_based_cert_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698