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/memory/scoped_ptr.h" |
| 21 #include "base/metrics/field_trial.h" | 21 #include "base/metrics/field_trial.h" |
| 22 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
| 23 #include "base/metrics/sparse_histogram.h" | 23 #include "base/metrics/sparse_histogram.h" |
| 24 #include "base/profiler/scoped_tracker.h" | 24 #include "base/profiler/scoped_tracker.h" |
| 25 #include "base/rand_util.h" | 25 #include "base/rand_util.h" |
| 26 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
| 27 #include "base/strings/string_piece.h" | 27 #include "base/strings/string_piece.h" |
| 28 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
| 29 #include "base/strings/stringprintf.h" | 29 #include "base/strings/stringprintf.h" |
| 30 #include "base/time/clock.h" | |
| 30 #include "base/time/time.h" | 31 #include "base/time/time.h" |
| 31 #include "base/values.h" | 32 #include "base/values.h" |
| 32 #include "net/base/completion_callback.h" | 33 #include "net/base/completion_callback.h" |
| 33 #include "net/base/io_buffer.h" | 34 #include "net/base/io_buffer.h" |
| 34 #include "net/base/load_flags.h" | 35 #include "net/base/load_flags.h" |
| 35 #include "net/base/load_timing_info.h" | 36 #include "net/base/load_timing_info.h" |
| 36 #include "net/base/net_errors.h" | 37 #include "net/base/net_errors.h" |
| 37 #include "net/base/net_log.h" | 38 #include "net/base/net_log.h" |
| 38 #include "net/base/upload_data_stream.h" | 39 #include "net/base/upload_data_stream.h" |
| 39 #include "net/cert/cert_status_flags.h" | 40 #include "net/cert/cert_status_flags.h" |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 // SendRequest* -> SuccessfulSendRequest -> OverwriteCachedResponse | 836 // SendRequest* -> SuccessfulSendRequest -> OverwriteCachedResponse |
| 836 // | 837 // |
| 837 // 10. HEAD. Sparse entry, partially cached: | 838 // 10. HEAD. Sparse entry, partially cached: |
| 838 // Serve the request from the cache, as long as it doesn't require | 839 // Serve the request from the cache, as long as it doesn't require |
| 839 // revalidation. Ignore missing ranges when deciding to revalidate. If the | 840 // revalidation. Ignore missing ranges when deciding to revalidate. If the |
| 840 // entry requires revalidation, ignore the whole request and go to full pass | 841 // entry requires revalidation, ignore the whole request and go to full pass |
| 841 // through (the result of the HEAD request will NOT update the entry). | 842 // through (the result of the HEAD request will NOT update the entry). |
| 842 // | 843 // |
| 843 // Start(): Basically the same as example 7, as we never create a partial_ | 844 // Start(): Basically the same as example 7, as we never create a partial_ |
| 844 // object for this request. | 845 // object for this request. |
| 845 // | 846 // |
|
rvargas (doing something else)
2015/01/09 02:25:33
nit: keep this //
| |
| 846 int HttpCache::Transaction::DoLoop(int result) { | 847 int HttpCache::Transaction::DoLoop(int result) { |
| 847 DCHECK(next_state_ != STATE_NONE); | 848 DCHECK(next_state_ != STATE_NONE); |
| 848 | 849 |
| 849 int rv = result; | 850 int rv = result; |
| 850 do { | 851 do { |
| 851 State state = next_state_; | 852 State state = next_state_; |
| 852 next_state_ = STATE_NONE; | 853 next_state_ = STATE_NONE; |
| 853 switch (state) { | 854 switch (state) { |
| 854 case STATE_GET_BACKEND: | 855 case STATE_GET_BACKEND: |
| 855 DCHECK_EQ(OK, rv); | 856 DCHECK_EQ(OK, rv); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 944 DCHECK_EQ(OK, rv); | 945 DCHECK_EQ(OK, rv); |
| 945 rv = DoPartialHeadersReceived(); | 946 rv = DoPartialHeadersReceived(); |
| 946 break; | 947 break; |
| 947 case STATE_CACHE_READ_RESPONSE: | 948 case STATE_CACHE_READ_RESPONSE: |
| 948 DCHECK_EQ(OK, rv); | 949 DCHECK_EQ(OK, rv); |
| 949 rv = DoCacheReadResponse(); | 950 rv = DoCacheReadResponse(); |
| 950 break; | 951 break; |
| 951 case STATE_CACHE_READ_RESPONSE_COMPLETE: | 952 case STATE_CACHE_READ_RESPONSE_COMPLETE: |
| 952 rv = DoCacheReadResponseComplete(rv); | 953 rv = DoCacheReadResponseComplete(rv); |
| 953 break; | 954 break; |
| 955 case STATE_TOGGLE_UNUSED_SINCE_PREFETCH: | |
| 956 rv = DoCacheToggleUnusedSincePrefetch(); | |
|
rvargas (doing something else)
2014/12/24 02:15:24
DCHECK rv == ok?
jkarlin
2015/01/08 16:13:03
Done.
| |
| 957 break; | |
| 958 case STATE_TOGGLE_UNUSED_SINCE_PREFETCH_COMPLETE: | |
|
rvargas (doing something else)
2014/12/24 02:15:24
These states have to be incorporated on the commen
jkarlin
2015/01/08 16:13:03
Done.
| |
| 959 rv = DoCacheToggleUnusedSincePrefetchComplete(rv); | |
| 960 break; | |
| 954 case STATE_CACHE_WRITE_RESPONSE: | 961 case STATE_CACHE_WRITE_RESPONSE: |
| 955 DCHECK_EQ(OK, rv); | 962 DCHECK_EQ(OK, rv); |
| 956 rv = DoCacheWriteResponse(); | 963 rv = DoCacheWriteResponse(); |
| 957 break; | 964 break; |
| 958 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE: | 965 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE: |
| 959 DCHECK_EQ(OK, rv); | 966 DCHECK_EQ(OK, rv); |
| 960 rv = DoCacheWriteTruncatedResponse(); | 967 rv = DoCacheWriteTruncatedResponse(); |
| 961 break; | 968 break; |
| 962 case STATE_CACHE_WRITE_RESPONSE_COMPLETE: | 969 case STATE_CACHE_WRITE_RESPONSE_COMPLETE: |
| 963 rv = DoCacheWriteResponseComplete(rv); | 970 rv = DoCacheWriteResponseComplete(rv); |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1527 // We received 304 or 206 and we want to update the cached response headers. | 1534 // We received 304 or 206 and we want to update the cached response headers. |
| 1528 int HttpCache::Transaction::DoUpdateCachedResponse() { | 1535 int HttpCache::Transaction::DoUpdateCachedResponse() { |
| 1529 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; | 1536 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; |
| 1530 int rv = OK; | 1537 int rv = OK; |
| 1531 // Update cached response based on headers in new_response. | 1538 // Update cached response based on headers in new_response. |
| 1532 // TODO(wtc): should we update cached certificate (response_.ssl_info), too? | 1539 // TODO(wtc): should we update cached certificate (response_.ssl_info), too? |
| 1533 response_.headers->Update(*new_response_->headers.get()); | 1540 response_.headers->Update(*new_response_->headers.get()); |
| 1534 response_.response_time = new_response_->response_time; | 1541 response_.response_time = new_response_->response_time; |
| 1535 response_.request_time = new_response_->request_time; | 1542 response_.request_time = new_response_->request_time; |
| 1536 response_.network_accessed = new_response_->network_accessed; | 1543 response_.network_accessed = new_response_->network_accessed; |
| 1544 response_.unused_since_prefetch = new_response_->unused_since_prefetch; | |
| 1537 | 1545 |
| 1538 if (response_.headers->HasHeaderValue("cache-control", "no-store")) { | 1546 if (response_.headers->HasHeaderValue("cache-control", "no-store")) { |
| 1539 if (!entry_->doomed) { | 1547 if (!entry_->doomed) { |
| 1540 int ret = cache_->DoomEntry(cache_key_, NULL); | 1548 int ret = cache_->DoomEntry(cache_key_, NULL); |
| 1541 DCHECK_EQ(OK, ret); | 1549 DCHECK_EQ(OK, ret); |
| 1542 } | 1550 } |
| 1543 } else { | 1551 } else { |
| 1544 // If we are already reading, we already updated the headers for this | 1552 // If we are already reading, we already updated the headers for this |
| 1545 // request; doing it again will change Content-Length. | 1553 // request; doing it again will change Content-Length. |
| 1546 if (!reading_) { | 1554 if (!reading_) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1560 // | 1568 // |
| 1561 // By closing the cached entry now, we make sure that the 304 rather than | 1569 // By closing the cached entry now, we make sure that the 304 rather than |
| 1562 // the cached 200 response, is what will be returned to the user. | 1570 // the cached 200 response, is what will be returned to the user. |
| 1563 DoneWritingToEntry(true); | 1571 DoneWritingToEntry(true); |
| 1564 } else if (entry_ && !handling_206_) { | 1572 } else if (entry_ && !handling_206_) { |
| 1565 DCHECK_EQ(READ_WRITE, mode_); | 1573 DCHECK_EQ(READ_WRITE, mode_); |
| 1566 if (!partial_.get() || partial_->IsLastRange()) { | 1574 if (!partial_.get() || partial_->IsLastRange()) { |
| 1567 cache_->ConvertWriterToReader(entry_); | 1575 cache_->ConvertWriterToReader(entry_); |
| 1568 mode_ = READ; | 1576 mode_ = READ; |
| 1569 } | 1577 } |
| 1578 | |
| 1570 // We no longer need the network transaction, so destroy it. | 1579 // We no longer need the network transaction, so destroy it. |
| 1571 final_upload_progress_ = network_trans_->GetUploadProgress(); | 1580 final_upload_progress_ = network_trans_->GetUploadProgress(); |
| 1572 ResetNetworkTransaction(); | 1581 ResetNetworkTransaction(); |
| 1573 } else if (entry_ && handling_206_ && truncated_ && | 1582 } else if (entry_ && handling_206_ && truncated_ && |
| 1574 partial_->initial_validation()) { | 1583 partial_->initial_validation()) { |
| 1575 // We just finished the validation of a truncated entry, and the server | 1584 // We just finished the validation of a truncated entry, and the server |
| 1576 // is willing to resume the operation. Now we go back and start serving | 1585 // is willing to resume the operation. Now we go back and start serving |
| 1577 // the first part to the user. | 1586 // the first part to the user. |
| 1578 ResetNetworkTransaction(); | 1587 ResetNetworkTransaction(); |
| 1579 new_response_ = NULL; | 1588 new_response_ = NULL; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1700 | 1709 |
| 1701 // cert_cache() will be null if the CertCacheTrial field trial is disabled. | 1710 // cert_cache() will be null if the CertCacheTrial field trial is disabled. |
| 1702 if (cache_->cert_cache() && response_.ssl_info.is_valid()) | 1711 if (cache_->cert_cache() && response_.ssl_info.is_valid()) |
| 1703 ReadCertChain(); | 1712 ReadCertChain(); |
| 1704 | 1713 |
| 1705 // Some resources may have slipped in as truncated when they're not. | 1714 // Some resources may have slipped in as truncated when they're not. |
| 1706 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); | 1715 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); |
| 1707 if (response_.headers->GetContentLength() == current_size) | 1716 if (response_.headers->GetContentLength() == current_size) |
| 1708 truncated_ = false; | 1717 truncated_ = false; |
| 1709 | 1718 |
| 1719 if (response_.unused_since_prefetch || | |
| 1720 (!response_.unused_since_prefetch && | |
|
rvargas (doing something else)
2014/12/24 02:15:24
!response_.unused_since_prefetch seems unnecessary
jkarlin
2015/01/08 16:13:03
Thanks!
| |
| 1721 request_->load_flags & LOAD_PREFETCH)) { | |
| 1722 // Either this is the first use of an entry since it was prefetched or | |
| 1723 // this is a prefetch. The value of response.unused_since_prefetch is valid | |
| 1724 // for this transaction but the bit needs to be flipped in storage. | |
| 1725 next_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH; | |
|
rvargas (doing something else)
2014/12/24 02:15:24
looks like this is not really toggle, as two conse
jkarlin
2015/01/08 16:13:04
Nice catch on two consecutive prefetches. Fixed an
| |
| 1726 return OK; | |
| 1727 } | |
| 1728 | |
| 1729 return DoCacheReadResponseCompleteContinuation(); | |
|
rvargas (doing something else)
2014/12/24 02:15:24
This begs to be a dedicated state on the machine.
jkarlin
2015/01/08 16:13:03
Done.
| |
| 1730 } | |
| 1731 | |
| 1732 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetch() { | |
| 1733 // Write back the toggled value for the next use of this entry. | |
| 1734 response_.unused_since_prefetch = !response_.unused_since_prefetch; | |
| 1735 | |
| 1736 // TODO(jkarlin): If DoUpdateCachedResponse is also called for this | |
| 1737 // transaction then metadata will be written to cache twice. If prefetching | |
| 1738 // becomes more common, consider combining the writes. | |
| 1739 target_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH_COMPLETE; | |
| 1740 next_state_ = STATE_CACHE_WRITE_RESPONSE; | |
| 1741 return OK; | |
| 1742 } | |
| 1743 | |
| 1744 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetchComplete( | |
| 1745 int result) { | |
| 1746 // Restore the original value for this transaction. | |
| 1747 response_.unused_since_prefetch = !response_.unused_since_prefetch; | |
| 1748 | |
| 1749 return DoCacheReadResponseCompleteContinuation(); | |
| 1750 } | |
| 1751 | |
| 1752 int HttpCache::Transaction::DoCacheReadResponseCompleteContinuation() { | |
| 1710 // We now have access to the cache entry. | 1753 // We now have access to the cache entry. |
| 1711 // | 1754 // |
| 1712 // o if we are a reader for the transaction, then we can start reading the | 1755 // o if we are a reader for the transaction, then we can start reading the |
| 1713 // cache entry. | 1756 // cache entry. |
| 1714 // | 1757 // |
| 1715 // o if we can read or write, then we should check if the cache entry needs | 1758 // o if we can read or write, then we should check if the cache entry needs |
| 1716 // to be validated and then issue a network request if needed or just read | 1759 // to be validated and then issue a network request if needed or just read |
| 1717 // from the cache if the cache entry is already valid. | 1760 // from the cache if the cache entry is already valid. |
| 1718 // | 1761 // |
| 1719 // o if we are set to UPDATE, then we are handling an externally | 1762 // o if we are set to UPDATE, then we are handling an externally |
| 1720 // conditionalized request (if-modified-since / if-none-match). We check | 1763 // conditionalized request (if-modified-since / if-none-match). We check |
| 1721 // if the request headers define a validation request. | 1764 // if the request headers define a validation request. |
| 1722 // | 1765 // |
| 1766 int result = ERR_FAILED; | |
| 1723 switch (mode_) { | 1767 switch (mode_) { |
| 1724 case READ: | 1768 case READ: |
| 1725 UpdateTransactionPattern(PATTERN_ENTRY_USED); | 1769 UpdateTransactionPattern(PATTERN_ENTRY_USED); |
| 1726 result = BeginCacheRead(); | 1770 result = BeginCacheRead(); |
| 1727 break; | 1771 break; |
| 1728 case READ_WRITE: | 1772 case READ_WRITE: |
| 1729 result = BeginPartialCacheValidation(); | 1773 result = BeginPartialCacheValidation(); |
| 1730 break; | 1774 break; |
| 1731 case UPDATE: | 1775 case UPDATE: |
| 1732 result = BeginExternallyConditionalizedRequest(); | 1776 result = BeginExternallyConditionalizedRequest(); |
| 1733 break; | 1777 break; |
| 1734 case WRITE: | 1778 case WRITE: |
| 1735 default: | 1779 default: |
| 1736 NOTREACHED(); | 1780 NOTREACHED(); |
| 1737 result = ERR_FAILED; | 1781 result = ERR_FAILED; |
|
rvargas (doing something else)
2014/12/24 02:15:24
nit: this line is now redundant.
jkarlin
2015/01/08 16:13:03
Done.
| |
| 1738 } | 1782 } |
| 1739 return result; | 1783 return result; |
| 1740 } | 1784 } |
| 1741 | 1785 |
| 1742 int HttpCache::Transaction::DoCacheWriteResponse() { | 1786 int HttpCache::Transaction::DoCacheWriteResponse() { |
| 1743 if (entry_) { | 1787 if (entry_) { |
| 1744 if (net_log_.IsLogging()) | 1788 if (net_log_.IsLogging()) |
| 1745 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | 1789 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
| 1746 } | 1790 } |
| 1747 return WriteResponseInfoToEntry(false); | 1791 return WriteResponseInfoToEntry(false); |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2165 // Force revalidation for sparse or truncated entries. Note that we don't | 2209 // Force revalidation for sparse or truncated entries. Note that we don't |
| 2166 // want to ignore the regular validation logic just because a byte range was | 2210 // want to ignore the regular validation logic just because a byte range was |
| 2167 // part of the request. | 2211 // part of the request. |
| 2168 skip_validation = false; | 2212 skip_validation = false; |
| 2169 } | 2213 } |
| 2170 | 2214 |
| 2171 if (skip_validation) { | 2215 if (skip_validation) { |
| 2172 // TODO(ricea): Is this pattern okay for asynchronous revalidations? | 2216 // TODO(ricea): Is this pattern okay for asynchronous revalidations? |
| 2173 UpdateTransactionPattern(PATTERN_ENTRY_USED); | 2217 UpdateTransactionPattern(PATTERN_ENTRY_USED); |
| 2174 RecordOfflineStatus(effective_load_flags_, OFFLINE_STATUS_FRESH_CACHE); | 2218 RecordOfflineStatus(effective_load_flags_, OFFLINE_STATUS_FRESH_CACHE); |
| 2219 | |
|
rvargas (doing something else)
2014/12/24 02:15:24
?
jkarlin
2015/01/08 16:13:03
Done.
| |
| 2175 return SetupEntryForRead(); | 2220 return SetupEntryForRead(); |
| 2176 } else { | 2221 } else { |
| 2177 // Make the network request conditional, to see if we may reuse our cached | 2222 // Make the network request conditional, to see if we may reuse our cached |
| 2178 // response. If we cannot do so, then we just resort to a normal fetch. | 2223 // response. If we cannot do so, then we just resort to a normal fetch. |
| 2179 // Our mode remains READ_WRITE for a conditional request. Even if the | 2224 // Our mode remains READ_WRITE for a conditional request. Even if the |
| 2180 // conditionalization fails, we don't switch to WRITE mode until we | 2225 // conditionalization fails, we don't switch to WRITE mode until we |
| 2181 // know we won't be falling back to using the cache entry in the | 2226 // know we won't be falling back to using the cache entry in the |
| 2182 // LOAD_FROM_CACHE_IF_OFFLINE case. | 2227 // LOAD_FROM_CACHE_IF_OFFLINE case. |
| 2183 if (!ConditionalizeRequest()) { | 2228 if (!ConditionalizeRequest()) { |
| 2184 couldnt_conditionalize_request_ = true; | 2229 couldnt_conditionalize_request_ = true; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2337 if (response_.vary_data.is_valid() && | 2382 if (response_.vary_data.is_valid() && |
| 2338 !response_.vary_data.MatchesRequest(*request_, | 2383 !response_.vary_data.MatchesRequest(*request_, |
| 2339 *response_.headers.get())) { | 2384 *response_.headers.get())) { |
| 2340 vary_mismatch_ = true; | 2385 vary_mismatch_ = true; |
| 2341 return VALIDATION_SYNCHRONOUS; | 2386 return VALIDATION_SYNCHRONOUS; |
| 2342 } | 2387 } |
| 2343 | 2388 |
| 2344 if (effective_load_flags_ & LOAD_PREFERRING_CACHE) | 2389 if (effective_load_flags_ & LOAD_PREFERRING_CACHE) |
| 2345 return VALIDATION_NONE; | 2390 return VALIDATION_NONE; |
| 2346 | 2391 |
| 2392 if (response_.unused_since_prefetch && | |
| 2393 response_.headers->GetCurrentAge( | |
| 2394 response_.request_time, response_.response_time, | |
| 2395 cache_->clock_->Now()) < TimeDelta::FromMinutes(kPrefetchReuseMins)) { | |
| 2396 // The first use of a resource after prefetch within a short window skips | |
| 2397 // validation. | |
| 2398 return VALIDATION_NONE; | |
| 2399 } | |
| 2400 | |
| 2347 if (effective_load_flags_ & (LOAD_VALIDATE_CACHE | LOAD_ASYNC_REVALIDATION)) | 2401 if (effective_load_flags_ & (LOAD_VALIDATE_CACHE | LOAD_ASYNC_REVALIDATION)) |
| 2348 return VALIDATION_SYNCHRONOUS; | 2402 return VALIDATION_SYNCHRONOUS; |
| 2349 | 2403 |
| 2350 if (request_->method == "PUT" || request_->method == "DELETE") | 2404 if (request_->method == "PUT" || request_->method == "DELETE") |
| 2351 return VALIDATION_SYNCHRONOUS; | 2405 return VALIDATION_SYNCHRONOUS; |
| 2352 | 2406 |
| 2353 ValidationType validation_required_by_headers = | 2407 ValidationType validation_required_by_headers = |
| 2354 response_.headers->RequiresValidation( | 2408 response_.headers->RequiresValidation(response_.request_time, |
| 2355 response_.request_time, response_.response_time, Time::Now()); | 2409 response_.response_time, |
| 2410 cache_->clock_->Now()); | |
| 2356 | 2411 |
| 2357 if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) { | 2412 if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) { |
| 2358 // Asynchronous revalidation is only supported for GET and HEAD methods. | 2413 // Asynchronous revalidation is only supported for GET and HEAD methods. |
| 2359 if (request_->method != "GET" && request_->method != "HEAD") | 2414 if (request_->method != "GET" && request_->method != "HEAD") |
| 2360 return VALIDATION_SYNCHRONOUS; | 2415 return VALIDATION_SYNCHRONOUS; |
| 2361 } | 2416 } |
| 2362 | 2417 |
| 2363 return validation_required_by_headers; | 2418 return validation_required_by_headers; |
| 2364 } | 2419 } |
| 2365 | 2420 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2406 bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() && | 2461 bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() && |
| 2407 !invalid_range_; | 2462 !invalid_range_; |
| 2408 | 2463 |
| 2409 if (!use_if_range) { | 2464 if (!use_if_range) { |
| 2410 // stale-while-revalidate is not useful when we only have a partial response | 2465 // stale-while-revalidate is not useful when we only have a partial response |
| 2411 // cached, so don't set the header in that case. | 2466 // cached, so don't set the header in that case. |
| 2412 HttpResponseHeaders::FreshnessLifetimes lifetimes = | 2467 HttpResponseHeaders::FreshnessLifetimes lifetimes = |
| 2413 response_.headers->GetFreshnessLifetimes(response_.response_time); | 2468 response_.headers->GetFreshnessLifetimes(response_.response_time); |
| 2414 if (lifetimes.staleness > TimeDelta()) { | 2469 if (lifetimes.staleness > TimeDelta()) { |
| 2415 TimeDelta current_age = response_.headers->GetCurrentAge( | 2470 TimeDelta current_age = response_.headers->GetCurrentAge( |
| 2416 response_.request_time, response_.response_time, Time::Now()); | 2471 response_.request_time, response_.response_time, |
| 2472 cache_->clock_->Now()); | |
| 2417 | 2473 |
| 2418 custom_request_->extra_headers.SetHeader( | 2474 custom_request_->extra_headers.SetHeader( |
| 2419 kFreshnessHeader, | 2475 kFreshnessHeader, |
| 2420 base::StringPrintf("max-age=%" PRId64 | 2476 base::StringPrintf("max-age=%" PRId64 |
| 2421 ",stale-while-revalidate=%" PRId64 ",age=%" PRId64, | 2477 ",stale-while-revalidate=%" PRId64 ",age=%" PRId64, |
| 2422 lifetimes.freshness.InSeconds(), | 2478 lifetimes.freshness.InSeconds(), |
| 2423 lifetimes.staleness.InSeconds(), | 2479 lifetimes.staleness.InSeconds(), |
| 2424 current_age.InSeconds())); | 2480 current_age.InSeconds())); |
| 2425 } | 2481 } |
| 2426 } | 2482 } |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2952 | 3008 |
| 2953 void HttpCache::Transaction::OnIOComplete(int result) { | 3009 void HttpCache::Transaction::OnIOComplete(int result) { |
| 2954 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 3010 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 2955 tracked_objects::ScopedTracker tracking_profile( | 3011 tracked_objects::ScopedTracker tracking_profile( |
| 2956 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete")); | 3012 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete")); |
| 2957 | 3013 |
| 2958 DoLoop(result); | 3014 DoLoop(result); |
| 2959 } | 3015 } |
| 2960 | 3016 |
| 2961 } // namespace net | 3017 } // namespace net |
| OLD | NEW |