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

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

Issue 10834313: Add histograms for network activity, and total/cumulative (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
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>
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 bytes_read_from_network_(0), 145 bytes_read_from_network_(0),
146 transaction_delegate_(transaction_delegate) { 146 transaction_delegate_(transaction_delegate) {
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();
rvargas (doing something else) 2012/08/15 22:36:50 We should reset the delegate at this point, and ad
tburkard 2012/08/15 23:00:47 Done. The test is already verifying that the exac
156 156
157 if (cache_) { 157 if (cache_) {
158 if (entry_) { 158 if (entry_) {
159 bool cancel_request = reading_; 159 bool cancel_request = reading_;
160 if (cancel_request) { 160 if (cancel_request) {
161 if (partial_.get()) { 161 if (partial_.get()) {
162 entry_->disk_entry->CancelSparseIO(); 162 entry_->disk_entry->CancelSparseIO();
163 } else { 163 } else {
164 cancel_request &= (response_.headers->response_code() == 200); 164 cancel_request &= (response_.headers->response_code() == 200);
165 } 165 }
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 DCHECK(mode_ & WRITE || mode_ == NONE); 738 DCHECK(mode_ & WRITE || mode_ == NONE);
739 DCHECK(!network_trans_.get()); 739 DCHECK(!network_trans_.get());
740 740
741 send_request_since_ = TimeTicks::Now(); 741 send_request_since_ = TimeTicks::Now();
742 742
743 // Create a network transaction. 743 // Create a network transaction.
744 int rv = cache_->network_layer_->CreateTransaction(&network_trans_, NULL); 744 int rv = cache_->network_layer_->CreateTransaction(&network_trans_, NULL);
745 if (rv != OK) 745 if (rv != OK)
746 return rv; 746 return rv;
747 747
748 ReportNetworkActionStart();
mmenke 2012/08/15 15:09:53 I'm a bit concerned about mismatched Report*() cal
tburkard 2012/08/15 16:50:46 I can add that to the HttpTransactionDelegateImpl,
mmenke 2012/08/15 18:45:41 When the state was solely for use elsewhere, I tho
mmenke 2012/08/15 19:08:34 Actually, my real objection is that it was in net/
tburkard 2012/08/15 20:42:24 Done.
748 next_state_ = STATE_SEND_REQUEST_COMPLETE; 749 next_state_ = STATE_SEND_REQUEST_COMPLETE;
749 rv = network_trans_->Start(request_, io_callback_, net_log_); 750 rv = network_trans_->Start(request_, io_callback_, net_log_);
750 return rv; 751 return rv;
751 } 752 }
752 753
753 int HttpCache::Transaction::DoSendRequestComplete(int result) { 754 int HttpCache::Transaction::DoSendRequestComplete(int result) {
755 ReportNetworkActionFinish();
756
754 if (!cache_) 757 if (!cache_)
755 return ERR_UNEXPECTED; 758 return ERR_UNEXPECTED;
756 759
757 if (result == OK) { 760 if (result == OK) {
758 next_state_ = STATE_SUCCESSFUL_SEND_REQUEST; 761 next_state_ = STATE_SUCCESSFUL_SEND_REQUEST;
759 return OK; 762 return OK;
760 } 763 }
761 764
762 // Do not record requests that have network errors or restarts. 765 // Do not record requests that have network errors or restarts.
763 UpdateTransactionPattern(PATTERN_NOT_COVERED); 766 UpdateTransactionPattern(PATTERN_NOT_COVERED);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 } 835 }
833 UpdateTransactionPattern(PATTERN_ENTRY_UPDATED); 836 UpdateTransactionPattern(PATTERN_ENTRY_UPDATED);
834 mode_ = WRITE; 837 mode_ = WRITE;
835 } 838 }
836 839
837 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE; 840 next_state_ = STATE_OVERWRITE_CACHED_RESPONSE;
838 return OK; 841 return OK;
839 } 842 }
840 843
841 int HttpCache::Transaction::DoNetworkRead() { 844 int HttpCache::Transaction::DoNetworkRead() {
845 ReportNetworkActionStart();
842 next_state_ = STATE_NETWORK_READ_COMPLETE; 846 next_state_ = STATE_NETWORK_READ_COMPLETE;
843 return network_trans_->Read(read_buf_, io_buf_len_, io_callback_); 847 return network_trans_->Read(read_buf_, io_buf_len_, io_callback_);
844 } 848 }
845 849
846 int HttpCache::Transaction::DoNetworkReadComplete(int result) { 850 int HttpCache::Transaction::DoNetworkReadComplete(int result) {
847 DCHECK(mode_ & WRITE || mode_ == NONE); 851 DCHECK(mode_ & WRITE || mode_ == NONE);
848 852
853 ReportNetworkActionFinish();
854
849 if (!cache_) 855 if (!cache_)
850 return ERR_UNEXPECTED; 856 return ERR_UNEXPECTED;
851 857
852 if (result > 0) 858 if (result > 0)
853 bytes_read_from_network_ += result; 859 bytes_read_from_network_ += result;
854 860
855 // If there is an error or we aren't saving the data, we are done; just wait 861 // 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. 862 // until the destructor runs to see if we can keep the data.
857 if (mode_ == NONE || result < 0) 863 if (mode_ == NONE || result < 0)
858 return result; 864 return result;
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 if (entry_) { 1318 if (entry_) {
1313 if (net_log_.IsLoggingAllEvents()) 1319 if (net_log_.IsLoggingAllEvents())
1314 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); 1320 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO);
1315 ReportCacheActionStart(); 1321 ReportCacheActionStart();
1316 } 1322 }
1317 return WriteResponseInfoToEntry(false); 1323 return WriteResponseInfoToEntry(false);
1318 } 1324 }
1319 1325
1320 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { 1326 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() {
1321 if (entry_) { 1327 if (entry_) {
1322 if (net_log_.IsLoggingAllEvents() && entry_) 1328 if (net_log_.IsLoggingAllEvents())
1323 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); 1329 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO);
1324 ReportCacheActionStart(); 1330 ReportCacheActionStart();
1325 } 1331 }
1326 return WriteResponseInfoToEntry(true); 1332 return WriteResponseInfoToEntry(true);
1327 } 1333 }
1328 1334
1329 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { 1335 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) {
1330 next_state_ = target_state_; 1336 next_state_ = target_state_;
1331 target_state_ = STATE_NONE; 1337 target_state_ = STATE_NONE;
1332 if (!entry_) 1338 if (!entry_)
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 1772
1767 next_state_ = STATE_SEND_REQUEST; 1773 next_state_ = STATE_SEND_REQUEST;
1768 return OK; 1774 return OK;
1769 } 1775 }
1770 1776
1771 int HttpCache::Transaction::RestartNetworkRequest() { 1777 int HttpCache::Transaction::RestartNetworkRequest() {
1772 DCHECK(mode_ & WRITE || mode_ == NONE); 1778 DCHECK(mode_ & WRITE || mode_ == NONE);
1773 DCHECK(network_trans_.get()); 1779 DCHECK(network_trans_.get());
1774 DCHECK_EQ(STATE_NONE, next_state_); 1780 DCHECK_EQ(STATE_NONE, next_state_);
1775 1781
1782 ReportNetworkActionStart();
1776 next_state_ = STATE_SEND_REQUEST_COMPLETE; 1783 next_state_ = STATE_SEND_REQUEST_COMPLETE;
1777 int rv = network_trans_->RestartIgnoringLastError(io_callback_); 1784 int rv = network_trans_->RestartIgnoringLastError(io_callback_);
1778 if (rv != ERR_IO_PENDING) 1785 if (rv != ERR_IO_PENDING)
1779 return DoLoop(rv); 1786 return DoLoop(rv);
1780 return rv; 1787 return rv;
1781 } 1788 }
1782 1789
1783 int HttpCache::Transaction::RestartNetworkRequestWithCertificate( 1790 int HttpCache::Transaction::RestartNetworkRequestWithCertificate(
1784 X509Certificate* client_cert) { 1791 X509Certificate* client_cert) {
1785 DCHECK(mode_ & WRITE || mode_ == NONE); 1792 DCHECK(mode_ & WRITE || mode_ == NONE);
1786 DCHECK(network_trans_.get()); 1793 DCHECK(network_trans_.get());
1787 DCHECK_EQ(STATE_NONE, next_state_); 1794 DCHECK_EQ(STATE_NONE, next_state_);
1788 1795
1796 ReportNetworkActionStart();
1789 next_state_ = STATE_SEND_REQUEST_COMPLETE; 1797 next_state_ = STATE_SEND_REQUEST_COMPLETE;
1790 int rv = network_trans_->RestartWithCertificate(client_cert, io_callback_); 1798 int rv = network_trans_->RestartWithCertificate(client_cert, io_callback_);
1791 if (rv != ERR_IO_PENDING) 1799 if (rv != ERR_IO_PENDING)
1792 return DoLoop(rv); 1800 return DoLoop(rv);
1793 return rv; 1801 return rv;
1794 } 1802 }
1795 1803
1796 int HttpCache::Transaction::RestartNetworkRequestWithAuth( 1804 int HttpCache::Transaction::RestartNetworkRequestWithAuth(
1797 const AuthCredentials& credentials) { 1805 const AuthCredentials& credentials) {
1798 DCHECK(mode_ & WRITE || mode_ == NONE); 1806 DCHECK(mode_ & WRITE || mode_ == NONE);
1799 DCHECK(network_trans_.get()); 1807 DCHECK(network_trans_.get());
1800 DCHECK_EQ(STATE_NONE, next_state_); 1808 DCHECK_EQ(STATE_NONE, next_state_);
1801 1809
1810 ReportNetworkActionStart();
1802 next_state_ = STATE_SEND_REQUEST_COMPLETE; 1811 next_state_ = STATE_SEND_REQUEST_COMPLETE;
1803 int rv = network_trans_->RestartWithAuth(credentials, io_callback_); 1812 int rv = network_trans_->RestartWithAuth(credentials, io_callback_);
1804 if (rv != ERR_IO_PENDING) 1813 if (rv != ERR_IO_PENDING)
1805 return DoLoop(rv); 1814 return DoLoop(rv);
1806 return rv; 1815 return rv;
1807 } 1816 }
1808 1817
1809 bool HttpCache::Transaction::RequiresValidation() { 1818 bool HttpCache::Transaction::RequiresValidation() {
1810 // TODO(darin): need to do more work here: 1819 // TODO(darin): need to do more work here:
1811 // - make sure we have a matching request method 1820 // - make sure we have a matching request method
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 // HTTPS with a cert error we show an SSL blocking page. If the user clicks 2085 // 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 2086 // proceed we reload the resource ignoring the errors. The loaded resource
2078 // is then cached. If that resource is subsequently loaded from the cache, 2087 // 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 2088 // 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 2089 // 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. 2090 // reverse-map the cert status to a net error and replay the net error.
2082 if ((cache_->mode() != RECORD && 2091 if ((cache_->mode() != RECORD &&
2083 response_.headers->HasHeaderValue("cache-control", "no-store")) || 2092 response_.headers->HasHeaderValue("cache-control", "no-store")) ||
2084 net::IsCertStatusError(response_.ssl_info.cert_status)) { 2093 net::IsCertStatusError(response_.ssl_info.cert_status)) {
2085 DoneWritingToEntry(false); 2094 DoneWritingToEntry(false);
2095 ReportCacheActionFinish();
2096 if (net_log_.IsLoggingAllEvents()) {
2097 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO,
2098 OK);
mmenke 2012/08/15 15:09:53 optional nit: Can just use EndEvent. "OK" is ign
tburkard 2012/08/15 16:50:46 Done.
2099 }
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
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698