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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_job.cc
diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc
index 682f3d18bfe954ef1fd21af5a7c5cc9196166e69..2eb4025f897bb9547888414b5ab9da0ad5ff8a48 100644
--- a/net/url_request/url_request_job.cc
+++ b/net/url_request/url_request_job.cc
@@ -72,6 +72,7 @@ URLRequestJob::URLRequestJob(URLRequest* request,
has_handled_response_(false),
expected_content_size_(-1),
network_delegate_(network_delegate),
+ last_notified_total_received_bytes_(0),
weak_factory_(this) {
base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
if (power_monitor)
@@ -395,6 +396,8 @@ void URLRequestJob::NotifyHeadersComplete() {
// survival until we can get out of this method.
scoped_refptr<URLRequestJob> self_preservation(this);
+ MaybeNotifyNetworkBytes();
+
if (request_)
request_->OnHeadersComplete();
@@ -567,6 +570,8 @@ void URLRequestJob::NotifyDone(const URLRequestStatus &status) {
}
}
+ MaybeNotifyNetworkBytes();
+
// Complete this notification later. This prevents us from re-entering the
// delegate if we're done because of a synchronous call.
base::ThreadTaskRunnerHandle::Get()->PostTask(
@@ -864,8 +869,13 @@ void URLRequestJob::RecordBytesRead(int bytes_read) {
<< " pre total = " << prefilter_bytes_read_
<< " post total = " << postfilter_bytes_read_;
UpdatePacketReadTimes(); // Facilitate stats recording if it is active.
- if (network_delegate_)
- network_delegate_->NotifyRawBytesRead(*request_, bytes_read);
+
+ // Notify observers if any additional network usage has occurred. Note that
+ // the number of received bytes over the network sent by this notification
+ // could be vastly different from |bytes_read|, such as when a large chunk of
+ // network bytes is received before multiple smaller raw reads are performed
+ // on it.
+ MaybeNotifyNetworkBytes();
}
bool URLRequestJob::FilterHasData() {
@@ -919,4 +929,17 @@ RedirectInfo URLRequestJob::ComputeRedirectInfo(const GURL& location,
return redirect_info;
}
+void URLRequestJob::MaybeNotifyNetworkBytes() {
+ if (!request_ || !network_delegate_)
+ return;
+
+ int64_t total_received_bytes = GetTotalReceivedBytes();
+ DCHECK_GE(total_received_bytes, last_notified_total_received_bytes_);
+ if (total_received_bytes > last_notified_total_received_bytes_) {
+ network_delegate_->NotifyNetworkBytesReceived(
+ *request_, total_received_bytes - last_notified_total_received_bytes_);
+ }
+ last_notified_total_received_bytes_ = total_received_bytes;
+}
+
} // namespace net
« 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