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> |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "base/format_macros.h" | 18 #include "base/format_macros.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/scoped_ptr.h" | |
| 20 #include "base/metrics/field_trial.h" | 21 #include "base/metrics/field_trial.h" |
| 21 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
| 22 #include "base/metrics/sparse_histogram.h" | 23 #include "base/metrics/sparse_histogram.h" |
| 23 #include "base/rand_util.h" | 24 #include "base/rand_util.h" |
| 24 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
| 25 #include "base/strings/string_piece.h" | 26 #include "base/strings/string_piece.h" |
| 26 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
| 27 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
| 28 #include "base/time/time.h" | 29 #include "base/time/time.h" |
| 30 #include "base/values.h" | |
| 29 #include "net/base/completion_callback.h" | 31 #include "net/base/completion_callback.h" |
| 30 #include "net/base/io_buffer.h" | 32 #include "net/base/io_buffer.h" |
| 31 #include "net/base/load_flags.h" | 33 #include "net/base/load_flags.h" |
| 32 #include "net/base/load_timing_info.h" | 34 #include "net/base/load_timing_info.h" |
| 33 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
| 34 #include "net/base/net_log.h" | 36 #include "net/base/net_log.h" |
| 35 #include "net/base/upload_data_stream.h" | 37 #include "net/base/upload_data_stream.h" |
| 36 #include "net/cert/cert_status_flags.h" | 38 #include "net/cert/cert_status_flags.h" |
| 37 #include "net/disk_cache/disk_cache.h" | 39 #include "net/disk_cache/disk_cache.h" |
| 38 #include "net/http/disk_based_cert_cache.h" | 40 #include "net/http/disk_based_cert_cache.h" |
| 39 #include "net/http/http_network_session.h" | 41 #include "net/http/http_network_session.h" |
| 40 #include "net/http/http_request_info.h" | 42 #include "net/http/http_request_info.h" |
| 41 #include "net/http/http_response_headers.h" | 43 #include "net/http/http_response_headers.h" |
| 42 #include "net/http/http_transaction.h" | 44 #include "net/http/http_transaction.h" |
| 43 #include "net/http/http_util.h" | 45 #include "net/http/http_util.h" |
| 44 #include "net/http/partial_data.h" | 46 #include "net/http/partial_data.h" |
| 45 #include "net/ssl/ssl_cert_request_info.h" | 47 #include "net/ssl/ssl_cert_request_info.h" |
| 46 #include "net/ssl/ssl_config_service.h" | 48 #include "net/ssl/ssl_config_service.h" |
| 47 | 49 |
| 48 using base::Time; | 50 using base::Time; |
| 49 using base::TimeDelta; | 51 using base::TimeDelta; |
| 50 using base::TimeTicks; | 52 using base::TimeTicks; |
| 51 | 53 |
| 52 namespace { | 54 namespace { |
| 53 | 55 |
| 56 typedef net::HttpResponseHeaders::ValidationType ValidationType; | |
| 57 const ValidationType VALIDATION_NONE = ValidationType::VALIDATION_NONE; | |
|
rvargas (doing something else)
2014/08/29 23:36:07
I think we should just live with HttpResponseHeade
Adam Rice
2014/09/01 14:43:00
Done.
| |
| 58 const ValidationType VALIDATION_SYNCHRONOUS = | |
| 59 ValidationType::VALIDATION_SYNCHRONOUS; | |
| 60 const ValidationType VALIDATION_ASYNCHRONOUS = | |
| 61 ValidationType::VALIDATION_ASYNCHRONOUS; | |
| 62 | |
| 54 // TODO(ricea): Move this to HttpResponseHeaders once it is standardised. | 63 // TODO(ricea): Move this to HttpResponseHeaders once it is standardised. |
| 55 static const char kFreshnessHeader[] = "Resource-Freshness"; | 64 static const char kFreshnessHeader[] = "Resource-Freshness"; |
| 56 | 65 |
| 57 // Stores data relevant to the statistics of writing and reading entire | 66 // Stores data relevant to the statistics of writing and reading entire |
| 58 // certificate chains using DiskBasedCertCache. |num_pending_ops| is the number | 67 // certificate chains using DiskBasedCertCache. |num_pending_ops| is the number |
| 59 // of certificates in the chain that have pending operations in the | 68 // of certificates in the chain that have pending operations in the |
| 60 // DiskBasedCertCache. |start_time| is the time that the read and write | 69 // DiskBasedCertCache. |start_time| is the time that the read and write |
| 61 // commands began being issued to the DiskBasedCertCache. | 70 // commands began being issued to the DiskBasedCertCache. |
| 62 // TODO(brandonsalmon): Remove this when it is no longer necessary to | 71 // TODO(brandonsalmon): Remove this when it is no longer necessary to |
| 63 // collect data. | 72 // collect data. |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 | 240 |
| 232 void RecordNoStoreHeaderHistogram(int load_flags, | 241 void RecordNoStoreHeaderHistogram(int load_flags, |
| 233 const net::HttpResponseInfo* response) { | 242 const net::HttpResponseInfo* response) { |
| 234 if (load_flags & net::LOAD_MAIN_FRAME) { | 243 if (load_flags & net::LOAD_MAIN_FRAME) { |
| 235 UMA_HISTOGRAM_BOOLEAN( | 244 UMA_HISTOGRAM_BOOLEAN( |
| 236 "Net.MainFrameNoStore", | 245 "Net.MainFrameNoStore", |
| 237 response->headers->HasHeaderValue("cache-control", "no-store")); | 246 response->headers->HasHeaderValue("cache-control", "no-store")); |
| 238 } | 247 } |
| 239 } | 248 } |
| 240 | 249 |
| 250 base::Value* NetLogAsyncRevalidationInfoCallback( | |
| 251 const net::NetLog::Source& source, | |
| 252 const net::HttpRequestInfo* request, | |
| 253 net::NetLog::LogLevel log_level) { | |
| 254 base::DictionaryValue* dict = new base::DictionaryValue(); | |
| 255 source.AddToEventParameters(dict); | |
| 256 | |
| 257 dict->SetString("url", request->url.possibly_invalid_spec()); | |
| 258 dict->SetString("method", request->method); | |
| 259 return dict; | |
| 260 } | |
| 261 | |
| 241 } // namespace | 262 } // namespace |
| 242 | 263 |
| 243 namespace net { | 264 namespace net { |
| 244 | 265 |
| 245 struct HeaderNameAndValue { | 266 struct HeaderNameAndValue { |
| 246 const char* name; | 267 const char* name; |
| 247 const char* value; | 268 const char* value; |
| 248 }; | 269 }; |
| 249 | 270 |
| 250 // If the request includes one of these request headers, then avoid caching | 271 // If the request includes one of these request headers, then avoid caching |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 return network_trans_->GetLoadState(); | 426 return network_trans_->GetLoadState(); |
| 406 if (entry_ || !request_) | 427 if (entry_ || !request_) |
| 407 return LOAD_STATE_IDLE; | 428 return LOAD_STATE_IDLE; |
| 408 return LOAD_STATE_WAITING_FOR_CACHE; | 429 return LOAD_STATE_WAITING_FOR_CACHE; |
| 409 } | 430 } |
| 410 | 431 |
| 411 const BoundNetLog& HttpCache::Transaction::net_log() const { | 432 const BoundNetLog& HttpCache::Transaction::net_log() const { |
| 412 return net_log_; | 433 return net_log_; |
| 413 } | 434 } |
| 414 | 435 |
| 436 void HttpCache::Transaction::ValidateInternalCache() { | |
| 437 DCHECK(!request_); // Start() should not have been called. | |
| 438 effective_load_flags_ |= LOAD_VALIDATE_CACHE; | |
| 439 } | |
| 440 | |
| 415 int HttpCache::Transaction::Start(const HttpRequestInfo* request, | 441 int HttpCache::Transaction::Start(const HttpRequestInfo* request, |
| 416 const CompletionCallback& callback, | 442 const CompletionCallback& callback, |
| 417 const BoundNetLog& net_log) { | 443 const BoundNetLog& net_log) { |
| 418 DCHECK(request); | 444 DCHECK(request); |
| 419 DCHECK(!callback.is_null()); | 445 DCHECK(!callback.is_null()); |
| 420 | 446 |
| 421 // Ensure that we only have one asynchronous call at a time. | 447 // Ensure that we only have one asynchronous call at a time. |
| 422 DCHECK(callback_.is_null()); | 448 DCHECK(callback_.is_null()); |
| 423 DCHECK(!reading_); | 449 DCHECK(!reading_); |
| 424 DCHECK(!network_trans_.get()); | 450 DCHECK(!network_trans_.get()); |
| (...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1931 false /* is not leaf */, | 1957 false /* is not leaf */, |
| 1932 shared_chain_data)); | 1958 shared_chain_data)); |
| 1933 } | 1959 } |
| 1934 DCHECK_EQ(0, dist_from_root); | 1960 DCHECK_EQ(0, dist_from_root); |
| 1935 } | 1961 } |
| 1936 | 1962 |
| 1937 void HttpCache::Transaction::SetRequest(const BoundNetLog& net_log, | 1963 void HttpCache::Transaction::SetRequest(const BoundNetLog& net_log, |
| 1938 const HttpRequestInfo* request) { | 1964 const HttpRequestInfo* request) { |
| 1939 net_log_ = net_log; | 1965 net_log_ = net_log; |
| 1940 request_ = request; | 1966 request_ = request; |
| 1941 effective_load_flags_ = request_->load_flags; | 1967 // effective_load_flags_ may already have had LOAD_VALIDATE_CACHE set by the |
| 1968 // ValidateInternalCache() method. | |
| 1969 effective_load_flags_ |= request_->load_flags; | |
| 1942 | 1970 |
| 1943 switch (cache_->mode()) { | 1971 switch (cache_->mode()) { |
| 1944 case NORMAL: | 1972 case NORMAL: |
| 1945 break; | 1973 break; |
| 1946 case RECORD: | 1974 case RECORD: |
| 1947 // When in record mode, we want to NEVER load from the cache. | 1975 // When in record mode, we want to NEVER load from the cache. |
| 1948 // The reason for this is because we save the Set-Cookie headers | 1976 // The reason for this is because we save the Set-Cookie headers |
| 1949 // (intentionally). If we read from the cache, we replay them | 1977 // (intentionally). If we read from the cache, we replay them |
| 1950 // prematurely. | 1978 // prematurely. |
| 1951 effective_load_flags_ |= LOAD_BYPASS_CACHE; | 1979 effective_load_flags_ |= LOAD_BYPASS_CACHE; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2086 | 2114 |
| 2087 if (entry_->disk_entry->GetDataSize(kMetadataIndex)) | 2115 if (entry_->disk_entry->GetDataSize(kMetadataIndex)) |
| 2088 next_state_ = STATE_CACHE_READ_METADATA; | 2116 next_state_ = STATE_CACHE_READ_METADATA; |
| 2089 | 2117 |
| 2090 return OK; | 2118 return OK; |
| 2091 } | 2119 } |
| 2092 | 2120 |
| 2093 int HttpCache::Transaction::BeginCacheValidation() { | 2121 int HttpCache::Transaction::BeginCacheValidation() { |
| 2094 DCHECK(mode_ == READ_WRITE); | 2122 DCHECK(mode_ == READ_WRITE); |
| 2095 | 2123 |
| 2096 bool skip_validation = !RequiresValidation(); | 2124 ValidationType required_validation = RequiredValidationType(); |
| 2125 | |
| 2126 bool skip_validation = required_validation == VALIDATION_NONE; | |
| 2127 | |
| 2128 if (required_validation == VALIDATION_ASYNCHRONOUS && cache_ && | |
| 2129 cache_->use_stale_while_revalidate()) { | |
| 2130 TriggerAsyncValidation(); | |
| 2131 skip_validation = true; | |
| 2132 } | |
| 2097 | 2133 |
| 2098 if (request_->method == "HEAD" && | 2134 if (request_->method == "HEAD" && |
| 2099 (truncated_ || response_.headers->response_code() == 206)) { | 2135 (truncated_ || response_.headers->response_code() == 206)) { |
| 2100 DCHECK(!partial_); | 2136 DCHECK(!partial_); |
| 2101 if (skip_validation) | 2137 if (skip_validation) |
| 2102 return SetupEntryForRead(); | 2138 return SetupEntryForRead(); |
| 2103 | 2139 |
| 2104 // Bail out! | 2140 // Bail out! |
| 2105 next_state_ = STATE_SEND_REQUEST; | 2141 next_state_ = STATE_SEND_REQUEST; |
| 2106 mode_ = NONE; | 2142 mode_ = NONE; |
| 2107 return OK; | 2143 return OK; |
| 2108 } | 2144 } |
| 2109 | 2145 |
| 2110 if (truncated_) { | 2146 if (truncated_) { |
| 2111 // Truncated entries can cause partial gets, so we shouldn't record this | 2147 // Truncated entries can cause partial gets, so we shouldn't record this |
| 2112 // load in histograms. | 2148 // load in histograms. |
| 2113 UpdateTransactionPattern(PATTERN_NOT_COVERED); | 2149 UpdateTransactionPattern(PATTERN_NOT_COVERED); |
| 2114 skip_validation = !partial_->initial_validation(); | 2150 skip_validation = !partial_->initial_validation(); |
| 2115 } | 2151 } |
| 2116 | 2152 |
| 2117 if (partial_.get() && (is_sparse_ || truncated_) && | 2153 if (partial_.get() && (is_sparse_ || truncated_) && |
| 2118 (!partial_->IsCurrentRangeCached() || invalid_range_)) { | 2154 (!partial_->IsCurrentRangeCached() || invalid_range_)) { |
| 2119 // Force revalidation for sparse or truncated entries. Note that we don't | 2155 // Force revalidation for sparse or truncated entries. Note that we don't |
| 2120 // want to ignore the regular validation logic just because a byte range was | 2156 // want to ignore the regular validation logic just because a byte range was |
| 2121 // part of the request. | 2157 // part of the request. |
| 2122 skip_validation = false; | 2158 skip_validation = false; |
| 2123 } | 2159 } |
| 2124 | 2160 |
| 2125 if (skip_validation) { | 2161 if (skip_validation) { |
| 2162 // TODO(ricea): Is this pattern okay for asynchronous revalidations? | |
| 2126 UpdateTransactionPattern(PATTERN_ENTRY_USED); | 2163 UpdateTransactionPattern(PATTERN_ENTRY_USED); |
| 2127 RecordOfflineStatus(effective_load_flags_, OFFLINE_STATUS_FRESH_CACHE); | 2164 RecordOfflineStatus(effective_load_flags_, OFFLINE_STATUS_FRESH_CACHE); |
| 2128 return SetupEntryForRead(); | 2165 return SetupEntryForRead(); |
| 2129 } else { | 2166 } else { |
| 2130 // Make the network request conditional, to see if we may reuse our cached | 2167 // Make the network request conditional, to see if we may reuse our cached |
| 2131 // response. If we cannot do so, then we just resort to a normal fetch. | 2168 // response. If we cannot do so, then we just resort to a normal fetch. |
| 2132 // Our mode remains READ_WRITE for a conditional request. Even if the | 2169 // Our mode remains READ_WRITE for a conditional request. Even if the |
| 2133 // conditionalization fails, we don't switch to WRITE mode until we | 2170 // conditionalization fails, we don't switch to WRITE mode until we |
| 2134 // know we won't be falling back to using the cache entry in the | 2171 // know we won't be falling back to using the cache entry in the |
| 2135 // LOAD_FROM_CACHE_IF_OFFLINE case. | 2172 // LOAD_FROM_CACHE_IF_OFFLINE case. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2255 DCHECK(network_trans_.get()); | 2292 DCHECK(network_trans_.get()); |
| 2256 DCHECK_EQ(STATE_NONE, next_state_); | 2293 DCHECK_EQ(STATE_NONE, next_state_); |
| 2257 | 2294 |
| 2258 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 2295 next_state_ = STATE_SEND_REQUEST_COMPLETE; |
| 2259 int rv = network_trans_->RestartWithAuth(credentials, io_callback_); | 2296 int rv = network_trans_->RestartWithAuth(credentials, io_callback_); |
| 2260 if (rv != ERR_IO_PENDING) | 2297 if (rv != ERR_IO_PENDING) |
| 2261 return DoLoop(rv); | 2298 return DoLoop(rv); |
| 2262 return rv; | 2299 return rv; |
| 2263 } | 2300 } |
| 2264 | 2301 |
| 2265 bool HttpCache::Transaction::RequiresValidation() { | 2302 ValidationType HttpCache::Transaction::RequiredValidationType() { |
| 2266 // TODO(darin): need to do more work here: | 2303 // TODO(darin): need to do more work here: |
| 2267 // - make sure we have a matching request method | 2304 // - make sure we have a matching request method |
| 2268 // - watch out for cached responses that depend on authentication | 2305 // - watch out for cached responses that depend on authentication |
| 2269 | 2306 |
| 2270 // In playback mode, nothing requires validation. | 2307 // In playback mode, nothing requires validation. |
| 2271 if (cache_->mode() == net::HttpCache::PLAYBACK) | 2308 if (cache_->mode() == net::HttpCache::PLAYBACK) |
| 2272 return false; | 2309 return VALIDATION_NONE; |
| 2273 | 2310 |
| 2274 if (response_.vary_data.is_valid() && | 2311 if (response_.vary_data.is_valid() && |
| 2275 !response_.vary_data.MatchesRequest(*request_, | 2312 !response_.vary_data.MatchesRequest(*request_, |
| 2276 *response_.headers.get())) { | 2313 *response_.headers.get())) { |
| 2277 vary_mismatch_ = true; | 2314 vary_mismatch_ = true; |
| 2278 return true; | 2315 return VALIDATION_SYNCHRONOUS; |
| 2279 } | 2316 } |
| 2280 | 2317 |
| 2281 if (effective_load_flags_ & LOAD_PREFERRING_CACHE) | 2318 if (effective_load_flags_ & LOAD_PREFERRING_CACHE) |
| 2282 return false; | 2319 return VALIDATION_NONE; |
| 2283 | 2320 |
| 2284 if (effective_load_flags_ & LOAD_VALIDATE_CACHE) | 2321 if (effective_load_flags_ & LOAD_VALIDATE_CACHE) |
| 2285 return true; | 2322 return VALIDATION_SYNCHRONOUS; |
| 2286 | 2323 |
| 2287 if (request_->method == "PUT" || request_->method == "DELETE") | 2324 if (request_->method == "PUT" || request_->method == "DELETE") |
| 2288 return true; | 2325 return VALIDATION_SYNCHRONOUS; |
| 2289 | 2326 |
| 2290 if (response_.headers->RequiresValidation( | 2327 ValidationType validation_required_by_headers = |
| 2291 response_.request_time, response_.response_time, Time::Now())) { | 2328 response_.headers->RequiresValidation( |
|
rvargas (doing something else)
2014/08/29 23:36:06
If you keep the name for ResponseHeaders::Requires
Adam Rice
2014/09/01 14:43:00
Done.
| |
| 2292 return true; | 2329 response_.request_time, response_.response_time, Time::Now()); |
| 2330 | |
| 2331 if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) { | |
| 2332 // Asynchronous revalidation is only supported for GET and HEAD methods. | |
| 2333 if (request_->method != "GET" && request_->method != "HEAD") | |
| 2334 return VALIDATION_SYNCHRONOUS; | |
| 2335 | |
| 2336 // Asynchronous revalidation of GETs can only be used for completely cached | |
| 2337 // resources. | |
| 2338 if (request_->method == "GET" && (truncated_ || partial_)) | |
|
rvargas (doing something else)
2014/08/29 23:36:06
This part belong on the caller side.
Adam Rice
2014/09/01 14:43:00
Done.
| |
| 2339 return VALIDATION_SYNCHRONOUS; | |
| 2293 } | 2340 } |
| 2294 | 2341 |
| 2295 return false; | 2342 return validation_required_by_headers; |
| 2296 } | 2343 } |
| 2297 | 2344 |
| 2298 bool HttpCache::Transaction::ConditionalizeRequest() { | 2345 bool HttpCache::Transaction::ConditionalizeRequest() { |
| 2299 DCHECK(response_.headers.get()); | 2346 DCHECK(response_.headers.get()); |
| 2300 | 2347 |
| 2301 if (request_->method == "PUT" || request_->method == "DELETE") | 2348 if (request_->method == "PUT" || request_->method == "DELETE") |
| 2302 return false; | 2349 return false; |
| 2303 | 2350 |
| 2304 // This only makes sense for cached 200 or 206 responses. | 2351 // This only makes sense for cached 200 or 206 responses. |
| 2305 if (response_.headers->response_code() != 200 && | 2352 if (response_.headers->response_code() != 200 && |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 2334 } | 2381 } |
| 2335 DCHECK(custom_request_.get()); | 2382 DCHECK(custom_request_.get()); |
| 2336 | 2383 |
| 2337 bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() && | 2384 bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() && |
| 2338 !invalid_range_; | 2385 !invalid_range_; |
| 2339 | 2386 |
| 2340 if (!use_if_range) { | 2387 if (!use_if_range) { |
| 2341 // stale-while-revalidate is not useful when we only have a partial response | 2388 // stale-while-revalidate is not useful when we only have a partial response |
| 2342 // cached, so don't set the header in that case. | 2389 // cached, so don't set the header in that case. |
| 2343 TimeDelta stale_while_revalidate; | 2390 TimeDelta stale_while_revalidate; |
| 2391 TimeDelta max_age; | |
| 2344 if (response_.headers->GetStaleWhileRevalidateValue( | 2392 if (response_.headers->GetStaleWhileRevalidateValue( |
| 2345 &stale_while_revalidate) && | 2393 &stale_while_revalidate) && |
| 2394 response_.headers->GetFreshnessLifetime(response_.response_time, | |
|
rvargas (doing something else)
2014/08/29 23:36:07
This pattern reads very weird: returning a value t
Adam Rice
2014/09/01 14:43:00
I have attempted to improve it. PTAL.
| |
| 2395 &max_age) != | |
| 2396 HttpResponseHeaders::NEVER_FRESH && | |
| 2346 stale_while_revalidate > TimeDelta()) { | 2397 stale_while_revalidate > TimeDelta()) { |
| 2347 TimeDelta max_age = | |
| 2348 response_.headers->GetFreshnessLifetime(response_.response_time); | |
| 2349 TimeDelta current_age = response_.headers->GetCurrentAge( | 2398 TimeDelta current_age = response_.headers->GetCurrentAge( |
| 2350 response_.request_time, response_.response_time, Time::Now()); | 2399 response_.request_time, response_.response_time, Time::Now()); |
| 2351 | 2400 |
| 2352 custom_request_->extra_headers.SetHeader( | 2401 custom_request_->extra_headers.SetHeader( |
| 2353 kFreshnessHeader, | 2402 kFreshnessHeader, |
| 2354 base::StringPrintf("max-age=%" PRId64 | 2403 base::StringPrintf("max-age=%" PRId64 |
| 2355 ",stale-while-revalidate=%" PRId64 ",age=%" PRId64, | 2404 ",stale-while-revalidate=%" PRId64 ",age=%" PRId64, |
| 2356 max_age.InSeconds(), | 2405 max_age.InSeconds(), |
| 2357 stale_while_revalidate.InSeconds(), | 2406 stale_while_revalidate.InSeconds(), |
| 2358 current_age.InSeconds())); | 2407 current_age.InSeconds())); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2516 } | 2565 } |
| 2517 | 2566 |
| 2518 void HttpCache::Transaction::FixHeadersForHead() { | 2567 void HttpCache::Transaction::FixHeadersForHead() { |
| 2519 if (response_.headers->response_code() == 206) { | 2568 if (response_.headers->response_code() == 206) { |
| 2520 response_.headers->RemoveHeader("Content-Length"); | 2569 response_.headers->RemoveHeader("Content-Length"); |
| 2521 response_.headers->RemoveHeader("Content-Range"); | 2570 response_.headers->RemoveHeader("Content-Range"); |
| 2522 response_.headers->ReplaceStatusLine("HTTP/1.1 200 OK"); | 2571 response_.headers->ReplaceStatusLine("HTTP/1.1 200 OK"); |
| 2523 } | 2572 } |
| 2524 } | 2573 } |
| 2525 | 2574 |
| 2575 void HttpCache::Transaction::TriggerAsyncValidation() { | |
| 2576 DCHECK(!request_->upload_data_stream); | |
| 2577 BoundNetLog async_revalidation_net_log( | |
| 2578 BoundNetLog::Make(net_log_.net_log(), NetLog::SOURCE_ASYNC_REVALIDATION)); | |
| 2579 net_log_.AddEvent( | |
| 2580 NetLog::TYPE_HTTP_CACHE_VALIDATE_RESOURCE_ASYNC, | |
| 2581 async_revalidation_net_log.source().ToEventParametersCallback()); | |
| 2582 async_revalidation_net_log.BeginEvent( | |
| 2583 NetLog::TYPE_ASYNC_REVALIDATION, | |
| 2584 base::Bind( | |
| 2585 &NetLogAsyncRevalidationInfoCallback, net_log_.source(), request_)); | |
| 2586 base::MessageLoop::current()->PostTask( | |
| 2587 FROM_HERE, | |
| 2588 base::Bind(&HttpCache::PerformAsyncValidation, | |
| 2589 cache_, | |
|
rvargas (doing something else)
2014/08/29 23:36:06
Is the intention here to use a weak pointer? (I be
Adam Rice
2014/09/01 14:43:00
Yes. I have added a comment.
| |
| 2590 *request_, | |
| 2591 async_revalidation_net_log)); | |
| 2592 } | |
| 2593 | |
| 2526 void HttpCache::Transaction::FailRangeRequest() { | 2594 void HttpCache::Transaction::FailRangeRequest() { |
| 2527 response_ = *new_response_; | 2595 response_ = *new_response_; |
| 2528 partial_->FixResponseHeaders(response_.headers.get(), false); | 2596 partial_->FixResponseHeaders(response_.headers.get(), false); |
| 2529 } | 2597 } |
| 2530 | 2598 |
| 2531 int HttpCache::Transaction::SetupEntryForRead() { | 2599 int HttpCache::Transaction::SetupEntryForRead() { |
| 2532 if (network_trans_) | 2600 if (network_trans_) |
| 2533 ResetNetworkTransaction(); | 2601 ResetNetworkTransaction(); |
| 2534 if (partial_.get()) { | 2602 if (partial_.get()) { |
| 2535 if (truncated_ || is_sparse_ || !invalid_range_) { | 2603 if (truncated_ || is_sparse_ || !invalid_range_) { |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2862 default: | 2930 default: |
| 2863 NOTREACHED(); | 2931 NOTREACHED(); |
| 2864 } | 2932 } |
| 2865 } | 2933 } |
| 2866 | 2934 |
| 2867 void HttpCache::Transaction::OnIOComplete(int result) { | 2935 void HttpCache::Transaction::OnIOComplete(int result) { |
| 2868 DoLoop(result); | 2936 DoLoop(result); |
| 2869 } | 2937 } |
| 2870 | 2938 |
| 2871 } // namespace net | 2939 } // namespace net |
| OLD | NEW |