Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: net/http/http_cache_transaction.cc

Issue 793823002: Let prefetched resources skip cache revalidation once for a short duration. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments from PS8 Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_cache_transaction.h ('k') | net/http/http_cache_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 // SendRequest* -> SuccessfulSendRequest -> OverwriteCachedResponse -> 750 // SendRequest* -> SuccessfulSendRequest -> OverwriteCachedResponse ->
750 // CacheWriteResponse* -> TruncateCachedData* -> TruncateCachedMetadata* -> 751 // CacheWriteResponse* -> TruncateCachedData* -> TruncateCachedMetadata* ->
751 // PartialHeadersReceived 752 // PartialHeadersReceived
752 // 753 //
753 // Read(): 754 // Read():
754 // NetworkRead* -> CacheWriteData* 755 // NetworkRead* -> CacheWriteData*
755 // 756 //
756 // 2. Cached entry, no validation: 757 // 2. Cached entry, no validation:
757 // Start(): 758 // Start():
758 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* 759 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse*
759 // -> BeginPartialCacheValidation() -> BeginCacheValidation() -> 760 // -> CacheDispatchValidation -> BeginPartialCacheValidation() ->
760 // SetupEntryForRead() 761 // BeginCacheValidation() -> SetupEntryForRead()
761 // 762 //
762 // Read(): 763 // Read():
763 // CacheReadData* 764 // CacheReadData*
764 // 765 //
765 // 3. Cached entry, validation (304): 766 // 3. Cached entry, validation (304):
766 // Start(): 767 // Start():
767 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* 768 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse*
768 // -> BeginPartialCacheValidation() -> BeginCacheValidation() -> 769 // -> CacheDispatchValidation -> BeginPartialCacheValidation() ->
769 // SendRequest* -> SuccessfulSendRequest -> UpdateCachedResponse -> 770 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest ->
770 // CacheWriteResponse* -> UpdateCachedResponseComplete -> 771 // UpdateCachedResponse -> CacheWriteResponse* -> UpdateCachedResponseComplete
771 // OverwriteCachedResponse -> PartialHeadersReceived 772 // -> OverwriteCachedResponse -> PartialHeadersReceived
772 // 773 //
773 // Read(): 774 // Read():
774 // CacheReadData* 775 // CacheReadData*
775 // 776 //
776 // 4. Cached entry, validation and replace (200): 777 // 4. Cached entry, validation and replace (200):
777 // Start(): 778 // Start():
778 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* 779 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse*
779 // -> BeginPartialCacheValidation() -> BeginCacheValidation() -> 780 // -> CacheDispatchValidation -> BeginPartialCacheValidation() ->
780 // SendRequest* -> SuccessfulSendRequest -> OverwriteCachedResponse -> 781 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest ->
781 // CacheWriteResponse* -> DoTruncateCachedData* -> TruncateCachedMetadata* -> 782 // OverwriteCachedResponse -> CacheWriteResponse* -> DoTruncateCachedData* ->
782 // PartialHeadersReceived 783 // TruncateCachedMetadata* -> PartialHeadersReceived
783 // 784 //
784 // Read(): 785 // Read():
785 // NetworkRead* -> CacheWriteData* 786 // NetworkRead* -> CacheWriteData*
786 // 787 //
787 // 5. Sparse entry, partially cached, byte range request: 788 // 5. Sparse entry, partially cached, byte range request:
788 // Start(): 789 // Start():
789 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* 790 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse*
790 // -> BeginPartialCacheValidation() -> CacheQueryData* -> 791 // -> CacheDispatchValidation -> BeginPartialCacheValidation() ->
791 // ValidateEntryHeadersAndContinue() -> StartPartialCacheValidation -> 792 // CacheQueryData* -> ValidateEntryHeadersAndContinue() ->
792 // CompletePartialCacheValidation -> BeginCacheValidation() -> SendRequest* -> 793 // StartPartialCacheValidation -> CompletePartialCacheValidation ->
793 // SuccessfulSendRequest -> UpdateCachedResponse -> CacheWriteResponse* -> 794 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest ->
794 // UpdateCachedResponseComplete -> OverwriteCachedResponse -> 795 // UpdateCachedResponse -> CacheWriteResponse* -> UpdateCachedResponseComplete
795 // PartialHeadersReceived 796 // -> OverwriteCachedResponse -> PartialHeadersReceived
796 // 797 //
797 // Read() 1: 798 // Read() 1:
798 // NetworkRead* -> CacheWriteData* 799 // NetworkRead* -> CacheWriteData*
799 // 800 //
800 // Read() 2: 801 // Read() 2:
801 // NetworkRead* -> CacheWriteData* -> StartPartialCacheValidation -> 802 // NetworkRead* -> CacheWriteData* -> StartPartialCacheValidation ->
802 // CompletePartialCacheValidation -> CacheReadData* -> 803 // CompletePartialCacheValidation -> CacheReadData* ->
803 // 804 //
804 // Read() 3: 805 // Read() 3:
805 // CacheReadData* -> StartPartialCacheValidation -> 806 // CacheReadData* -> StartPartialCacheValidation ->
(...skipping 18 matching lines...) Expand all
824 // Start(): Same as for a GET request (example #3) 825 // Start(): Same as for a GET request (example #3)
825 // 826 //
826 // Read(): 827 // Read():
827 // CacheReadData (returns 0) 828 // CacheReadData (returns 0)
828 // 829 //
829 // 9. HEAD. Cached entry, validation and replace (200): 830 // 9. HEAD. Cached entry, validation and replace (200):
830 // Pass through. The request dooms the old entry, as a HEAD won't be stored by 831 // Pass through. The request dooms the old entry, as a HEAD won't be stored by
831 // itself. 832 // itself.
832 // Start(): 833 // Start():
833 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* 834 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse*
834 // -> BeginPartialCacheValidation() -> BeginCacheValidation() -> 835 // -> CacheDispatchValidation -> BeginPartialCacheValidation() ->
835 // SendRequest* -> SuccessfulSendRequest -> OverwriteCachedResponse 836 // BeginCacheValidation() -> SendRequest* -> SuccessfulSendRequest ->
837 // OverwriteCachedResponse
836 // 838 //
837 // 10. HEAD. Sparse entry, partially cached: 839 // 10. HEAD. Sparse entry, partially cached:
838 // Serve the request from the cache, as long as it doesn't require 840 // Serve the request from the cache, as long as it doesn't require
839 // revalidation. Ignore missing ranges when deciding to revalidate. If the 841 // revalidation. Ignore missing ranges when deciding to revalidate. If the
840 // entry requires revalidation, ignore the whole request and go to full pass 842 // 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). 843 // through (the result of the HEAD request will NOT update the entry).
842 // 844 //
843 // Start(): Basically the same as example 7, as we never create a partial_ 845 // Start(): Basically the same as example 7, as we never create a partial_
844 // object for this request. 846 // object for this request.
845 // 847 //
848 // 11. Prefetch, not-cached entry:
849 // The same as example 1. The "unused_since_prefetch" bit is stored as true in
850 // UpdateCachedResponse.
851 //
852 // 12. Prefetch, cached entry:
853 // Like examples 2-4, only CacheToggleUnusedSincePrefetch* is inserted between
854 // CacheReadResponse* and CacheDispatchValidation if the unused_since_prefetch
855 // bit is unset.
856 //
857 // 13. Cached entry less than 5 minutes old, unused_since_prefetch is true:
858 // Skip validation, similar to example 2.
859 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse*
860 // -> CacheToggleUnusedSincePrefetch* -> CacheDispatchValidation ->
861 // BeginPartialCacheValidation() -> BeginCacheValidation() ->
862 // SetupEntryForRead()
863 //
864 // Read():
865 // CacheReadData*
866 //
867 // 14. Cached entry more than 5 minutes old, unused_since_prefetch is true:
868 // Like examples 2-4, only CacheToggleUnusedSincePrefetch* is inserted between
869 // CacheReadResponse* and CacheDispatchValidation.
846 int HttpCache::Transaction::DoLoop(int result) { 870 int HttpCache::Transaction::DoLoop(int result) {
847 DCHECK(next_state_ != STATE_NONE); 871 DCHECK(next_state_ != STATE_NONE);
848 872
849 int rv = result; 873 int rv = result;
850 do { 874 do {
851 State state = next_state_; 875 State state = next_state_;
852 next_state_ = STATE_NONE; 876 next_state_ = STATE_NONE;
853 switch (state) { 877 switch (state) {
854 case STATE_GET_BACKEND: 878 case STATE_GET_BACKEND:
855 DCHECK_EQ(OK, rv); 879 DCHECK_EQ(OK, rv);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 DCHECK_EQ(OK, rv); 968 DCHECK_EQ(OK, rv);
945 rv = DoPartialHeadersReceived(); 969 rv = DoPartialHeadersReceived();
946 break; 970 break;
947 case STATE_CACHE_READ_RESPONSE: 971 case STATE_CACHE_READ_RESPONSE:
948 DCHECK_EQ(OK, rv); 972 DCHECK_EQ(OK, rv);
949 rv = DoCacheReadResponse(); 973 rv = DoCacheReadResponse();
950 break; 974 break;
951 case STATE_CACHE_READ_RESPONSE_COMPLETE: 975 case STATE_CACHE_READ_RESPONSE_COMPLETE:
952 rv = DoCacheReadResponseComplete(rv); 976 rv = DoCacheReadResponseComplete(rv);
953 break; 977 break;
978 case STATE_CACHE_DISPATCH_VALIDATION:
979 DCHECK_EQ(OK, rv);
980 rv = DoCacheDispatchValidation();
981 break;
982 case STATE_TOGGLE_UNUSED_SINCE_PREFETCH:
983 DCHECK_EQ(OK, rv);
984 rv = DoCacheToggleUnusedSincePrefetch();
985 break;
986 case STATE_TOGGLE_UNUSED_SINCE_PREFETCH_COMPLETE:
987 rv = DoCacheToggleUnusedSincePrefetchComplete(rv);
988 break;
954 case STATE_CACHE_WRITE_RESPONSE: 989 case STATE_CACHE_WRITE_RESPONSE:
955 DCHECK_EQ(OK, rv); 990 DCHECK_EQ(OK, rv);
956 rv = DoCacheWriteResponse(); 991 rv = DoCacheWriteResponse();
957 break; 992 break;
958 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE: 993 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE:
959 DCHECK_EQ(OK, rv); 994 DCHECK_EQ(OK, rv);
960 rv = DoCacheWriteTruncatedResponse(); 995 rv = DoCacheWriteTruncatedResponse();
961 break; 996 break;
962 case STATE_CACHE_WRITE_RESPONSE_COMPLETE: 997 case STATE_CACHE_WRITE_RESPONSE_COMPLETE:
963 rv = DoCacheWriteResponseComplete(rv); 998 rv = DoCacheWriteResponseComplete(rv);
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 "422516 HttpCache::Transaction::DoUpdateCachedResponse")); 1658 "422516 HttpCache::Transaction::DoUpdateCachedResponse"));
1624 1659
1625 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; 1660 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE;
1626 int rv = OK; 1661 int rv = OK;
1627 // Update cached response based on headers in new_response. 1662 // Update cached response based on headers in new_response.
1628 // TODO(wtc): should we update cached certificate (response_.ssl_info), too? 1663 // TODO(wtc): should we update cached certificate (response_.ssl_info), too?
1629 response_.headers->Update(*new_response_->headers.get()); 1664 response_.headers->Update(*new_response_->headers.get());
1630 response_.response_time = new_response_->response_time; 1665 response_.response_time = new_response_->response_time;
1631 response_.request_time = new_response_->request_time; 1666 response_.request_time = new_response_->request_time;
1632 response_.network_accessed = new_response_->network_accessed; 1667 response_.network_accessed = new_response_->network_accessed;
1668 response_.unused_since_prefetch = new_response_->unused_since_prefetch;
1633 1669
1634 if (response_.headers->HasHeaderValue("cache-control", "no-store")) { 1670 if (response_.headers->HasHeaderValue("cache-control", "no-store")) {
1635 if (!entry_->doomed) { 1671 if (!entry_->doomed) {
1636 int ret = cache_->DoomEntry(cache_key_, NULL); 1672 int ret = cache_->DoomEntry(cache_key_, NULL);
1637 DCHECK_EQ(OK, ret); 1673 DCHECK_EQ(OK, ret);
1638 } 1674 }
1639 } else { 1675 } else {
1640 // If we are already reading, we already updated the headers for this 1676 // If we are already reading, we already updated the headers for this
1641 // request; doing it again will change Content-Length. 1677 // request; doing it again will change Content-Length.
1642 if (!reading_) { 1678 if (!reading_) {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1841 1877
1842 // cert_cache() will be null if the CertCacheTrial field trial is disabled. 1878 // cert_cache() will be null if the CertCacheTrial field trial is disabled.
1843 if (cache_->cert_cache() && response_.ssl_info.is_valid()) 1879 if (cache_->cert_cache() && response_.ssl_info.is_valid())
1844 ReadCertChain(); 1880 ReadCertChain();
1845 1881
1846 // Some resources may have slipped in as truncated when they're not. 1882 // Some resources may have slipped in as truncated when they're not.
1847 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); 1883 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex);
1848 if (response_.headers->GetContentLength() == current_size) 1884 if (response_.headers->GetContentLength() == current_size)
1849 truncated_ = false; 1885 truncated_ = false;
1850 1886
1887 if ((response_.unused_since_prefetch &&
1888 !(request_->load_flags & LOAD_PREFETCH)) ||
1889 (!response_.unused_since_prefetch &&
1890 (request_->load_flags & LOAD_PREFETCH))) {
1891 // Either this is the first use of an entry since it was prefetched or
1892 // this is a prefetch. The value of response.unused_since_prefetch is valid
1893 // for this transaction but the bit needs to be flipped in storage.
1894 next_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH;
1895 return OK;
1896 }
1897
1898 next_state_ = STATE_CACHE_DISPATCH_VALIDATION;
1899 return OK;
1900 }
1901
1902 int HttpCache::Transaction::DoCacheDispatchValidation() {
1851 // We now have access to the cache entry. 1903 // We now have access to the cache entry.
1852 // 1904 //
1853 // o if we are a reader for the transaction, then we can start reading the 1905 // o if we are a reader for the transaction, then we can start reading the
1854 // cache entry. 1906 // cache entry.
1855 // 1907 //
1856 // o if we can read or write, then we should check if the cache entry needs 1908 // o if we can read or write, then we should check if the cache entry needs
1857 // to be validated and then issue a network request if needed or just read 1909 // to be validated and then issue a network request if needed or just read
1858 // from the cache if the cache entry is already valid. 1910 // from the cache if the cache entry is already valid.
1859 // 1911 //
1860 // o if we are set to UPDATE, then we are handling an externally 1912 // o if we are set to UPDATE, then we are handling an externally
1861 // conditionalized request (if-modified-since / if-none-match). We check 1913 // conditionalized request (if-modified-since / if-none-match). We check
1862 // if the request headers define a validation request. 1914 // if the request headers define a validation request.
1863 // 1915 //
1916 int result = ERR_FAILED;
1864 switch (mode_) { 1917 switch (mode_) {
1865 case READ: 1918 case READ:
1866 UpdateTransactionPattern(PATTERN_ENTRY_USED); 1919 UpdateTransactionPattern(PATTERN_ENTRY_USED);
1867 result = BeginCacheRead(); 1920 result = BeginCacheRead();
1868 break; 1921 break;
1869 case READ_WRITE: 1922 case READ_WRITE:
1870 result = BeginPartialCacheValidation(); 1923 result = BeginPartialCacheValidation();
1871 break; 1924 break;
1872 case UPDATE: 1925 case UPDATE:
1873 result = BeginExternallyConditionalizedRequest(); 1926 result = BeginExternallyConditionalizedRequest();
1874 break; 1927 break;
1875 case WRITE: 1928 case WRITE:
1876 default: 1929 default:
1877 NOTREACHED(); 1930 NOTREACHED();
1878 result = ERR_FAILED;
1879 } 1931 }
1880 return result; 1932 return result;
1881 } 1933 }
1882 1934
1935 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetch() {
1936 // Write back the toggled value for the next use of this entry.
1937 response_.unused_since_prefetch = !response_.unused_since_prefetch;
1938
1939 // TODO(jkarlin): If DoUpdateCachedResponse is also called for this
1940 // transaction then metadata will be written to cache twice. If prefetching
1941 // becomes more common, consider combining the writes.
1942 target_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH_COMPLETE;
1943 next_state_ = STATE_CACHE_WRITE_RESPONSE;
1944 return OK;
1945 }
1946
1947 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetchComplete(
1948 int result) {
1949 // Restore the original value for this transaction.
1950 response_.unused_since_prefetch = !response_.unused_since_prefetch;
1951 next_state_ = STATE_CACHE_DISPATCH_VALIDATION;
1952 return OK;
1953 }
1954
1883 int HttpCache::Transaction::DoCacheWriteResponse() { 1955 int HttpCache::Transaction::DoCacheWriteResponse() {
1884 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. 1956 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed.
1885 tracked_objects::ScopedTracker tracking_profile( 1957 tracked_objects::ScopedTracker tracking_profile(
1886 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1958 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1887 "422516 HttpCache::Transaction::DoCacheWriteResponse")); 1959 "422516 HttpCache::Transaction::DoCacheWriteResponse"));
1888 1960
1889 if (entry_) { 1961 if (entry_) {
1890 if (net_log_.IsLogging()) 1962 if (net_log_.IsLogging())
1891 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); 1963 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO);
1892 } 1964 }
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
2538 if (response_.vary_data.is_valid() && 2610 if (response_.vary_data.is_valid() &&
2539 !response_.vary_data.MatchesRequest(*request_, 2611 !response_.vary_data.MatchesRequest(*request_,
2540 *response_.headers.get())) { 2612 *response_.headers.get())) {
2541 vary_mismatch_ = true; 2613 vary_mismatch_ = true;
2542 return VALIDATION_SYNCHRONOUS; 2614 return VALIDATION_SYNCHRONOUS;
2543 } 2615 }
2544 2616
2545 if (effective_load_flags_ & LOAD_PREFERRING_CACHE) 2617 if (effective_load_flags_ & LOAD_PREFERRING_CACHE)
2546 return VALIDATION_NONE; 2618 return VALIDATION_NONE;
2547 2619
2620 if (response_.unused_since_prefetch &&
2621 !(effective_load_flags_ & LOAD_PREFETCH) &&
2622 response_.headers->GetCurrentAge(
2623 response_.request_time, response_.response_time,
2624 cache_->clock_->Now()) < TimeDelta::FromMinutes(kPrefetchReuseMins)) {
2625 // The first use of a resource after prefetch within a short window skips
2626 // validation.
2627 return VALIDATION_NONE;
2628 }
2629
2548 if (effective_load_flags_ & (LOAD_VALIDATE_CACHE | LOAD_ASYNC_REVALIDATION)) 2630 if (effective_load_flags_ & (LOAD_VALIDATE_CACHE | LOAD_ASYNC_REVALIDATION))
2549 return VALIDATION_SYNCHRONOUS; 2631 return VALIDATION_SYNCHRONOUS;
2550 2632
2551 if (request_->method == "PUT" || request_->method == "DELETE") 2633 if (request_->method == "PUT" || request_->method == "DELETE")
2552 return VALIDATION_SYNCHRONOUS; 2634 return VALIDATION_SYNCHRONOUS;
2553 2635
2554 ValidationType validation_required_by_headers = 2636 ValidationType validation_required_by_headers =
2555 response_.headers->RequiresValidation( 2637 response_.headers->RequiresValidation(response_.request_time,
2556 response_.request_time, response_.response_time, Time::Now()); 2638 response_.response_time,
2639 cache_->clock_->Now());
2557 2640
2558 if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) { 2641 if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) {
2559 // Asynchronous revalidation is only supported for GET and HEAD methods. 2642 // Asynchronous revalidation is only supported for GET and HEAD methods.
2560 if (request_->method != "GET" && request_->method != "HEAD") 2643 if (request_->method != "GET" && request_->method != "HEAD")
2561 return VALIDATION_SYNCHRONOUS; 2644 return VALIDATION_SYNCHRONOUS;
2562 } 2645 }
2563 2646
2564 return validation_required_by_headers; 2647 return validation_required_by_headers;
2565 } 2648 }
2566 2649
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2607 bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() && 2690 bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() &&
2608 !invalid_range_; 2691 !invalid_range_;
2609 2692
2610 if (!use_if_range) { 2693 if (!use_if_range) {
2611 // stale-while-revalidate is not useful when we only have a partial response 2694 // stale-while-revalidate is not useful when we only have a partial response
2612 // cached, so don't set the header in that case. 2695 // cached, so don't set the header in that case.
2613 HttpResponseHeaders::FreshnessLifetimes lifetimes = 2696 HttpResponseHeaders::FreshnessLifetimes lifetimes =
2614 response_.headers->GetFreshnessLifetimes(response_.response_time); 2697 response_.headers->GetFreshnessLifetimes(response_.response_time);
2615 if (lifetimes.staleness > TimeDelta()) { 2698 if (lifetimes.staleness > TimeDelta()) {
2616 TimeDelta current_age = response_.headers->GetCurrentAge( 2699 TimeDelta current_age = response_.headers->GetCurrentAge(
2617 response_.request_time, response_.response_time, Time::Now()); 2700 response_.request_time, response_.response_time,
2701 cache_->clock_->Now());
2618 2702
2619 custom_request_->extra_headers.SetHeader( 2703 custom_request_->extra_headers.SetHeader(
2620 kFreshnessHeader, 2704 kFreshnessHeader,
2621 base::StringPrintf("max-age=%" PRId64 2705 base::StringPrintf("max-age=%" PRId64
2622 ",stale-while-revalidate=%" PRId64 ",age=%" PRId64, 2706 ",stale-while-revalidate=%" PRId64 ",age=%" PRId64,
2623 lifetimes.freshness.InSeconds(), 2707 lifetimes.freshness.InSeconds(),
2624 lifetimes.staleness.InSeconds(), 2708 lifetimes.staleness.InSeconds(),
2625 current_age.InSeconds())); 2709 current_age.InSeconds()));
2626 } 2710 }
2627 } 2711 }
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
3165 3249
3166 void HttpCache::Transaction::OnIOComplete(int result) { 3250 void HttpCache::Transaction::OnIOComplete(int result) {
3167 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. 3251 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed.
3168 tracked_objects::ScopedTracker tracking_profile( 3252 tracked_objects::ScopedTracker tracking_profile(
3169 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete")); 3253 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete"));
3170 3254
3171 DoLoop(result); 3255 DoLoop(result);
3172 } 3256 }
3173 3257
3174 } // namespace net 3258 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_cache_transaction.h ('k') | net/http/http_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698