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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 COMPILE_ASSERT(HttpCache::Transaction::kNumValidationHeaders == | 147 COMPILE_ASSERT(HttpCache::Transaction::kNumValidationHeaders == |
148 arraysize(kValidationHeaders), | 148 arraysize(kValidationHeaders), |
149 Invalid_number_of_validation_headers); | 149 Invalid_number_of_validation_headers); |
150 } | 150 } |
151 | 151 |
152 HttpCache::Transaction::~Transaction() { | 152 HttpCache::Transaction::~Transaction() { |
153 // We may have to issue another IO, but we should never invoke the callback_ | 153 // We may have to issue another IO, but we should never invoke the callback_ |
154 // after this point. | 154 // after this point. |
155 callback_.Reset(); | 155 callback_.Reset(); |
156 | 156 |
| 157 transaction_delegate_ = NULL; |
| 158 |
157 if (cache_) { | 159 if (cache_) { |
158 if (entry_) { | 160 if (entry_) { |
159 bool cancel_request = reading_; | 161 bool cancel_request = reading_; |
160 if (cancel_request) { | 162 if (cancel_request) { |
161 if (partial_.get()) { | 163 if (partial_.get()) { |
162 entry_->disk_entry->CancelSparseIO(); | 164 entry_->disk_entry->CancelSparseIO(); |
163 } else { | 165 } else { |
164 cancel_request &= (response_.headers->response_code() == 200); | 166 cancel_request &= (response_.headers->response_code() == 200); |
165 } | 167 } |
166 } | 168 } |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 DCHECK(mode_ & WRITE || mode_ == NONE); | 740 DCHECK(mode_ & WRITE || mode_ == NONE); |
739 DCHECK(!network_trans_.get()); | 741 DCHECK(!network_trans_.get()); |
740 | 742 |
741 send_request_since_ = TimeTicks::Now(); | 743 send_request_since_ = TimeTicks::Now(); |
742 | 744 |
743 // Create a network transaction. | 745 // Create a network transaction. |
744 int rv = cache_->network_layer_->CreateTransaction(&network_trans_, NULL); | 746 int rv = cache_->network_layer_->CreateTransaction(&network_trans_, NULL); |
745 if (rv != OK) | 747 if (rv != OK) |
746 return rv; | 748 return rv; |
747 | 749 |
| 750 ReportNetworkActionStart(); |
748 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 751 next_state_ = STATE_SEND_REQUEST_COMPLETE; |
749 rv = network_trans_->Start(request_, io_callback_, net_log_); | 752 rv = network_trans_->Start(request_, io_callback_, net_log_); |
750 return rv; | 753 return rv; |
751 } | 754 } |
752 | 755 |
753 int HttpCache::Transaction::DoSendRequestComplete(int result) { | 756 int HttpCache::Transaction::DoSendRequestComplete(int result) { |
| 757 ReportNetworkActionFinish(); |
| 758 |
754 if (!cache_) | 759 if (!cache_) |
755 return ERR_UNEXPECTED; | 760 return ERR_UNEXPECTED; |
756 | 761 |
757 if (result == OK) { | 762 if (result == OK) { |
758 next_state_ = STATE_SUCCESSFUL_SEND_REQUEST; | 763 next_state_ = STATE_SUCCESSFUL_SEND_REQUEST; |
759 return OK; | 764 return OK; |
760 } | 765 } |
761 | 766 |
762 // Do not record requests that have network errors or restarts. | 767 // Do not record requests that have network errors or restarts. |
763 UpdateTransactionPattern(PATTERN_NOT_COVERED); | 768 UpdateTransactionPattern(PATTERN_NOT_COVERED); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 } | 837 } |
833 UpdateTransactionPattern(PATTERN_ENTRY_UPDATED); | 838 UpdateTransactionPattern(PATTERN_ENTRY_UPDATED); |
834 mode_ = WRITE; | 839 mode_ = WRITE; |
835 } | 840 } |
836 | 841 |
837 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; | 842 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; |
838 return OK; | 843 return OK; |
839 } | 844 } |
840 | 845 |
841 int HttpCache::Transaction::DoNetworkRead() { | 846 int HttpCache::Transaction::DoNetworkRead() { |
| 847 ReportNetworkActionStart(); |
842 next_state_ = STATE_NETWORK_READ_COMPLETE; | 848 next_state_ = STATE_NETWORK_READ_COMPLETE; |
843 return network_trans_->Read(read_buf_, io_buf_len_, io_callback_); | 849 return network_trans_->Read(read_buf_, io_buf_len_, io_callback_); |
844 } | 850 } |
845 | 851 |
846 int HttpCache::Transaction::DoNetworkReadComplete(int result) { | 852 int HttpCache::Transaction::DoNetworkReadComplete(int result) { |
847 DCHECK(mode_ & WRITE || mode_ == NONE); | 853 DCHECK(mode_ & WRITE || mode_ == NONE); |
848 | 854 |
| 855 ReportNetworkActionFinish(); |
| 856 |
849 if (!cache_) | 857 if (!cache_) |
850 return ERR_UNEXPECTED; | 858 return ERR_UNEXPECTED; |
851 | 859 |
852 if (result > 0) | 860 if (result > 0) |
853 bytes_read_from_network_ += result; | 861 bytes_read_from_network_ += result; |
854 | 862 |
855 // If there is an error or we aren't saving the data, we are done; just wait | 863 // If there is an error or we aren't saving the data, we are done; just wait |
856 // until the destructor runs to see if we can keep the data. | 864 // until the destructor runs to see if we can keep the data. |
857 if (mode_ == NONE || result < 0) | 865 if (mode_ == NONE || result < 0) |
858 return result; | 866 return result; |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 if (entry_) { | 1320 if (entry_) { |
1313 if (net_log_.IsLoggingAllEvents()) | 1321 if (net_log_.IsLoggingAllEvents()) |
1314 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | 1322 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
1315 ReportCacheActionStart(); | 1323 ReportCacheActionStart(); |
1316 } | 1324 } |
1317 return WriteResponseInfoToEntry(false); | 1325 return WriteResponseInfoToEntry(false); |
1318 } | 1326 } |
1319 | 1327 |
1320 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { | 1328 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { |
1321 if (entry_) { | 1329 if (entry_) { |
1322 if (net_log_.IsLoggingAllEvents() && entry_) | 1330 if (net_log_.IsLoggingAllEvents()) |
1323 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | 1331 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
1324 ReportCacheActionStart(); | 1332 ReportCacheActionStart(); |
1325 } | 1333 } |
1326 return WriteResponseInfoToEntry(true); | 1334 return WriteResponseInfoToEntry(true); |
1327 } | 1335 } |
1328 | 1336 |
1329 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { | 1337 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { |
1330 next_state_ = target_state_; | 1338 next_state_ = target_state_; |
1331 target_state_ = STATE_NONE; | 1339 target_state_ = STATE_NONE; |
1332 if (!entry_) | 1340 if (!entry_) |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1766 | 1774 |
1767 next_state_ = STATE_SEND_REQUEST; | 1775 next_state_ = STATE_SEND_REQUEST; |
1768 return OK; | 1776 return OK; |
1769 } | 1777 } |
1770 | 1778 |
1771 int HttpCache::Transaction::RestartNetworkRequest() { | 1779 int HttpCache::Transaction::RestartNetworkRequest() { |
1772 DCHECK(mode_ & WRITE || mode_ == NONE); | 1780 DCHECK(mode_ & WRITE || mode_ == NONE); |
1773 DCHECK(network_trans_.get()); | 1781 DCHECK(network_trans_.get()); |
1774 DCHECK_EQ(STATE_NONE, next_state_); | 1782 DCHECK_EQ(STATE_NONE, next_state_); |
1775 | 1783 |
| 1784 ReportNetworkActionStart(); |
1776 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 1785 next_state_ = STATE_SEND_REQUEST_COMPLETE; |
1777 int rv = network_trans_->RestartIgnoringLastError(io_callback_); | 1786 int rv = network_trans_->RestartIgnoringLastError(io_callback_); |
1778 if (rv != ERR_IO_PENDING) | 1787 if (rv != ERR_IO_PENDING) |
1779 return DoLoop(rv); | 1788 return DoLoop(rv); |
1780 return rv; | 1789 return rv; |
1781 } | 1790 } |
1782 | 1791 |
1783 int HttpCache::Transaction::RestartNetworkRequestWithCertificate( | 1792 int HttpCache::Transaction::RestartNetworkRequestWithCertificate( |
1784 X509Certificate* client_cert) { | 1793 X509Certificate* client_cert) { |
1785 DCHECK(mode_ & WRITE || mode_ == NONE); | 1794 DCHECK(mode_ & WRITE || mode_ == NONE); |
1786 DCHECK(network_trans_.get()); | 1795 DCHECK(network_trans_.get()); |
1787 DCHECK_EQ(STATE_NONE, next_state_); | 1796 DCHECK_EQ(STATE_NONE, next_state_); |
1788 | 1797 |
| 1798 ReportNetworkActionStart(); |
1789 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 1799 next_state_ = STATE_SEND_REQUEST_COMPLETE; |
1790 int rv = network_trans_->RestartWithCertificate(client_cert, io_callback_); | 1800 int rv = network_trans_->RestartWithCertificate(client_cert, io_callback_); |
1791 if (rv != ERR_IO_PENDING) | 1801 if (rv != ERR_IO_PENDING) |
1792 return DoLoop(rv); | 1802 return DoLoop(rv); |
1793 return rv; | 1803 return rv; |
1794 } | 1804 } |
1795 | 1805 |
1796 int HttpCache::Transaction::RestartNetworkRequestWithAuth( | 1806 int HttpCache::Transaction::RestartNetworkRequestWithAuth( |
1797 const AuthCredentials& credentials) { | 1807 const AuthCredentials& credentials) { |
1798 DCHECK(mode_ & WRITE || mode_ == NONE); | 1808 DCHECK(mode_ & WRITE || mode_ == NONE); |
1799 DCHECK(network_trans_.get()); | 1809 DCHECK(network_trans_.get()); |
1800 DCHECK_EQ(STATE_NONE, next_state_); | 1810 DCHECK_EQ(STATE_NONE, next_state_); |
1801 | 1811 |
| 1812 ReportNetworkActionStart(); |
1802 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 1813 next_state_ = STATE_SEND_REQUEST_COMPLETE; |
1803 int rv = network_trans_->RestartWithAuth(credentials, io_callback_); | 1814 int rv = network_trans_->RestartWithAuth(credentials, io_callback_); |
1804 if (rv != ERR_IO_PENDING) | 1815 if (rv != ERR_IO_PENDING) |
1805 return DoLoop(rv); | 1816 return DoLoop(rv); |
1806 return rv; | 1817 return rv; |
1807 } | 1818 } |
1808 | 1819 |
1809 bool HttpCache::Transaction::RequiresValidation() { | 1820 bool HttpCache::Transaction::RequiresValidation() { |
1810 // TODO(darin): need to do more work here: | 1821 // TODO(darin): need to do more work here: |
1811 // - make sure we have a matching request method | 1822 // - make sure we have a matching request method |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2076 // HTTPS with a cert error we show an SSL blocking page. If the user clicks | 2087 // HTTPS with a cert error we show an SSL blocking page. If the user clicks |
2077 // proceed we reload the resource ignoring the errors. The loaded resource | 2088 // proceed we reload the resource ignoring the errors. The loaded resource |
2078 // is then cached. If that resource is subsequently loaded from the cache, | 2089 // is then cached. If that resource is subsequently loaded from the cache, |
2079 // no net error is reported (even though the cert status contains the actual | 2090 // no net error is reported (even though the cert status contains the actual |
2080 // errors) and no SSL blocking page is shown. An alternative would be to | 2091 // errors) and no SSL blocking page is shown. An alternative would be to |
2081 // reverse-map the cert status to a net error and replay the net error. | 2092 // reverse-map the cert status to a net error and replay the net error. |
2082 if ((cache_->mode() != RECORD && | 2093 if ((cache_->mode() != RECORD && |
2083 response_.headers->HasHeaderValue("cache-control", "no-store")) || | 2094 response_.headers->HasHeaderValue("cache-control", "no-store")) || |
2084 net::IsCertStatusError(response_.ssl_info.cert_status)) { | 2095 net::IsCertStatusError(response_.ssl_info.cert_status)) { |
2085 DoneWritingToEntry(false); | 2096 DoneWritingToEntry(false); |
| 2097 ReportCacheActionFinish(); |
| 2098 if (net_log_.IsLoggingAllEvents()) |
| 2099 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
2086 return OK; | 2100 return OK; |
2087 } | 2101 } |
2088 | 2102 |
2089 // When writing headers, we normally only write the non-transient | 2103 // When writing headers, we normally only write the non-transient |
2090 // headers; when in record mode, record everything. | 2104 // headers; when in record mode, record everything. |
2091 bool skip_transient_headers = (cache_->mode() != RECORD); | 2105 bool skip_transient_headers = (cache_->mode() != RECORD); |
2092 | 2106 |
2093 if (truncated) { | 2107 if (truncated) { |
2094 DCHECK_EQ(200, response_.headers->response_code()); | 2108 DCHECK_EQ(200, response_.headers->response_code()); |
2095 } | 2109 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2225 void HttpCache::Transaction::ReportCacheActionStart() { | 2239 void HttpCache::Transaction::ReportCacheActionStart() { |
2226 if (transaction_delegate_) | 2240 if (transaction_delegate_) |
2227 transaction_delegate_->OnCacheActionStart(); | 2241 transaction_delegate_->OnCacheActionStart(); |
2228 } | 2242 } |
2229 | 2243 |
2230 void HttpCache::Transaction::ReportCacheActionFinish() { | 2244 void HttpCache::Transaction::ReportCacheActionFinish() { |
2231 if (transaction_delegate_) | 2245 if (transaction_delegate_) |
2232 transaction_delegate_->OnCacheActionFinish(); | 2246 transaction_delegate_->OnCacheActionFinish(); |
2233 } | 2247 } |
2234 | 2248 |
| 2249 void HttpCache::Transaction::ReportNetworkActionStart() { |
| 2250 if (transaction_delegate_) |
| 2251 transaction_delegate_->OnNetworkActionStart(); |
| 2252 } |
| 2253 |
| 2254 void HttpCache::Transaction::ReportNetworkActionFinish() { |
| 2255 if (transaction_delegate_) |
| 2256 transaction_delegate_->OnNetworkActionFinish(); |
| 2257 } |
| 2258 |
2235 void HttpCache::Transaction::UpdateTransactionPattern( | 2259 void HttpCache::Transaction::UpdateTransactionPattern( |
2236 TransactionPattern new_transaction_pattern) { | 2260 TransactionPattern new_transaction_pattern) { |
2237 if (transaction_pattern_ == PATTERN_NOT_COVERED) | 2261 if (transaction_pattern_ == PATTERN_NOT_COVERED) |
2238 return; | 2262 return; |
2239 DCHECK(transaction_pattern_ == PATTERN_UNDEFINED || | 2263 DCHECK(transaction_pattern_ == PATTERN_UNDEFINED || |
2240 new_transaction_pattern == PATTERN_NOT_COVERED); | 2264 new_transaction_pattern == PATTERN_NOT_COVERED); |
2241 transaction_pattern_ = new_transaction_pattern; | 2265 transaction_pattern_ = new_transaction_pattern; |
2242 } | 2266 } |
2243 | 2267 |
2244 void HttpCache::Transaction::RecordHistograms() { | 2268 void HttpCache::Transaction::RecordHistograms() { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2349 before_send_percent); | 2373 before_send_percent); |
2350 } | 2374 } |
2351 break; | 2375 break; |
2352 } | 2376 } |
2353 default: | 2377 default: |
2354 NOTREACHED(); | 2378 NOTREACHED(); |
2355 } | 2379 } |
2356 } | 2380 } |
2357 | 2381 |
2358 } // namespace net | 2382 } // namespace net |
OLD | NEW |