Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/http_cache_transaction.h" | 5 #include "net/http/http_cache_transaction.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 #include "net/http/http_util.h" | 39 #include "net/http/http_util.h" |
| 40 #include "net/http/partial_data.h" | 40 #include "net/http/partial_data.h" |
| 41 #include "net/ssl/ssl_cert_request_info.h" | 41 #include "net/ssl/ssl_cert_request_info.h" |
| 42 #include "net/ssl/ssl_config_service.h" | 42 #include "net/ssl/ssl_config_service.h" |
| 43 | 43 |
| 44 using base::Time; | 44 using base::Time; |
| 45 using base::TimeDelta; | 45 using base::TimeDelta; |
| 46 using base::TimeTicks; | 46 using base::TimeTicks; |
| 47 | 47 |
| 48 namespace { | 48 namespace { |
| 49 // used with DiskBasedCertCached objects. TODO(brandonsalmon) start | |
| 50 // storing cache keys so that this doesn't need to be done. | |
|
Ryan Sleevi
2014/06/26 19:56:02
This comment can use some style guide love.
Compl
| |
| 51 std::string GetCacheKeyToCert( | |
| 52 const net::X509Certificate::OSCertHandle cert_handle) { | |
| 53 net::SHA1HashValue fingerprint = | |
| 54 net::X509Certificate::CalculateFingerprint(cert_handle); | |
| 55 | |
| 56 return "cert:" + | |
| 57 base::HexEncode(fingerprint.data, arraysize(fingerprint.data)); | |
| 58 } | |
| 59 | |
| 60 void OnCertReadIOComplete(net::X509Certificate::OSCertHandle cert_handle) { | |
| 61 bool success = (cert_handle != NULL); | |
| 62 UMA_HISTOGRAM_BOOLEAN("DiskBasedCertCache.ReadSuccess", success); | |
| 63 } | |
| 64 | |
| 65 void OnCertWriteIOComplete(const std::string& key) { | |
| 66 bool success = (key!=std::string()); | |
| 67 UMA_HISTOGRAM_BOOLEAN("DiskBasedCertCache.WriteSuccess", success); | |
| 68 } | |
| 49 | 69 |
| 50 // From http://tools.ietf.org/html/draft-ietf-httpbis-p6-cache-21#section-6 | 70 // From http://tools.ietf.org/html/draft-ietf-httpbis-p6-cache-21#section-6 |
| 51 // a "non-error response" is one with a 2xx (Successful) or 3xx | 71 // a "non-error response" is one with a 2xx (Successful) or 3xx |
| 52 // (Redirection) status code. | 72 // (Redirection) status code. |
| 53 bool NonErrorResponse(int status_code) { | 73 bool NonErrorResponse(int status_code) { |
| 54 int status_code_range = status_code / 100; | 74 int status_code_range = status_code / 100; |
| 55 return status_code_range == 2 || status_code_range == 3; | 75 return status_code_range == 2 || status_code_range == 3; |
| 56 } | 76 } |
| 57 | 77 |
| 58 // Error codes that will be considered indicative of a page being offline/ | 78 // Error codes that will be considered indicative of a page being offline/ |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 while (v.GetNext()) { | 203 while (v.GetNext()) { |
| 184 if (LowerCaseEqualsASCII(v.value_begin(), v.value_end(), search->value)) | 204 if (LowerCaseEqualsASCII(v.value_begin(), v.value_end(), search->value)) |
| 185 return true; | 205 return true; |
| 186 } | 206 } |
| 187 } | 207 } |
| 188 return false; | 208 return false; |
| 189 } | 209 } |
| 190 | 210 |
| 191 //----------------------------------------------------------------------------- | 211 //----------------------------------------------------------------------------- |
| 192 | 212 |
| 193 HttpCache::Transaction::Transaction( | 213 HttpCache::Transaction::Transaction(RequestPriority priority, HttpCache* cache) |
| 194 RequestPriority priority, | |
| 195 HttpCache* cache) | |
| 196 : next_state_(STATE_NONE), | 214 : next_state_(STATE_NONE), |
| 197 request_(NULL), | 215 request_(NULL), |
| 198 priority_(priority), | 216 priority_(priority), |
| 199 cache_(cache->GetWeakPtr()), | 217 cache_(cache->GetWeakPtr()), |
| 200 entry_(NULL), | 218 entry_(NULL), |
| 201 new_entry_(NULL), | 219 new_entry_(NULL), |
| 202 new_response_(NULL), | 220 new_response_(NULL), |
| 203 mode_(NONE), | 221 mode_(NONE), |
| 204 target_state_(STATE_NONE), | 222 target_state_(STATE_NONE), |
| 205 reading_(false), | 223 reading_(false), |
| 206 invalid_range_(false), | 224 invalid_range_(false), |
| 207 truncated_(false), | 225 truncated_(false), |
| 208 is_sparse_(false), | 226 is_sparse_(false), |
| 209 range_requested_(false), | 227 range_requested_(false), |
| 210 handling_206_(false), | 228 handling_206_(false), |
| 211 cache_pending_(false), | 229 cache_pending_(false), |
| 212 done_reading_(false), | 230 done_reading_(false), |
| 213 vary_mismatch_(false), | 231 vary_mismatch_(false), |
| 214 couldnt_conditionalize_request_(false), | 232 couldnt_conditionalize_request_(false), |
| 215 bypass_lock_for_test_(false), | 233 bypass_lock_for_test_(false), |
| 216 io_buf_len_(0), | 234 io_buf_len_(0), |
| 217 read_offset_(0), | 235 read_offset_(0), |
| 218 effective_load_flags_(0), | 236 effective_load_flags_(0), |
| 219 write_len_(0), | 237 write_len_(0), |
| 220 weak_factory_(this), | 238 weak_factory_(this), |
| 221 io_callback_(base::Bind(&Transaction::OnIOComplete, | 239 io_callback_( |
| 222 weak_factory_.GetWeakPtr())), | 240 base::Bind(&Transaction::OnIOComplete, weak_factory_.GetWeakPtr())), |
| 241 cert_read_io_callback_(base::Bind(&OnCertReadIOComplete)), | |
| 242 cert_write_io_callback_(base::Bind(&OnCertWriteIOComplete)), | |
| 223 transaction_pattern_(PATTERN_UNDEFINED), | 243 transaction_pattern_(PATTERN_UNDEFINED), |
| 224 total_received_bytes_(0), | 244 total_received_bytes_(0), |
| 225 websocket_handshake_stream_base_create_helper_(NULL) { | 245 websocket_handshake_stream_base_create_helper_(NULL) { |
| 226 COMPILE_ASSERT(HttpCache::Transaction::kNumValidationHeaders == | 246 COMPILE_ASSERT(HttpCache::Transaction::kNumValidationHeaders == |
| 227 arraysize(kValidationHeaders), | 247 arraysize(kValidationHeaders), |
| 228 Invalid_number_of_validation_headers); | 248 Invalid_number_of_validation_headers); |
| 229 } | 249 } |
| 230 | 250 |
| 231 HttpCache::Transaction::~Transaction() { | 251 HttpCache::Transaction::~Transaction() { |
| 232 // We may have to issue another IO, but we should never invoke the callback_ | 252 // We may have to issue another IO, but we should never invoke the callback_ |
| (...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1488 } | 1508 } |
| 1489 | 1509 |
| 1490 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { | 1510 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { |
| 1491 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); | 1511 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); |
| 1492 if (result != io_buf_len_ || | 1512 if (result != io_buf_len_ || |
| 1493 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, | 1513 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, |
| 1494 &response_, &truncated_)) { | 1514 &response_, &truncated_)) { |
| 1495 return OnCacheReadError(result, true); | 1515 return OnCacheReadError(result, true); |
| 1496 } | 1516 } |
| 1497 | 1517 |
| 1518 if(response_.ssl_info.is_valid()) { | |
| 1519 std::string key = GetCacheKeyToCert( | |
| 1520 response_.ssl_info.cert->os_cert_handle()); | |
| 1521 cache_->CertCache()->Get(key, cert_read_io_callback_); | |
|
Ryan Sleevi
2014/06/26 19:56:02
BUG? You're not checking the intermediates (from t
| |
| 1522 } | |
| 1523 | |
| 1498 // Some resources may have slipped in as truncated when they're not. | 1524 // Some resources may have slipped in as truncated when they're not. |
| 1499 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); | 1525 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); |
| 1500 if (response_.headers->GetContentLength() == current_size) | 1526 if (response_.headers->GetContentLength() == current_size) |
| 1501 truncated_ = false; | 1527 truncated_ = false; |
| 1502 | 1528 |
| 1503 // We now have access to the cache entry. | 1529 // We now have access to the cache entry. |
| 1504 // | 1530 // |
| 1505 // o if we are a reader for the transaction, then we can start reading the | 1531 // o if we are a reader for the transaction, then we can start reading the |
| 1506 // cache entry. | 1532 // cache entry. |
| 1507 // | 1533 // |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2320 // reverse-map the cert status to a net error and replay the net error. | 2346 // reverse-map the cert status to a net error and replay the net error. |
| 2321 if ((cache_->mode() != RECORD && | 2347 if ((cache_->mode() != RECORD && |
| 2322 response_.headers->HasHeaderValue("cache-control", "no-store")) || | 2348 response_.headers->HasHeaderValue("cache-control", "no-store")) || |
| 2323 net::IsCertStatusError(response_.ssl_info.cert_status)) { | 2349 net::IsCertStatusError(response_.ssl_info.cert_status)) { |
| 2324 DoneWritingToEntry(false); | 2350 DoneWritingToEntry(false); |
| 2325 if (net_log_.IsLogging()) | 2351 if (net_log_.IsLogging()) |
| 2326 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | 2352 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
| 2327 return OK; | 2353 return OK; |
| 2328 } | 2354 } |
| 2329 | 2355 |
| 2356 if (response_.ssl_info.is_valid()) { | |
| 2357 cache_->CertCache()->Set(response_.ssl_info.cert->os_cert_handle(), | |
| 2358 cert_write_io_callback_); | |
|
Ryan Sleevi
2014/06/26 19:56:02
STYLE: Indent style
BUG: Same as above, not checki
| |
| 2359 } | |
| 2360 | |
| 2330 // When writing headers, we normally only write the non-transient | 2361 // When writing headers, we normally only write the non-transient |
| 2331 // headers; when in record mode, record everything. | 2362 // headers; when in record mode, record everything. |
| 2332 bool skip_transient_headers = (cache_->mode() != RECORD); | 2363 bool skip_transient_headers = (cache_->mode() != RECORD); |
| 2333 | 2364 |
| 2334 if (truncated) | 2365 if (truncated) |
| 2335 DCHECK_EQ(200, response_.headers->response_code()); | 2366 DCHECK_EQ(200, response_.headers->response_code()); |
| 2336 | 2367 |
| 2337 scoped_refptr<PickledIOBuffer> data(new PickledIOBuffer()); | 2368 scoped_refptr<PickledIOBuffer> data(new PickledIOBuffer()); |
| 2338 response_.Persist(data->pickle(), skip_transient_headers, truncated); | 2369 response_.Persist(data->pickle(), skip_transient_headers, truncated); |
| 2339 data->Done(); | 2370 data->Done(); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2576 default: | 2607 default: |
| 2577 NOTREACHED(); | 2608 NOTREACHED(); |
| 2578 } | 2609 } |
| 2579 } | 2610 } |
| 2580 | 2611 |
| 2581 void HttpCache::Transaction::OnIOComplete(int result) { | 2612 void HttpCache::Transaction::OnIOComplete(int result) { |
| 2582 DoLoop(result); | 2613 DoLoop(result); |
| 2583 } | 2614 } |
| 2584 | 2615 |
| 2585 } // namespace net | 2616 } // namespace net |
| OLD | NEW |