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

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: Test nits 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, unused_since_prefetch is true:
858 // Like examples 2-4, only CacheToggleUnusedSincePrefetch* is inserted between
rvargas (doing something else) 2015/01/09 20:16:13 mind making this explicit? Assuming the entry is u
jkarlin 2015/01/12 13:01:14 Done.
859 // CacheReadResponse* and CacheDispatchValidation and a validation request is
860 // not sent if the entry is less than 5 minutes old.
846 int HttpCache::Transaction::DoLoop(int result) { 861 int HttpCache::Transaction::DoLoop(int result) {
847 DCHECK(next_state_ != STATE_NONE); 862 DCHECK(next_state_ != STATE_NONE);
848 863
849 int rv = result; 864 int rv = result;
850 do { 865 do {
851 State state = next_state_; 866 State state = next_state_;
852 next_state_ = STATE_NONE; 867 next_state_ = STATE_NONE;
853 switch (state) { 868 switch (state) {
854 case STATE_GET_BACKEND: 869 case STATE_GET_BACKEND:
855 DCHECK_EQ(OK, rv); 870 DCHECK_EQ(OK, rv);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 DCHECK_EQ(OK, rv); 959 DCHECK_EQ(OK, rv);
945 rv = DoPartialHeadersReceived(); 960 rv = DoPartialHeadersReceived();
946 break; 961 break;
947 case STATE_CACHE_READ_RESPONSE: 962 case STATE_CACHE_READ_RESPONSE:
948 DCHECK_EQ(OK, rv); 963 DCHECK_EQ(OK, rv);
949 rv = DoCacheReadResponse(); 964 rv = DoCacheReadResponse();
950 break; 965 break;
951 case STATE_CACHE_READ_RESPONSE_COMPLETE: 966 case STATE_CACHE_READ_RESPONSE_COMPLETE:
952 rv = DoCacheReadResponseComplete(rv); 967 rv = DoCacheReadResponseComplete(rv);
953 break; 968 break;
969 case STATE_CACHE_DISPATCH_VALIDATION:
970 DCHECK_EQ(OK, rv);
971 rv = DoCacheDispatchValidation();
972 break;
973 case STATE_TOGGLE_UNUSED_SINCE_PREFETCH:
974 DCHECK_EQ(OK, rv);
975 rv = DoCacheToggleUnusedSincePrefetch();
976 break;
977 case STATE_TOGGLE_UNUSED_SINCE_PREFETCH_COMPLETE:
978 rv = DoCacheToggleUnusedSincePrefetchComplete(rv);
979 break;
954 case STATE_CACHE_WRITE_RESPONSE: 980 case STATE_CACHE_WRITE_RESPONSE:
955 DCHECK_EQ(OK, rv); 981 DCHECK_EQ(OK, rv);
956 rv = DoCacheWriteResponse(); 982 rv = DoCacheWriteResponse();
957 break; 983 break;
958 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE: 984 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE:
959 DCHECK_EQ(OK, rv); 985 DCHECK_EQ(OK, rv);
960 rv = DoCacheWriteTruncatedResponse(); 986 rv = DoCacheWriteTruncatedResponse();
961 break; 987 break;
962 case STATE_CACHE_WRITE_RESPONSE_COMPLETE: 988 case STATE_CACHE_WRITE_RESPONSE_COMPLETE:
963 rv = DoCacheWriteResponseComplete(rv); 989 rv = DoCacheWriteResponseComplete(rv);
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 "422516 HttpCache::Transaction::DoUpdateCachedResponse")); 1649 "422516 HttpCache::Transaction::DoUpdateCachedResponse"));
1624 1650
1625 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; 1651 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE;
1626 int rv = OK; 1652 int rv = OK;
1627 // Update cached response based on headers in new_response. 1653 // Update cached response based on headers in new_response.
1628 // TODO(wtc): should we update cached certificate (response_.ssl_info), too? 1654 // TODO(wtc): should we update cached certificate (response_.ssl_info), too?
1629 response_.headers->Update(*new_response_->headers.get()); 1655 response_.headers->Update(*new_response_->headers.get());
1630 response_.response_time = new_response_->response_time; 1656 response_.response_time = new_response_->response_time;
1631 response_.request_time = new_response_->request_time; 1657 response_.request_time = new_response_->request_time;
1632 response_.network_accessed = new_response_->network_accessed; 1658 response_.network_accessed = new_response_->network_accessed;
1659 response_.unused_since_prefetch = new_response_->unused_since_prefetch;
1633 1660
1634 if (response_.headers->HasHeaderValue("cache-control", "no-store")) { 1661 if (response_.headers->HasHeaderValue("cache-control", "no-store")) {
1635 if (!entry_->doomed) { 1662 if (!entry_->doomed) {
1636 int ret = cache_->DoomEntry(cache_key_, NULL); 1663 int ret = cache_->DoomEntry(cache_key_, NULL);
1637 DCHECK_EQ(OK, ret); 1664 DCHECK_EQ(OK, ret);
1638 } 1665 }
1639 } else { 1666 } else {
1640 // If we are already reading, we already updated the headers for this 1667 // If we are already reading, we already updated the headers for this
1641 // request; doing it again will change Content-Length. 1668 // request; doing it again will change Content-Length.
1642 if (!reading_) { 1669 if (!reading_) {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1841 1868
1842 // cert_cache() will be null if the CertCacheTrial field trial is disabled. 1869 // cert_cache() will be null if the CertCacheTrial field trial is disabled.
1843 if (cache_->cert_cache() && response_.ssl_info.is_valid()) 1870 if (cache_->cert_cache() && response_.ssl_info.is_valid())
1844 ReadCertChain(); 1871 ReadCertChain();
1845 1872
1846 // Some resources may have slipped in as truncated when they're not. 1873 // Some resources may have slipped in as truncated when they're not.
1847 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); 1874 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex);
1848 if (response_.headers->GetContentLength() == current_size) 1875 if (response_.headers->GetContentLength() == current_size)
1849 truncated_ = false; 1876 truncated_ = false;
1850 1877
1878 if ((response_.unused_since_prefetch &&
1879 !(request_->load_flags & LOAD_PREFETCH)) ||
1880 (!response_.unused_since_prefetch &&
1881 (request_->load_flags & LOAD_PREFETCH))) {
1882 // Either this is the first use of an entry since it was prefetched or
1883 // this is a prefetch. The value of response.unused_since_prefetch is valid
1884 // for this transaction but the bit needs to be flipped in storage.
1885 next_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH;
1886 return OK;
1887 }
1888
1889 next_state_ = STATE_CACHE_DISPATCH_VALIDATION;
1890 return OK;
1891 }
1892
1893 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetch() {
1894 // Write back the toggled value for the next use of this entry.
1895 response_.unused_since_prefetch = !response_.unused_since_prefetch;
1896
1897 // TODO(jkarlin): If DoUpdateCachedResponse is also called for this
1898 // transaction then metadata will be written to cache twice. If prefetching
1899 // becomes more common, consider combining the writes.
1900 target_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH_COMPLETE;
1901 next_state_ = STATE_CACHE_WRITE_RESPONSE;
1902 return OK;
1903 }
1904
1905 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetchComplete(
1906 int result) {
1907 // Restore the original value for this transaction.
1908 response_.unused_since_prefetch = !response_.unused_since_prefetch;
1909 next_state_ = STATE_CACHE_DISPATCH_VALIDATION;
1910 return OK;
1911 }
1912
1913 int HttpCache::Transaction::DoCacheDispatchValidation() {
rvargas (doing something else) 2015/01/09 20:16:13 Time to make sure that method definition follows t
jkarlin 2015/01/12 13:01:14 Done. Thanks!
1851 // We now have access to the cache entry. 1914 // We now have access to the cache entry.
1852 // 1915 //
1853 // o if we are a reader for the transaction, then we can start reading the 1916 // o if we are a reader for the transaction, then we can start reading the
1854 // cache entry. 1917 // cache entry.
1855 // 1918 //
1856 // o if we can read or write, then we should check if the cache entry needs 1919 // 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 1920 // 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. 1921 // from the cache if the cache entry is already valid.
1859 // 1922 //
1860 // o if we are set to UPDATE, then we are handling an externally 1923 // o if we are set to UPDATE, then we are handling an externally
1861 // conditionalized request (if-modified-since / if-none-match). We check 1924 // conditionalized request (if-modified-since / if-none-match). We check
1862 // if the request headers define a validation request. 1925 // if the request headers define a validation request.
1863 // 1926 //
1927 int result = ERR_FAILED;
1864 switch (mode_) { 1928 switch (mode_) {
1865 case READ: 1929 case READ:
1866 UpdateTransactionPattern(PATTERN_ENTRY_USED); 1930 UpdateTransactionPattern(PATTERN_ENTRY_USED);
1867 result = BeginCacheRead(); 1931 result = BeginCacheRead();
1868 break; 1932 break;
1869 case READ_WRITE: 1933 case READ_WRITE:
1870 result = BeginPartialCacheValidation(); 1934 result = BeginPartialCacheValidation();
1871 break; 1935 break;
1872 case UPDATE: 1936 case UPDATE:
1873 result = BeginExternallyConditionalizedRequest(); 1937 result = BeginExternallyConditionalizedRequest();
1874 break; 1938 break;
1875 case WRITE: 1939 case WRITE:
1876 default: 1940 default:
1877 NOTREACHED(); 1941 NOTREACHED();
1878 result = ERR_FAILED;
1879 } 1942 }
1880 return result; 1943 return result;
1881 } 1944 }
1882 1945
1883 int HttpCache::Transaction::DoCacheWriteResponse() { 1946 int HttpCache::Transaction::DoCacheWriteResponse() {
1884 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. 1947 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed.
1885 tracked_objects::ScopedTracker tracking_profile( 1948 tracked_objects::ScopedTracker tracking_profile(
1886 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1949 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1887 "422516 HttpCache::Transaction::DoCacheWriteResponse")); 1950 "422516 HttpCache::Transaction::DoCacheWriteResponse"));
1888 1951
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
2538 if (response_.vary_data.is_valid() && 2601 if (response_.vary_data.is_valid() &&
2539 !response_.vary_data.MatchesRequest(*request_, 2602 !response_.vary_data.MatchesRequest(*request_,
2540 *response_.headers.get())) { 2603 *response_.headers.get())) {
2541 vary_mismatch_ = true; 2604 vary_mismatch_ = true;
2542 return VALIDATION_SYNCHRONOUS; 2605 return VALIDATION_SYNCHRONOUS;
2543 } 2606 }
2544 2607
2545 if (effective_load_flags_ & LOAD_PREFERRING_CACHE) 2608 if (effective_load_flags_ & LOAD_PREFERRING_CACHE)
2546 return VALIDATION_NONE; 2609 return VALIDATION_NONE;
2547 2610
2611 if (response_.unused_since_prefetch &&
2612 !(effective_load_flags_ & LOAD_PREFETCH) &&
2613 response_.headers->GetCurrentAge(
2614 response_.request_time, response_.response_time,
2615 cache_->clock_->Now()) < TimeDelta::FromMinutes(kPrefetchReuseMins)) {
2616 // The first use of a resource after prefetch within a short window skips
2617 // validation.
2618 return VALIDATION_NONE;
2619 }
2620
2548 if (effective_load_flags_ & (LOAD_VALIDATE_CACHE | LOAD_ASYNC_REVALIDATION)) 2621 if (effective_load_flags_ & (LOAD_VALIDATE_CACHE | LOAD_ASYNC_REVALIDATION))
2549 return VALIDATION_SYNCHRONOUS; 2622 return VALIDATION_SYNCHRONOUS;
2550 2623
2551 if (request_->method == "PUT" || request_->method == "DELETE") 2624 if (request_->method == "PUT" || request_->method == "DELETE")
2552 return VALIDATION_SYNCHRONOUS; 2625 return VALIDATION_SYNCHRONOUS;
2553 2626
2554 ValidationType validation_required_by_headers = 2627 ValidationType validation_required_by_headers =
2555 response_.headers->RequiresValidation( 2628 response_.headers->RequiresValidation(response_.request_time,
2556 response_.request_time, response_.response_time, Time::Now()); 2629 response_.response_time,
2630 cache_->clock_->Now());
2557 2631
2558 if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) { 2632 if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) {
2559 // Asynchronous revalidation is only supported for GET and HEAD methods. 2633 // Asynchronous revalidation is only supported for GET and HEAD methods.
2560 if (request_->method != "GET" && request_->method != "HEAD") 2634 if (request_->method != "GET" && request_->method != "HEAD")
2561 return VALIDATION_SYNCHRONOUS; 2635 return VALIDATION_SYNCHRONOUS;
2562 } 2636 }
2563 2637
2564 return validation_required_by_headers; 2638 return validation_required_by_headers;
2565 } 2639 }
2566 2640
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2607 bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() && 2681 bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() &&
2608 !invalid_range_; 2682 !invalid_range_;
2609 2683
2610 if (!use_if_range) { 2684 if (!use_if_range) {
2611 // stale-while-revalidate is not useful when we only have a partial response 2685 // stale-while-revalidate is not useful when we only have a partial response
2612 // cached, so don't set the header in that case. 2686 // cached, so don't set the header in that case.
2613 HttpResponseHeaders::FreshnessLifetimes lifetimes = 2687 HttpResponseHeaders::FreshnessLifetimes lifetimes =
2614 response_.headers->GetFreshnessLifetimes(response_.response_time); 2688 response_.headers->GetFreshnessLifetimes(response_.response_time);
2615 if (lifetimes.staleness > TimeDelta()) { 2689 if (lifetimes.staleness > TimeDelta()) {
2616 TimeDelta current_age = response_.headers->GetCurrentAge( 2690 TimeDelta current_age = response_.headers->GetCurrentAge(
2617 response_.request_time, response_.response_time, Time::Now()); 2691 response_.request_time, response_.response_time,
2692 cache_->clock_->Now());
2618 2693
2619 custom_request_->extra_headers.SetHeader( 2694 custom_request_->extra_headers.SetHeader(
2620 kFreshnessHeader, 2695 kFreshnessHeader,
2621 base::StringPrintf("max-age=%" PRId64 2696 base::StringPrintf("max-age=%" PRId64
2622 ",stale-while-revalidate=%" PRId64 ",age=%" PRId64, 2697 ",stale-while-revalidate=%" PRId64 ",age=%" PRId64,
2623 lifetimes.freshness.InSeconds(), 2698 lifetimes.freshness.InSeconds(),
2624 lifetimes.staleness.InSeconds(), 2699 lifetimes.staleness.InSeconds(),
2625 current_age.InSeconds())); 2700 current_age.InSeconds()));
2626 } 2701 }
2627 } 2702 }
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
3165 3240
3166 void HttpCache::Transaction::OnIOComplete(int result) { 3241 void HttpCache::Transaction::OnIOComplete(int result) {
3167 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. 3242 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed.
3168 tracked_objects::ScopedTracker tracking_profile( 3243 tracked_objects::ScopedTracker tracking_profile(
3169 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete")); 3244 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete"));
3170 3245
3171 DoLoop(result); 3246 DoLoop(result);
3172 } 3247 }
3173 3248
3174 } // namespace net 3249 } // 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