| OLD | NEW |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 | 8 |
| 9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 truncated_(false), | 107 truncated_(false), |
| 108 server_responded_206_(false), | 108 server_responded_206_(false), |
| 109 cache_pending_(false), | 109 cache_pending_(false), |
| 110 read_offset_(0), | 110 read_offset_(0), |
| 111 effective_load_flags_(0), | 111 effective_load_flags_(0), |
| 112 final_upload_progress_(0), | 112 final_upload_progress_(0), |
| 113 ALLOW_THIS_IN_INITIALIZER_LIST( | 113 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 114 io_callback_(this, &Transaction::OnIOComplete)), | 114 io_callback_(this, &Transaction::OnIOComplete)), |
| 115 ALLOW_THIS_IN_INITIALIZER_LIST( | 115 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 116 cache_callback_(new CancelableCompletionCallback<Transaction>( | 116 cache_callback_(new CancelableCompletionCallback<Transaction>( |
| 117 this, &Transaction::OnIOComplete))), | 117 this, &Transaction::OnIOComplete))), |
| 118 ALLOW_THIS_IN_INITIALIZER_LIST( | 118 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 119 write_headers_callback_(new CancelableCompletionCallback<Transaction>( | 119 write_headers_callback_(new CancelableCompletionCallback<Transaction>( |
| 120 this, &Transaction::OnIOComplete))) { | 120 this, &Transaction::OnIOComplete))) { |
| 121 COMPILE_ASSERT(HttpCache::Transaction::kNumValidationHeaders == | 121 COMPILE_ASSERT(HttpCache::Transaction::kNumValidationHeaders == |
| 122 ARRAYSIZE_UNSAFE(kValidationHeaders), | 122 ARRAYSIZE_UNSAFE(kValidationHeaders), |
| 123 Invalid_number_of_validation_headers); | 123 Invalid_number_of_validation_headers); |
| 124 } | 124 } |
| 125 | 125 |
| 126 HttpCache::Transaction::~Transaction() { | 126 HttpCache::Transaction::~Transaction() { |
| 127 // We may have to issue another IO, but we should never invoke the callback_ | 127 // We may have to issue another IO, but we should never invoke the callback_ |
| 128 // after this point. | 128 // after this point. |
| 129 callback_ = NULL; | 129 callback_ = NULL; |
| 130 | 130 |
| 131 if (cache_) { | 131 if (cache_) { |
| 132 if (entry_) { | 132 if (entry_) { |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 return OK; | 895 return OK; |
| 896 } | 896 } |
| 897 | 897 |
| 898 // We change the value of Content-Length for partial content. | 898 // We change the value of Content-Length for partial content. |
| 899 if (server_responded_206_ && partial_.get()) | 899 if (server_responded_206_ && partial_.get()) |
| 900 partial_->FixContentLength(new_response_->headers); | 900 partial_->FixContentLength(new_response_->headers); |
| 901 | 901 |
| 902 response_ = *new_response_; | 902 response_ = *new_response_; |
| 903 target_state_ = STATE_TRUNCATE_CACHED_DATA; | 903 target_state_ = STATE_TRUNCATE_CACHED_DATA; |
| 904 next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE : | 904 next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE : |
| 905 STATE_CACHE_WRITE_RESPONSE; | 905 STATE_CACHE_WRITE_RESPONSE; |
| 906 return OK; | 906 return OK; |
| 907 } | 907 } |
| 908 | 908 |
| 909 int HttpCache::Transaction::DoTruncateCachedData() { | 909 int HttpCache::Transaction::DoTruncateCachedData() { |
| 910 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; | 910 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; |
| 911 if (!entry_) | 911 if (!entry_) |
| 912 return OK; | 912 return OK; |
| 913 | 913 |
| 914 // Truncate the stream. | 914 // Truncate the stream. |
| 915 int rv = WriteToEntry(kResponseContentIndex, 0, NULL, 0, NULL); | 915 int rv = WriteToEntry(kResponseContentIndex, 0, NULL, 0, NULL); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 cache_callback_->Release(); | 1115 cache_callback_->Release(); |
| 1116 if (!cache_) | 1116 if (!cache_) |
| 1117 return ERR_UNEXPECTED; | 1117 return ERR_UNEXPECTED; |
| 1118 | 1118 |
| 1119 if (result < 0) | 1119 if (result < 0) |
| 1120 return result; | 1120 return result; |
| 1121 | 1121 |
| 1122 if (partial_.get()) { | 1122 if (partial_.get()) { |
| 1123 // This may be the last request. | 1123 // This may be the last request. |
| 1124 if (!(result == 0 && !truncated_ && | 1124 if (!(result == 0 && !truncated_ && |
| 1125 (partial_->IsLastRange() || mode_ == WRITE))) | 1125 (partial_->IsLastRange() || mode_ == WRITE))) |
| 1126 return DoPartialNetworkReadCompleted(result); | 1126 return DoPartialNetworkReadCompleted(result); |
| 1127 } | 1127 } |
| 1128 | 1128 |
| 1129 if (result == 0) // End of file. | 1129 if (result == 0) // End of file. |
| 1130 DoneWritingToEntry(true); | 1130 DoneWritingToEntry(true); |
| 1131 | 1131 |
| 1132 return result; | 1132 return result; |
| 1133 } | 1133 } |
| 1134 | 1134 |
| 1135 //----------------------------------------------------------------------------- | 1135 //----------------------------------------------------------------------------- |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 break; | 1194 break; |
| 1195 } | 1195 } |
| 1196 } | 1196 } |
| 1197 | 1197 |
| 1198 // Check for conditionalization headers which may correspond with a | 1198 // Check for conditionalization headers which may correspond with a |
| 1199 // cache validation request. | 1199 // cache validation request. |
| 1200 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kValidationHeaders); ++i) { | 1200 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kValidationHeaders); ++i) { |
| 1201 const ValidationHeaderInfo& info = kValidationHeaders[i]; | 1201 const ValidationHeaderInfo& info = kValidationHeaders[i]; |
| 1202 std::string validation_value; | 1202 std::string validation_value; |
| 1203 if (request_->extra_headers.GetHeader( | 1203 if (request_->extra_headers.GetHeader( |
| 1204 info.request_header_name, &validation_value)) { | 1204 info.request_header_name, &validation_value)) { |
| 1205 if (!external_validation_.values[i].empty() || | 1205 if (!external_validation_.values[i].empty() || |
| 1206 validation_value.empty()) | 1206 validation_value.empty()) |
| 1207 external_validation_error = true; | 1207 external_validation_error = true; |
| 1208 external_validation_.values[i] = validation_value; | 1208 external_validation_.values[i] = validation_value; |
| 1209 external_validation_.initialized = true; | 1209 external_validation_.initialized = true; |
| 1210 break; | 1210 break; |
| 1211 } | 1211 } |
| 1212 } | 1212 } |
| 1213 | 1213 |
| 1214 // We don't support ranges and validation headers. | 1214 // We don't support ranges and validation headers. |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1445 | 1445 |
| 1446 if (response_.headers->response_code() == 206 && !enable_range_support_) | 1446 if (response_.headers->response_code() == 206 && !enable_range_support_) |
| 1447 return true; | 1447 return true; |
| 1448 | 1448 |
| 1449 if (response_.headers->RequiresValidation( | 1449 if (response_.headers->RequiresValidation( |
| 1450 response_.request_time, response_.response_time, Time::Now())) | 1450 response_.request_time, response_.response_time, Time::Now())) |
| 1451 return true; | 1451 return true; |
| 1452 | 1452 |
| 1453 // Since Vary header computation is fairly expensive, we save it for last. | 1453 // Since Vary header computation is fairly expensive, we save it for last. |
| 1454 if (response_.vary_data.is_valid() && | 1454 if (response_.vary_data.is_valid() && |
| 1455 !response_.vary_data.MatchesRequest(*request_, *response_.headers)) | 1455 !response_.vary_data.MatchesRequest(*request_, *response_.headers)) |
| 1456 return true; | 1456 return true; |
| 1457 | 1457 |
| 1458 return false; | 1458 return false; |
| 1459 } | 1459 } |
| 1460 | 1460 |
| 1461 bool HttpCache::Transaction::ConditionalizeRequest() { | 1461 bool HttpCache::Transaction::ConditionalizeRequest() { |
| 1462 DCHECK(response_.headers); | 1462 DCHECK(response_.headers); |
| 1463 | 1463 |
| 1464 if (!enable_range_support_ && response_.headers->response_code() != 200) { | 1464 if (!enable_range_support_ && response_.headers->response_code() != 200) { |
| 1465 // This only makes sense for cached 200 responses. | 1465 // This only makes sense for cached 200 responses. |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1675 // Do not cache no-store content (unless we are record mode). Do not cache | 1675 // Do not cache no-store content (unless we are record mode). Do not cache |
| 1676 // content with cert errors either. This is to prevent not reporting net | 1676 // content with cert errors either. This is to prevent not reporting net |
| 1677 // errors when loading a resource from the cache. When we load a page over | 1677 // errors when loading a resource from the cache. When we load a page over |
| 1678 // HTTPS with a cert error we show an SSL blocking page. If the user clicks | 1678 // HTTPS with a cert error we show an SSL blocking page. If the user clicks |
| 1679 // proceed we reload the resource ignoring the errors. The loaded resource | 1679 // proceed we reload the resource ignoring the errors. The loaded resource |
| 1680 // is then cached. If that resource is subsequently loaded from the cache, | 1680 // is then cached. If that resource is subsequently loaded from the cache, |
| 1681 // no net error is reported (even though the cert status contains the actual | 1681 // no net error is reported (even though the cert status contains the actual |
| 1682 // errors) and no SSL blocking page is shown. An alternative would be to | 1682 // errors) and no SSL blocking page is shown. An alternative would be to |
| 1683 // reverse-map the cert status to a net error and replay the net error. | 1683 // reverse-map the cert status to a net error and replay the net error. |
| 1684 if ((cache_->mode() != RECORD && | 1684 if ((cache_->mode() != RECORD && |
| 1685 response_.headers->HasHeaderValue("cache-control", "no-store")) || | 1685 response_.headers->HasHeaderValue("cache-control", "no-store")) || |
| 1686 net::IsCertStatusError(response_.ssl_info.cert_status)) { | 1686 net::IsCertStatusError(response_.ssl_info.cert_status)) { |
| 1687 DoneWritingToEntry(false); | 1687 DoneWritingToEntry(false); |
| 1688 return OK; | 1688 return OK; |
| 1689 } | 1689 } |
| 1690 | 1690 |
| 1691 // When writing headers, we normally only write the non-transient | 1691 // When writing headers, we normally only write the non-transient |
| 1692 // headers; when in record mode, record everything. | 1692 // headers; when in record mode, record everything. |
| 1693 bool skip_transient_headers = (cache_->mode() != RECORD); | 1693 bool skip_transient_headers = (cache_->mode() != RECORD); |
| 1694 | 1694 |
| 1695 if (truncated) { | 1695 if (truncated) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1800 // |value| goes from 0 to 63. Actually, the max value should be 47 (0x2f) | 1800 // |value| goes from 0 to 63. Actually, the max value should be 47 (0x2f) |
| 1801 // but we'll see. | 1801 // but we'll see. |
| 1802 UMA_HISTOGRAM_ENUMERATION("HttpCache.ResponseHeaders", value, 65); | 1802 UMA_HISTOGRAM_ENUMERATION("HttpCache.ResponseHeaders", value, 65); |
| 1803 } | 1803 } |
| 1804 | 1804 |
| 1805 void HttpCache::Transaction::OnIOComplete(int result) { | 1805 void HttpCache::Transaction::OnIOComplete(int result) { |
| 1806 DoLoop(result); | 1806 DoLoop(result); |
| 1807 } | 1807 } |
| 1808 | 1808 |
| 1809 } // namespace net | 1809 } // namespace net |
| OLD | NEW |