| 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> |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 if (load_flags & net::LOAD_MAIN_FRAME) { | 221 if (load_flags & net::LOAD_MAIN_FRAME) { |
| 222 UMA_HISTOGRAM_BOOLEAN( | 222 UMA_HISTOGRAM_BOOLEAN( |
| 223 "Net.MainFrameNoStore", | 223 "Net.MainFrameNoStore", |
| 224 response->headers->HasHeaderValue("cache-control", "no-store")); | 224 response->headers->HasHeaderValue("cache-control", "no-store")); |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 | 227 |
| 228 base::Value* NetLogAsyncRevalidationInfoCallback( | 228 base::Value* NetLogAsyncRevalidationInfoCallback( |
| 229 const net::NetLog::Source& source, | 229 const net::NetLog::Source& source, |
| 230 const net::HttpRequestInfo* request, | 230 const net::HttpRequestInfo* request, |
| 231 net::NetLog::LogLevel log_level) { | 231 net::NetLogCaptureMode capture_mode) { |
| 232 base::DictionaryValue* dict = new base::DictionaryValue(); | 232 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 233 source.AddToEventParameters(dict); | 233 source.AddToEventParameters(dict); |
| 234 | 234 |
| 235 dict->SetString("url", request->url.possibly_invalid_spec()); | 235 dict->SetString("url", request->url.possibly_invalid_spec()); |
| 236 dict->SetString("method", request->method); | 236 dict->SetString("method", request->method); |
| 237 return dict; | 237 return dict; |
| 238 } | 238 } |
| 239 | 239 |
| 240 enum ExternallyConditionalizedType { | 240 enum ExternallyConditionalizedType { |
| 241 EXTERNALLY_CONDITIONALIZED_CACHE_REQUIRES_VALIDATION, | 241 EXTERNALLY_CONDITIONALIZED_CACHE_REQUIRES_VALIDATION, |
| (...skipping 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1638 target_state_ = STATE_TRUNCATE_CACHED_DATA; | 1638 target_state_ = STATE_TRUNCATE_CACHED_DATA; |
| 1639 next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE : | 1639 next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE : |
| 1640 STATE_CACHE_WRITE_RESPONSE; | 1640 STATE_CACHE_WRITE_RESPONSE; |
| 1641 return OK; | 1641 return OK; |
| 1642 } | 1642 } |
| 1643 | 1643 |
| 1644 int HttpCache::Transaction::DoTruncateCachedData() { | 1644 int HttpCache::Transaction::DoTruncateCachedData() { |
| 1645 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; | 1645 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; |
| 1646 if (!entry_) | 1646 if (!entry_) |
| 1647 return OK; | 1647 return OK; |
| 1648 if (net_log_.IsLogging()) | 1648 if (net_log_.GetCaptureMode().enabled()) |
| 1649 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); | 1649 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); |
| 1650 // Truncate the stream. | 1650 // Truncate the stream. |
| 1651 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, io_callback_); | 1651 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, io_callback_); |
| 1652 } | 1652 } |
| 1653 | 1653 |
| 1654 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { | 1654 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { |
| 1655 if (entry_) { | 1655 if (entry_) { |
| 1656 if (net_log_.IsLogging()) { | 1656 if (net_log_.GetCaptureMode().enabled()) { |
| 1657 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, | 1657 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, |
| 1658 result); | 1658 result); |
| 1659 } | 1659 } |
| 1660 } | 1660 } |
| 1661 | 1661 |
| 1662 next_state_ = STATE_TRUNCATE_CACHED_METADATA; | 1662 next_state_ = STATE_TRUNCATE_CACHED_METADATA; |
| 1663 return OK; | 1663 return OK; |
| 1664 } | 1664 } |
| 1665 | 1665 |
| 1666 int HttpCache::Transaction::DoTruncateCachedMetadata() { | 1666 int HttpCache::Transaction::DoTruncateCachedMetadata() { |
| 1667 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; | 1667 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; |
| 1668 if (!entry_) | 1668 if (!entry_) |
| 1669 return OK; | 1669 return OK; |
| 1670 | 1670 |
| 1671 if (net_log_.IsLogging()) | 1671 if (net_log_.GetCaptureMode().enabled()) |
| 1672 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | 1672 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
| 1673 return WriteToEntry(kMetadataIndex, 0, NULL, 0, io_callback_); | 1673 return WriteToEntry(kMetadataIndex, 0, NULL, 0, io_callback_); |
| 1674 } | 1674 } |
| 1675 | 1675 |
| 1676 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { | 1676 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { |
| 1677 if (entry_) { | 1677 if (entry_) { |
| 1678 if (net_log_.IsLogging()) { | 1678 if (net_log_.GetCaptureMode().enabled()) { |
| 1679 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, | 1679 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, |
| 1680 result); | 1680 result); |
| 1681 } | 1681 } |
| 1682 } | 1682 } |
| 1683 | 1683 |
| 1684 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; | 1684 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; |
| 1685 return OK; | 1685 return OK; |
| 1686 } | 1686 } |
| 1687 | 1687 |
| 1688 int HttpCache::Transaction::DoPartialHeadersReceived() { | 1688 int HttpCache::Transaction::DoPartialHeadersReceived() { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1805 return OK; | 1805 return OK; |
| 1806 } | 1806 } |
| 1807 | 1807 |
| 1808 int HttpCache::Transaction::DoCacheWriteResponse() { | 1808 int HttpCache::Transaction::DoCacheWriteResponse() { |
| 1809 // TODO(rtenneti): Remove ScopedTracker below once crbug.com/422516 is fixed. | 1809 // TODO(rtenneti): Remove ScopedTracker below once crbug.com/422516 is fixed. |
| 1810 tracked_objects::ScopedTracker tracking_profile( | 1810 tracked_objects::ScopedTracker tracking_profile( |
| 1811 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1811 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1812 "422516 HttpCache::Transaction::DoCacheWriteResponse")); | 1812 "422516 HttpCache::Transaction::DoCacheWriteResponse")); |
| 1813 | 1813 |
| 1814 if (entry_) { | 1814 if (entry_) { |
| 1815 if (net_log_.IsLogging()) | 1815 if (net_log_.GetCaptureMode().enabled()) |
| 1816 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | 1816 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
| 1817 } | 1817 } |
| 1818 return WriteResponseInfoToEntry(false); | 1818 return WriteResponseInfoToEntry(false); |
| 1819 } | 1819 } |
| 1820 | 1820 |
| 1821 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { | 1821 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { |
| 1822 if (entry_) { | 1822 if (entry_) { |
| 1823 if (net_log_.IsLogging()) | 1823 if (net_log_.GetCaptureMode().enabled()) |
| 1824 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | 1824 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
| 1825 } | 1825 } |
| 1826 return WriteResponseInfoToEntry(true); | 1826 return WriteResponseInfoToEntry(true); |
| 1827 } | 1827 } |
| 1828 | 1828 |
| 1829 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { | 1829 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { |
| 1830 next_state_ = target_state_; | 1830 next_state_ = target_state_; |
| 1831 target_state_ = STATE_NONE; | 1831 target_state_ = STATE_NONE; |
| 1832 if (!entry_) | 1832 if (!entry_) |
| 1833 return OK; | 1833 return OK; |
| 1834 if (net_log_.IsLogging()) { | 1834 if (net_log_.GetCaptureMode().enabled()) { |
| 1835 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, | 1835 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, |
| 1836 result); | 1836 result); |
| 1837 } | 1837 } |
| 1838 | 1838 |
| 1839 // Balance the AddRef from WriteResponseInfoToEntry. | 1839 // Balance the AddRef from WriteResponseInfoToEntry. |
| 1840 if (result != io_buf_len_) { | 1840 if (result != io_buf_len_) { |
| 1841 DLOG(ERROR) << "failed to write response info to cache"; | 1841 DLOG(ERROR) << "failed to write response info to cache"; |
| 1842 DoneWritingToEntry(false); | 1842 DoneWritingToEntry(false); |
| 1843 } | 1843 } |
| 1844 return OK; | 1844 return OK; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1876 if (!cache_.get()) | 1876 if (!cache_.get()) |
| 1877 return ERR_UNEXPECTED; | 1877 return ERR_UNEXPECTED; |
| 1878 | 1878 |
| 1879 return ValidateEntryHeadersAndContinue(); | 1879 return ValidateEntryHeadersAndContinue(); |
| 1880 } | 1880 } |
| 1881 | 1881 |
| 1882 int HttpCache::Transaction::DoCacheReadData() { | 1882 int HttpCache::Transaction::DoCacheReadData() { |
| 1883 DCHECK(entry_); | 1883 DCHECK(entry_); |
| 1884 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; | 1884 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; |
| 1885 | 1885 |
| 1886 if (net_log_.IsLogging()) | 1886 if (net_log_.GetCaptureMode().enabled()) |
| 1887 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA); | 1887 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA); |
| 1888 if (partial_.get()) { | 1888 if (partial_.get()) { |
| 1889 return partial_->CacheRead(entry_->disk_entry, read_buf_.get(), io_buf_len_, | 1889 return partial_->CacheRead(entry_->disk_entry, read_buf_.get(), io_buf_len_, |
| 1890 io_callback_); | 1890 io_callback_); |
| 1891 } | 1891 } |
| 1892 | 1892 |
| 1893 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, | 1893 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, |
| 1894 read_buf_.get(), io_buf_len_, | 1894 read_buf_.get(), io_buf_len_, |
| 1895 io_callback_); | 1895 io_callback_); |
| 1896 } | 1896 } |
| 1897 | 1897 |
| 1898 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { | 1898 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { |
| 1899 if (net_log_.IsLogging()) { | 1899 if (net_log_.GetCaptureMode().enabled()) { |
| 1900 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA, | 1900 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA, |
| 1901 result); | 1901 result); |
| 1902 } | 1902 } |
| 1903 | 1903 |
| 1904 if (!cache_.get()) | 1904 if (!cache_.get()) |
| 1905 return ERR_UNEXPECTED; | 1905 return ERR_UNEXPECTED; |
| 1906 | 1906 |
| 1907 if (partial_.get()) { | 1907 if (partial_.get()) { |
| 1908 // Partial requests are confusing to report in histograms because they may | 1908 // Partial requests are confusing to report in histograms because they may |
| 1909 // have multiple underlying requests. | 1909 // have multiple underlying requests. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1920 } else { | 1920 } else { |
| 1921 return OnCacheReadError(result, false); | 1921 return OnCacheReadError(result, false); |
| 1922 } | 1922 } |
| 1923 return result; | 1923 return result; |
| 1924 } | 1924 } |
| 1925 | 1925 |
| 1926 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { | 1926 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { |
| 1927 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; | 1927 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; |
| 1928 write_len_ = num_bytes; | 1928 write_len_ = num_bytes; |
| 1929 if (entry_) { | 1929 if (entry_) { |
| 1930 if (net_log_.IsLogging()) | 1930 if (net_log_.GetCaptureMode().enabled()) |
| 1931 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); | 1931 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); |
| 1932 } | 1932 } |
| 1933 | 1933 |
| 1934 return AppendResponseDataToEntry(read_buf_.get(), num_bytes, io_callback_); | 1934 return AppendResponseDataToEntry(read_buf_.get(), num_bytes, io_callback_); |
| 1935 } | 1935 } |
| 1936 | 1936 |
| 1937 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { | 1937 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { |
| 1938 if (entry_) { | 1938 if (entry_) { |
| 1939 if (net_log_.IsLogging()) { | 1939 if (net_log_.GetCaptureMode().enabled()) { |
| 1940 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, | 1940 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, |
| 1941 result); | 1941 result); |
| 1942 } | 1942 } |
| 1943 } | 1943 } |
| 1944 // Balance the AddRef from DoCacheWriteData. | 1944 // Balance the AddRef from DoCacheWriteData. |
| 1945 if (!cache_.get()) | 1945 if (!cache_.get()) |
| 1946 return ERR_UNEXPECTED; | 1946 return ERR_UNEXPECTED; |
| 1947 | 1947 |
| 1948 if (result != write_len_) { | 1948 if (result != write_len_) { |
| 1949 DLOG(ERROR) << "failed to write response data to cache"; | 1949 DLOG(ERROR) << "failed to write response data to cache"; |
| (...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2751 // resource from the cache. When we load a page over HTTPS with a cert error | 2751 // resource from the cache. When we load a page over HTTPS with a cert error |
| 2752 // we show an SSL blocking page. If the user clicks proceed we reload the | 2752 // we show an SSL blocking page. If the user clicks proceed we reload the |
| 2753 // resource ignoring the errors. The loaded resource is then cached. If that | 2753 // resource ignoring the errors. The loaded resource is then cached. If that |
| 2754 // resource is subsequently loaded from the cache, no net error is reported | 2754 // resource is subsequently loaded from the cache, no net error is reported |
| 2755 // (even though the cert status contains the actual errors) and no SSL | 2755 // (even though the cert status contains the actual errors) and no SSL |
| 2756 // blocking page is shown. An alternative would be to reverse-map the cert | 2756 // blocking page is shown. An alternative would be to reverse-map the cert |
| 2757 // status to a net error and replay the net error. | 2757 // status to a net error and replay the net error. |
| 2758 if ((response_.headers->HasHeaderValue("cache-control", "no-store")) || | 2758 if ((response_.headers->HasHeaderValue("cache-control", "no-store")) || |
| 2759 net::IsCertStatusError(response_.ssl_info.cert_status)) { | 2759 net::IsCertStatusError(response_.ssl_info.cert_status)) { |
| 2760 DoneWritingToEntry(false); | 2760 DoneWritingToEntry(false); |
| 2761 if (net_log_.IsLogging()) | 2761 if (net_log_.GetCaptureMode().enabled()) |
| 2762 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | 2762 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
| 2763 return OK; | 2763 return OK; |
| 2764 } | 2764 } |
| 2765 | 2765 |
| 2766 // cert_cache() will be null if the CertCacheTrial field trial is disabled. | 2766 // cert_cache() will be null if the CertCacheTrial field trial is disabled. |
| 2767 if (cache_->cert_cache() && response_.ssl_info.is_valid()) | 2767 if (cache_->cert_cache() && response_.ssl_info.is_valid()) |
| 2768 WriteCertChain(); | 2768 WriteCertChain(); |
| 2769 | 2769 |
| 2770 if (truncated) | 2770 if (truncated) |
| 2771 DCHECK_EQ(200, response_.headers->response_code()); | 2771 DCHECK_EQ(200, response_.headers->response_code()); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3032 default: | 3032 default: |
| 3033 NOTREACHED(); | 3033 NOTREACHED(); |
| 3034 } | 3034 } |
| 3035 } | 3035 } |
| 3036 | 3036 |
| 3037 void HttpCache::Transaction::OnIOComplete(int result) { | 3037 void HttpCache::Transaction::OnIOComplete(int result) { |
| 3038 DoLoop(result); | 3038 DoLoop(result); |
| 3039 } | 3039 } |
| 3040 | 3040 |
| 3041 } // namespace net | 3041 } // namespace net |
| OLD | NEW |