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 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
734 } | 735 } |
735 | 736 |
736 int HttpCache::Transaction::HandleResult(int rv) { | 737 int HttpCache::Transaction::HandleResult(int rv) { |
737 DCHECK(rv != ERR_IO_PENDING); | 738 DCHECK(rv != ERR_IO_PENDING); |
738 if (!callback_.is_null()) | 739 if (!callback_.is_null()) |
739 DoCallback(rv); | 740 DoCallback(rv); |
740 | 741 |
741 return rv; | 742 return rv; |
742 } | 743 } |
743 | 744 |
744 // A few common patterns: (Foo* means Foo -> FooComplete) | 745 // A few common patterns: Foo* means Foo -> FooComplete |
746 // [Foo] means state Foo may be skipped | |
rvargas (doing something else)
2015/01/09 02:25:34
Instead of adding an optional state pairs to known
jkarlin
2015/01/09 14:03:50
Done.
| |
747 // | |
745 // | 748 // |
746 // 1. Not-cached entry: | 749 // 1. Not-cached entry: |
747 // Start(): | 750 // Start(): |
748 // GetBackend* -> InitEntry -> OpenEntry* -> CreateEntry* -> AddToEntry* -> | 751 // GetBackend* -> InitEntry -> OpenEntry* -> CreateEntry* -> AddToEntry* -> |
749 // SendRequest* -> SuccessfulSendRequest -> OverwriteCachedResponse -> | 752 // SendRequest* -> SuccessfulSendRequest -> OverwriteCachedResponse -> |
750 // CacheWriteResponse* -> TruncateCachedData* -> TruncateCachedMetadata* -> | 753 // CacheWriteResponse* -> TruncateCachedData* -> TruncateCachedMetadata* -> |
751 // PartialHeadersReceived | 754 // PartialHeadersReceived |
752 // | 755 // |
753 // Read(): | 756 // Read(): |
754 // NetworkRead* -> CacheWriteData* | 757 // NetworkRead* -> CacheWriteData* |
755 // | 758 // |
756 // 2. Cached entry, no validation: | 759 // 2. Cached entry, no validation: |
757 // Start(): | 760 // Start(): |
758 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* | 761 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* |
759 // -> BeginPartialCacheValidation() -> BeginCacheValidation() -> | 762 // -> [CacheToggleUnusedSincePrefetch*] -> CacheReadResponseContinue -> |
763 // BeginPartialCacheValidation() -> BeginCacheValidation() -> | |
760 // SetupEntryForRead() | 764 // SetupEntryForRead() |
761 // | 765 // |
762 // Read(): | 766 // Read(): |
763 // CacheReadData* | 767 // CacheReadData* |
764 // | 768 // |
765 // 3. Cached entry, validation (304): | 769 // 3. Cached entry, validation (304): |
766 // Start(): | 770 // Start(): |
767 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* | 771 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* |
768 // -> BeginPartialCacheValidation() -> BeginCacheValidation() -> | 772 // -> [CacheToggleUnusedSincePrefetch*] -> CacheReadResponseContinue -> |
769 // SendRequest* -> SuccessfulSendRequest -> UpdateCachedResponse -> | 773 // BeginPartialCacheValidation() -> BeginCacheValidation() -> SendRequest* -> |
770 // CacheWriteResponse* -> UpdateCachedResponseComplete -> | 774 // SuccessfulSendRequest -> UpdateCachedResponse -> CacheWriteResponse* -> |
771 // OverwriteCachedResponse -> PartialHeadersReceived | 775 // UpdateCachedResponseComplete -> OverwriteCachedResponse -> |
776 // PartialHeadersReceived | |
772 // | 777 // |
773 // Read(): | 778 // Read(): |
774 // CacheReadData* | 779 // CacheReadData* |
775 // | 780 // |
776 // 4. Cached entry, validation and replace (200): | 781 // 4. Cached entry, validation and replace (200): |
777 // Start(): | 782 // Start(): |
778 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* | 783 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* |
779 // -> BeginPartialCacheValidation() -> BeginCacheValidation() -> | 784 // -> [CacheToggleUnusedSincePrefetch*] -> CacheReadResponseContinue -> |
780 // SendRequest* -> SuccessfulSendRequest -> OverwriteCachedResponse -> | 785 // BeginPartialCacheValidation() -> BeginCacheValidation() -> SendRequest* -> |
781 // CacheWriteResponse* -> DoTruncateCachedData* -> TruncateCachedMetadata* -> | 786 // SuccessfulSendRequest -> OverwriteCachedResponse -> CacheWriteResponse* -> |
782 // PartialHeadersReceived | 787 // DoTruncateCachedData* -> TruncateCachedMetadata* -> PartialHeadersReceived |
783 // | 788 // |
784 // Read(): | 789 // Read(): |
785 // NetworkRead* -> CacheWriteData* | 790 // NetworkRead* -> CacheWriteData* |
786 // | 791 // |
787 // 5. Sparse entry, partially cached, byte range request: | 792 // 5. Sparse entry, partially cached, byte range request: |
788 // Start(): | 793 // Start(): |
789 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* | 794 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* |
790 // -> BeginPartialCacheValidation() -> CacheQueryData* -> | 795 // -> [CacheToggleUnusedSincePrefetch*] -> CacheReadResponseContinue -> |
796 // BeginPartialCacheValidation() -> CacheQueryData* -> | |
791 // ValidateEntryHeadersAndContinue() -> StartPartialCacheValidation -> | 797 // ValidateEntryHeadersAndContinue() -> StartPartialCacheValidation -> |
792 // CompletePartialCacheValidation -> BeginCacheValidation() -> SendRequest* -> | 798 // CompletePartialCacheValidation -> BeginCacheValidation() -> SendRequest* -> |
793 // SuccessfulSendRequest -> UpdateCachedResponse -> CacheWriteResponse* -> | 799 // SuccessfulSendRequest -> UpdateCachedResponse -> CacheWriteResponse* -> |
794 // UpdateCachedResponseComplete -> OverwriteCachedResponse -> | 800 // UpdateCachedResponseComplete -> OverwriteCachedResponse -> |
795 // PartialHeadersReceived | 801 // PartialHeadersReceived |
796 // | 802 // |
797 // Read() 1: | 803 // Read() 1: |
798 // NetworkRead* -> CacheWriteData* | 804 // NetworkRead* -> CacheWriteData* |
799 // | 805 // |
800 // Read() 2: | 806 // Read() 2: |
(...skipping 23 matching lines...) Expand all Loading... | |
824 // Start(): Same as for a GET request (example #3) | 830 // Start(): Same as for a GET request (example #3) |
825 // | 831 // |
826 // Read(): | 832 // Read(): |
827 // CacheReadData (returns 0) | 833 // CacheReadData (returns 0) |
828 // | 834 // |
829 // 9. HEAD. Cached entry, validation and replace (200): | 835 // 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 | 836 // Pass through. The request dooms the old entry, as a HEAD won't be stored by |
831 // itself. | 837 // itself. |
832 // Start(): | 838 // Start(): |
833 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* | 839 // GetBackend* -> InitEntry -> OpenEntry* -> AddToEntry* -> CacheReadResponse* |
834 // -> BeginPartialCacheValidation() -> BeginCacheValidation() -> | 840 // -> [CacheToggleUnusedSincePrefetch*] -> CacheReadResponseContinue -> |
835 // SendRequest* -> SuccessfulSendRequest -> OverwriteCachedResponse | 841 // BeginPartialCacheValidation() -> BeginCacheValidation() -> SendRequest* -> |
842 // SuccessfulSendRequest -> OverwriteCachedResponse | |
836 // | 843 // |
837 // 10. HEAD. Sparse entry, partially cached: | 844 // 10. HEAD. Sparse entry, partially cached: |
838 // Serve the request from the cache, as long as it doesn't require | 845 // Serve the request from the cache, as long as it doesn't require |
839 // revalidation. Ignore missing ranges when deciding to revalidate. If the | 846 // revalidation. Ignore missing ranges when deciding to revalidate. If the |
840 // entry requires revalidation, ignore the whole request and go to full pass | 847 // 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). | 848 // through (the result of the HEAD request will NOT update the entry). |
842 // | 849 // |
843 // Start(): Basically the same as example 7, as we never create a partial_ | 850 // Start(): Basically the same as example 7, as we never create a partial_ |
844 // object for this request. | 851 // object for this request. |
845 // | 852 |
846 int HttpCache::Transaction::DoLoop(int result) { | 853 int HttpCache::Transaction::DoLoop(int result) { |
847 DCHECK(next_state_ != STATE_NONE); | 854 DCHECK(next_state_ != STATE_NONE); |
848 | 855 |
849 int rv = result; | 856 int rv = result; |
850 do { | 857 do { |
851 State state = next_state_; | 858 State state = next_state_; |
852 next_state_ = STATE_NONE; | 859 next_state_ = STATE_NONE; |
853 switch (state) { | 860 switch (state) { |
854 case STATE_GET_BACKEND: | 861 case STATE_GET_BACKEND: |
855 DCHECK_EQ(OK, rv); | 862 DCHECK_EQ(OK, rv); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
944 DCHECK_EQ(OK, rv); | 951 DCHECK_EQ(OK, rv); |
945 rv = DoPartialHeadersReceived(); | 952 rv = DoPartialHeadersReceived(); |
946 break; | 953 break; |
947 case STATE_CACHE_READ_RESPONSE: | 954 case STATE_CACHE_READ_RESPONSE: |
948 DCHECK_EQ(OK, rv); | 955 DCHECK_EQ(OK, rv); |
949 rv = DoCacheReadResponse(); | 956 rv = DoCacheReadResponse(); |
950 break; | 957 break; |
951 case STATE_CACHE_READ_RESPONSE_COMPLETE: | 958 case STATE_CACHE_READ_RESPONSE_COMPLETE: |
952 rv = DoCacheReadResponseComplete(rv); | 959 rv = DoCacheReadResponseComplete(rv); |
953 break; | 960 break; |
961 case STATE_CACHE_READ_RESPONSE_CONTINUE: | |
962 rv = DoCacheReadResponseContinue(); | |
rvargas (doing something else)
2015/01/09 02:25:33
dcheck rv == ok
jkarlin
2015/01/09 14:03:50
Done.
| |
963 break; | |
964 case STATE_TOGGLE_UNUSED_SINCE_PREFETCH: | |
965 DCHECK_EQ(OK, rv); | |
966 rv = DoCacheToggleUnusedSincePrefetch(); | |
967 break; | |
968 case STATE_TOGGLE_UNUSED_SINCE_PREFETCH_COMPLETE: | |
969 rv = DoCacheToggleUnusedSincePrefetchComplete(rv); | |
970 break; | |
954 case STATE_CACHE_WRITE_RESPONSE: | 971 case STATE_CACHE_WRITE_RESPONSE: |
955 DCHECK_EQ(OK, rv); | 972 DCHECK_EQ(OK, rv); |
956 rv = DoCacheWriteResponse(); | 973 rv = DoCacheWriteResponse(); |
957 break; | 974 break; |
958 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE: | 975 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE: |
959 DCHECK_EQ(OK, rv); | 976 DCHECK_EQ(OK, rv); |
960 rv = DoCacheWriteTruncatedResponse(); | 977 rv = DoCacheWriteTruncatedResponse(); |
961 break; | 978 break; |
962 case STATE_CACHE_WRITE_RESPONSE_COMPLETE: | 979 case STATE_CACHE_WRITE_RESPONSE_COMPLETE: |
963 rv = DoCacheWriteResponseComplete(rv); | 980 rv = DoCacheWriteResponseComplete(rv); |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1623 "422516 HttpCache::Transaction::DoUpdateCachedResponse")); | 1640 "422516 HttpCache::Transaction::DoUpdateCachedResponse")); |
1624 | 1641 |
1625 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; | 1642 next_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; |
1626 int rv = OK; | 1643 int rv = OK; |
1627 // Update cached response based on headers in new_response. | 1644 // Update cached response based on headers in new_response. |
1628 // TODO(wtc): should we update cached certificate (response_.ssl_info), too? | 1645 // TODO(wtc): should we update cached certificate (response_.ssl_info), too? |
1629 response_.headers->Update(*new_response_->headers.get()); | 1646 response_.headers->Update(*new_response_->headers.get()); |
1630 response_.response_time = new_response_->response_time; | 1647 response_.response_time = new_response_->response_time; |
1631 response_.request_time = new_response_->request_time; | 1648 response_.request_time = new_response_->request_time; |
1632 response_.network_accessed = new_response_->network_accessed; | 1649 response_.network_accessed = new_response_->network_accessed; |
1650 response_.unused_since_prefetch = new_response_->unused_since_prefetch; | |
1633 | 1651 |
1634 if (response_.headers->HasHeaderValue("cache-control", "no-store")) { | 1652 if (response_.headers->HasHeaderValue("cache-control", "no-store")) { |
1635 if (!entry_->doomed) { | 1653 if (!entry_->doomed) { |
1636 int ret = cache_->DoomEntry(cache_key_, NULL); | 1654 int ret = cache_->DoomEntry(cache_key_, NULL); |
1637 DCHECK_EQ(OK, ret); | 1655 DCHECK_EQ(OK, ret); |
1638 } | 1656 } |
1639 } else { | 1657 } else { |
1640 // If we are already reading, we already updated the headers for this | 1658 // If we are already reading, we already updated the headers for this |
1641 // request; doing it again will change Content-Length. | 1659 // request; doing it again will change Content-Length. |
1642 if (!reading_) { | 1660 if (!reading_) { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1841 | 1859 |
1842 // cert_cache() will be null if the CertCacheTrial field trial is disabled. | 1860 // cert_cache() will be null if the CertCacheTrial field trial is disabled. |
1843 if (cache_->cert_cache() && response_.ssl_info.is_valid()) | 1861 if (cache_->cert_cache() && response_.ssl_info.is_valid()) |
1844 ReadCertChain(); | 1862 ReadCertChain(); |
1845 | 1863 |
1846 // Some resources may have slipped in as truncated when they're not. | 1864 // Some resources may have slipped in as truncated when they're not. |
1847 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); | 1865 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); |
1848 if (response_.headers->GetContentLength() == current_size) | 1866 if (response_.headers->GetContentLength() == current_size) |
1849 truncated_ = false; | 1867 truncated_ = false; |
1850 | 1868 |
1869 if ((response_.unused_since_prefetch && | |
1870 !(request_->load_flags & LOAD_PREFETCH)) || | |
1871 (!response_.unused_since_prefetch && | |
1872 (request_->load_flags & LOAD_PREFETCH))) { | |
1873 // Either this is the first use of an entry since it was prefetched or | |
1874 // this is a prefetch. The value of response.unused_since_prefetch is valid | |
1875 // for this transaction but the bit needs to be flipped in storage. | |
1876 next_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH; | |
1877 return OK; | |
1878 } | |
1879 | |
1880 next_state_ = STATE_CACHE_READ_RESPONSE_CONTINUE; | |
1881 return OK; | |
1882 } | |
1883 | |
1884 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetch() { | |
1885 // Write back the toggled value for the next use of this entry. | |
1886 response_.unused_since_prefetch = !response_.unused_since_prefetch; | |
1887 | |
1888 // TODO(jkarlin): If DoUpdateCachedResponse is also called for this | |
1889 // transaction then metadata will be written to cache twice. If prefetching | |
1890 // becomes more common, consider combining the writes. | |
1891 target_state_ = STATE_TOGGLE_UNUSED_SINCE_PREFETCH_COMPLETE; | |
1892 next_state_ = STATE_CACHE_WRITE_RESPONSE; | |
1893 return OK; | |
1894 } | |
1895 | |
1896 int HttpCache::Transaction::DoCacheToggleUnusedSincePrefetchComplete( | |
1897 int result) { | |
1898 // Restore the original value for this transaction. | |
1899 response_.unused_since_prefetch = !response_.unused_since_prefetch; | |
1900 next_state_ = STATE_CACHE_READ_RESPONSE_CONTINUE; | |
1901 return OK; | |
1902 } | |
1903 | |
1904 int HttpCache::Transaction::DoCacheReadResponseContinue() { | |
rvargas (doing something else)
2015/01/09 02:25:34
Ideally states should be named by what is done in
jkarlin
2015/01/09 14:03:50
Yeah, I had a hell of a time coming up with an acc
| |
1851 // We now have access to the cache entry. | 1905 // We now have access to the cache entry. |
1852 // | 1906 // |
1853 // o if we are a reader for the transaction, then we can start reading the | 1907 // o if we are a reader for the transaction, then we can start reading the |
1854 // cache entry. | 1908 // cache entry. |
1855 // | 1909 // |
1856 // o if we can read or write, then we should check if the cache entry needs | 1910 // 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 | 1911 // 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. | 1912 // from the cache if the cache entry is already valid. |
1859 // | 1913 // |
1860 // o if we are set to UPDATE, then we are handling an externally | 1914 // o if we are set to UPDATE, then we are handling an externally |
1861 // conditionalized request (if-modified-since / if-none-match). We check | 1915 // conditionalized request (if-modified-since / if-none-match). We check |
1862 // if the request headers define a validation request. | 1916 // if the request headers define a validation request. |
1863 // | 1917 // |
1918 int result = ERR_FAILED; | |
1864 switch (mode_) { | 1919 switch (mode_) { |
1865 case READ: | 1920 case READ: |
1866 UpdateTransactionPattern(PATTERN_ENTRY_USED); | 1921 UpdateTransactionPattern(PATTERN_ENTRY_USED); |
1867 result = BeginCacheRead(); | 1922 result = BeginCacheRead(); |
1868 break; | 1923 break; |
1869 case READ_WRITE: | 1924 case READ_WRITE: |
1870 result = BeginPartialCacheValidation(); | 1925 result = BeginPartialCacheValidation(); |
1871 break; | 1926 break; |
1872 case UPDATE: | 1927 case UPDATE: |
1873 result = BeginExternallyConditionalizedRequest(); | 1928 result = BeginExternallyConditionalizedRequest(); |
1874 break; | 1929 break; |
1875 case WRITE: | 1930 case WRITE: |
1876 default: | 1931 default: |
1877 NOTREACHED(); | 1932 NOTREACHED(); |
1878 result = ERR_FAILED; | |
1879 } | 1933 } |
1880 return result; | 1934 return result; |
1881 } | 1935 } |
1882 | 1936 |
1883 int HttpCache::Transaction::DoCacheWriteResponse() { | 1937 int HttpCache::Transaction::DoCacheWriteResponse() { |
1884 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 1938 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
1885 tracked_objects::ScopedTracker tracking_profile( | 1939 tracked_objects::ScopedTracker tracking_profile( |
1886 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1940 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
1887 "422516 HttpCache::Transaction::DoCacheWriteResponse")); | 1941 "422516 HttpCache::Transaction::DoCacheWriteResponse")); |
1888 | 1942 |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2538 if (response_.vary_data.is_valid() && | 2592 if (response_.vary_data.is_valid() && |
2539 !response_.vary_data.MatchesRequest(*request_, | 2593 !response_.vary_data.MatchesRequest(*request_, |
2540 *response_.headers.get())) { | 2594 *response_.headers.get())) { |
2541 vary_mismatch_ = true; | 2595 vary_mismatch_ = true; |
2542 return VALIDATION_SYNCHRONOUS; | 2596 return VALIDATION_SYNCHRONOUS; |
2543 } | 2597 } |
2544 | 2598 |
2545 if (effective_load_flags_ & LOAD_PREFERRING_CACHE) | 2599 if (effective_load_flags_ & LOAD_PREFERRING_CACHE) |
2546 return VALIDATION_NONE; | 2600 return VALIDATION_NONE; |
2547 | 2601 |
2602 if (response_.unused_since_prefetch && | |
2603 !(effective_load_flags_ & LOAD_PREFETCH) && | |
2604 response_.headers->GetCurrentAge( | |
2605 response_.request_time, response_.response_time, | |
2606 cache_->clock_->Now()) < TimeDelta::FromMinutes(kPrefetchReuseMins)) { | |
2607 // The first use of a resource after prefetch within a short window skips | |
2608 // validation. | |
2609 return VALIDATION_NONE; | |
2610 } | |
2611 | |
2548 if (effective_load_flags_ & (LOAD_VALIDATE_CACHE | LOAD_ASYNC_REVALIDATION)) | 2612 if (effective_load_flags_ & (LOAD_VALIDATE_CACHE | LOAD_ASYNC_REVALIDATION)) |
2549 return VALIDATION_SYNCHRONOUS; | 2613 return VALIDATION_SYNCHRONOUS; |
2550 | 2614 |
2551 if (request_->method == "PUT" || request_->method == "DELETE") | 2615 if (request_->method == "PUT" || request_->method == "DELETE") |
2552 return VALIDATION_SYNCHRONOUS; | 2616 return VALIDATION_SYNCHRONOUS; |
2553 | 2617 |
2554 ValidationType validation_required_by_headers = | 2618 ValidationType validation_required_by_headers = |
2555 response_.headers->RequiresValidation( | 2619 response_.headers->RequiresValidation(response_.request_time, |
2556 response_.request_time, response_.response_time, Time::Now()); | 2620 response_.response_time, |
2621 cache_->clock_->Now()); | |
2557 | 2622 |
2558 if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) { | 2623 if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) { |
2559 // Asynchronous revalidation is only supported for GET and HEAD methods. | 2624 // Asynchronous revalidation is only supported for GET and HEAD methods. |
2560 if (request_->method != "GET" && request_->method != "HEAD") | 2625 if (request_->method != "GET" && request_->method != "HEAD") |
2561 return VALIDATION_SYNCHRONOUS; | 2626 return VALIDATION_SYNCHRONOUS; |
2562 } | 2627 } |
2563 | 2628 |
2564 return validation_required_by_headers; | 2629 return validation_required_by_headers; |
2565 } | 2630 } |
2566 | 2631 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2607 bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() && | 2672 bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() && |
2608 !invalid_range_; | 2673 !invalid_range_; |
2609 | 2674 |
2610 if (!use_if_range) { | 2675 if (!use_if_range) { |
2611 // stale-while-revalidate is not useful when we only have a partial response | 2676 // stale-while-revalidate is not useful when we only have a partial response |
2612 // cached, so don't set the header in that case. | 2677 // cached, so don't set the header in that case. |
2613 HttpResponseHeaders::FreshnessLifetimes lifetimes = | 2678 HttpResponseHeaders::FreshnessLifetimes lifetimes = |
2614 response_.headers->GetFreshnessLifetimes(response_.response_time); | 2679 response_.headers->GetFreshnessLifetimes(response_.response_time); |
2615 if (lifetimes.staleness > TimeDelta()) { | 2680 if (lifetimes.staleness > TimeDelta()) { |
2616 TimeDelta current_age = response_.headers->GetCurrentAge( | 2681 TimeDelta current_age = response_.headers->GetCurrentAge( |
2617 response_.request_time, response_.response_time, Time::Now()); | 2682 response_.request_time, response_.response_time, |
2683 cache_->clock_->Now()); | |
2618 | 2684 |
2619 custom_request_->extra_headers.SetHeader( | 2685 custom_request_->extra_headers.SetHeader( |
2620 kFreshnessHeader, | 2686 kFreshnessHeader, |
2621 base::StringPrintf("max-age=%" PRId64 | 2687 base::StringPrintf("max-age=%" PRId64 |
2622 ",stale-while-revalidate=%" PRId64 ",age=%" PRId64, | 2688 ",stale-while-revalidate=%" PRId64 ",age=%" PRId64, |
2623 lifetimes.freshness.InSeconds(), | 2689 lifetimes.freshness.InSeconds(), |
2624 lifetimes.staleness.InSeconds(), | 2690 lifetimes.staleness.InSeconds(), |
2625 current_age.InSeconds())); | 2691 current_age.InSeconds())); |
2626 } | 2692 } |
2627 } | 2693 } |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3165 | 3231 |
3166 void HttpCache::Transaction::OnIOComplete(int result) { | 3232 void HttpCache::Transaction::OnIOComplete(int result) { |
3167 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 3233 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
3168 tracked_objects::ScopedTracker tracking_profile( | 3234 tracked_objects::ScopedTracker tracking_profile( |
3169 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete")); | 3235 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 Transaction::OnIOComplete")); |
3170 | 3236 |
3171 DoLoop(result); | 3237 DoLoop(result); |
3172 } | 3238 } |
3173 | 3239 |
3174 } // namespace net | 3240 } // namespace net |
OLD | NEW |