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