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

Side by Side Diff: net/url_request/url_request_job.cc

Issue 1284993005: Notify NetworkDelegate when bytes have been received over the network. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed empty cronet OnRawBytesRead implementation Created 5 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
« no previous file with comments | « net/url_request/url_request_job.h ('k') | net/url_request/url_request_test_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/url_request/url_request_job.h" 5 #include "net/url_request/url_request_job.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 NetworkDelegate* network_delegate) 65 NetworkDelegate* network_delegate)
66 : request_(request), 66 : request_(request),
67 done_(false), 67 done_(false),
68 prefilter_bytes_read_(0), 68 prefilter_bytes_read_(0),
69 postfilter_bytes_read_(0), 69 postfilter_bytes_read_(0),
70 filter_needs_more_output_space_(false), 70 filter_needs_more_output_space_(false),
71 filtered_read_buffer_len_(0), 71 filtered_read_buffer_len_(0),
72 has_handled_response_(false), 72 has_handled_response_(false),
73 expected_content_size_(-1), 73 expected_content_size_(-1),
74 network_delegate_(network_delegate), 74 network_delegate_(network_delegate),
75 last_notified_total_received_bytes_(0),
75 weak_factory_(this) { 76 weak_factory_(this) {
76 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); 77 base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
77 if (power_monitor) 78 if (power_monitor)
78 power_monitor->AddObserver(this); 79 power_monitor->AddObserver(this);
79 } 80 }
80 81
81 void URLRequestJob::SetUpload(UploadDataStream* upload) { 82 void URLRequestJob::SetUpload(UploadDataStream* upload) {
82 } 83 }
83 84
84 void URLRequestJob::SetExtraRequestHeaders(const HttpRequestHeaders& headers) { 85 void URLRequestJob::SetExtraRequestHeaders(const HttpRequestHeaders& headers) {
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 request_->response_info_.response_time = base::Time::Now(); 389 request_->response_info_.response_time = base::Time::Now();
389 GetResponseInfo(&request_->response_info_); 390 GetResponseInfo(&request_->response_info_);
390 391
391 // When notifying the delegate, the delegate can release the request 392 // When notifying the delegate, the delegate can release the request
392 // (and thus release 'this'). After calling to the delgate, we must 393 // (and thus release 'this'). After calling to the delgate, we must
393 // check the request pointer to see if it still exists, and return 394 // check the request pointer to see if it still exists, and return
394 // immediately if it has been destroyed. self_preservation ensures our 395 // immediately if it has been destroyed. self_preservation ensures our
395 // survival until we can get out of this method. 396 // survival until we can get out of this method.
396 scoped_refptr<URLRequestJob> self_preservation(this); 397 scoped_refptr<URLRequestJob> self_preservation(this);
397 398
399 MaybeNotifyNetworkBytes();
400
398 if (request_) 401 if (request_)
399 request_->OnHeadersComplete(); 402 request_->OnHeadersComplete();
400 403
401 GURL new_location; 404 GURL new_location;
402 int http_status_code; 405 int http_status_code;
403 if (IsRedirectResponse(&new_location, &http_status_code)) { 406 if (IsRedirectResponse(&new_location, &http_status_code)) {
404 // Redirect response bodies are not read. Notify the transaction 407 // Redirect response bodies are not read. Notify the transaction
405 // so it does not treat being stopped as an error. 408 // so it does not treat being stopped as an error.
406 DoneReadingRedirectResponse(); 409 DoneReadingRedirectResponse();
407 410
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 UMA_HISTOGRAM_BOOLEAN("Net.ErrorResponseHasContentMainFrame", 563 UMA_HISTOGRAM_BOOLEAN("Net.ErrorResponseHasContentMainFrame",
561 page_has_content); 564 page_has_content);
562 } else { 565 } else {
563 UMA_HISTOGRAM_BOOLEAN("Net.ErrorResponseHasContentNonMainFrame", 566 UMA_HISTOGRAM_BOOLEAN("Net.ErrorResponseHasContentNonMainFrame",
564 page_has_content); 567 page_has_content);
565 } 568 }
566 } 569 }
567 } 570 }
568 } 571 }
569 572
573 MaybeNotifyNetworkBytes();
574
570 // Complete this notification later. This prevents us from re-entering the 575 // Complete this notification later. This prevents us from re-entering the
571 // delegate if we're done because of a synchronous call. 576 // delegate if we're done because of a synchronous call.
572 base::ThreadTaskRunnerHandle::Get()->PostTask( 577 base::ThreadTaskRunnerHandle::Get()->PostTask(
573 FROM_HERE, base::Bind(&URLRequestJob::CompleteNotifyDone, 578 FROM_HERE, base::Bind(&URLRequestJob::CompleteNotifyDone,
574 weak_factory_.GetWeakPtr())); 579 weak_factory_.GetWeakPtr()));
575 } 580 }
576 581
577 void URLRequestJob::CompleteNotifyDone() { 582 void URLRequestJob::CompleteNotifyDone() {
578 // Check if we should notify the delegate that we're done because of an error. 583 // Check if we should notify the delegate that we're done because of an error.
579 if (request_ && 584 if (request_ &&
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 } 862 }
858 863
859 if (!filter_.get()) 864 if (!filter_.get())
860 postfilter_bytes_read_ += bytes_read; 865 postfilter_bytes_read_ += bytes_read;
861 DVLOG(2) << __FUNCTION__ << "() " 866 DVLOG(2) << __FUNCTION__ << "() "
862 << "\"" << (request_ ? request_->url().spec() : "???") << "\"" 867 << "\"" << (request_ ? request_->url().spec() : "???") << "\""
863 << " pre bytes read = " << bytes_read 868 << " pre bytes read = " << bytes_read
864 << " pre total = " << prefilter_bytes_read_ 869 << " pre total = " << prefilter_bytes_read_
865 << " post total = " << postfilter_bytes_read_; 870 << " post total = " << postfilter_bytes_read_;
866 UpdatePacketReadTimes(); // Facilitate stats recording if it is active. 871 UpdatePacketReadTimes(); // Facilitate stats recording if it is active.
867 if (network_delegate_) 872
868 network_delegate_->NotifyRawBytesRead(*request_, bytes_read); 873 // Notify observers if any additional network usage has occurred. Note that
874 // the number of received bytes over the network sent by this notification
875 // could be vastly different from |bytes_read|, such as when a large chunk of
876 // network bytes is received before multiple smaller raw reads are performed
877 // on it.
878 MaybeNotifyNetworkBytes();
869 } 879 }
870 880
871 bool URLRequestJob::FilterHasData() { 881 bool URLRequestJob::FilterHasData() {
872 return filter_.get() && filter_->stream_data_len(); 882 return filter_.get() && filter_->stream_data_len();
873 } 883 }
874 884
875 void URLRequestJob::UpdatePacketReadTimes() { 885 void URLRequestJob::UpdatePacketReadTimes() {
876 } 886 }
877 887
878 RedirectInfo URLRequestJob::ComputeRedirectInfo(const GURL& location, 888 RedirectInfo URLRequestJob::ComputeRedirectInfo(const GURL& location,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 922
913 // Alter the referrer if redirecting cross-origin (especially HTTP->HTTPS). 923 // Alter the referrer if redirecting cross-origin (especially HTTP->HTTPS).
914 redirect_info.new_referrer = 924 redirect_info.new_referrer =
915 ComputeReferrerForRedirect(request_->referrer_policy(), 925 ComputeReferrerForRedirect(request_->referrer_policy(),
916 request_->referrer(), 926 request_->referrer(),
917 redirect_info.new_url).spec(); 927 redirect_info.new_url).spec();
918 928
919 return redirect_info; 929 return redirect_info;
920 } 930 }
921 931
932 void URLRequestJob::MaybeNotifyNetworkBytes() {
933 if (!request_ || !network_delegate_)
934 return;
935
936 int64_t total_received_bytes = GetTotalReceivedBytes();
937 DCHECK_GE(total_received_bytes, last_notified_total_received_bytes_);
938 if (total_received_bytes > last_notified_total_received_bytes_) {
939 network_delegate_->NotifyNetworkBytesReceived(
940 *request_, total_received_bytes - last_notified_total_received_bytes_);
941 }
942 last_notified_total_received_bytes_ = total_received_bytes;
943 }
944
922 } // namespace net 945 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_job.h ('k') | net/url_request/url_request_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698