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

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 727 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();
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 907 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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
2225 void HttpCache::Transaction::ReportCacheActionStart() { 2234 void HttpCache::Transaction::ReportCacheActionStart() {
2226 if (transaction_delegate_) 2235 if (transaction_delegate_)
2227 transaction_delegate_->OnCacheActionStart(); 2236 transaction_delegate_->OnCacheActionStart();
2228 } 2237 }
2229 2238
2230 void HttpCache::Transaction::ReportCacheActionFinish() { 2239 void HttpCache::Transaction::ReportCacheActionFinish() {
2231 if (transaction_delegate_) 2240 if (transaction_delegate_)
2232 transaction_delegate_->OnCacheActionFinish(); 2241 transaction_delegate_->OnCacheActionFinish();
2233 } 2242 }
2234 2243
2244 void HttpCache::Transaction::ReportNetworkActionStart() {
2245 if (transaction_delegate_)
2246 transaction_delegate_->OnNetworkActionStart();
2247 }
2248
2249 void HttpCache::Transaction::ReportNetworkActionFinish() {
2250 if (transaction_delegate_)
2251 transaction_delegate_->OnNetworkActionFinish();
2252 }
2253
2235 void HttpCache::Transaction::UpdateTransactionPattern( 2254 void HttpCache::Transaction::UpdateTransactionPattern(
2236 TransactionPattern new_transaction_pattern) { 2255 TransactionPattern new_transaction_pattern) {
2237 if (transaction_pattern_ == PATTERN_NOT_COVERED) 2256 if (transaction_pattern_ == PATTERN_NOT_COVERED)
2238 return; 2257 return;
2239 DCHECK(transaction_pattern_ == PATTERN_UNDEFINED || 2258 DCHECK(transaction_pattern_ == PATTERN_UNDEFINED ||
2240 new_transaction_pattern == PATTERN_NOT_COVERED); 2259 new_transaction_pattern == PATTERN_NOT_COVERED);
2241 transaction_pattern_ = new_transaction_pattern; 2260 transaction_pattern_ = new_transaction_pattern;
2242 } 2261 }
2243 2262
2244 void HttpCache::Transaction::RecordHistograms() { 2263 void HttpCache::Transaction::RecordHistograms() {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
2349 before_send_percent); 2368 before_send_percent);
2350 } 2369 }
2351 break; 2370 break;
2352 } 2371 }
2353 default: 2372 default:
2354 NOTREACHED(); 2373 NOTREACHED();
2355 } 2374 }
2356 } 2375 }
2357 2376
2358 } // namespace net 2377 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698