Chromium Code Reviews| 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..ff7581cd2eb0e065f93020385ef5a7edcb538365 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( |
| @@ -778,6 +783,26 @@ void URLRequestJob::SetProxyServer(const HostPortPair& proxy_server) { |
| request_->proxy_server_ = proxy_server; |
| } |
| +void URLRequestJob::MaybeNotifyNetworkBytes() { |
|
bengr
2015/08/17 21:30:40
Is this for sent bytes too? If not, the name shoul
sclittle
2015/08/17 23:35:14
Eventually it will be for both sent and received,
|
| + if (!request_ || !network_delegate_) |
| + return; |
| + |
|
tbansal1
2015/08/17 20:51:17
May be worth it to add a DCHECK:
DCHECK(!request_-
sclittle
2015/08/17 23:35:14
It's possible that responses served from a local c
|
| + int64 total_received_bytes = GetTotalReceivedBytes(); |
| + // For URLRequestHttpJobs, |total_received_bytes| will reset to 0 if the |
| + // transaction is killed, such as when a request is cancelled. Check for that |
| + // here to avoid reporting negative network usage in these cases. |
|
bengr
2015/08/17 21:30:40
What happens to the bytes received between the las
sclittle
2015/08/17 23:35:14
In URLRequestHttpJob, any remaining bytes received
|
| + if (total_received_bytes) { |
| + 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; |
| +} |
| + |
| bool URLRequestJob::ReadRawDataForFilter(int* bytes_read) { |
| bool rv = false; |
| @@ -866,6 +891,8 @@ void URLRequestJob::RecordBytesRead(int bytes_read) { |
| UpdatePacketReadTimes(); // Facilitate stats recording if it is active. |
| if (network_delegate_) |
| network_delegate_->NotifyRawBytesRead(*request_, bytes_read); |
| + |
| + MaybeNotifyNetworkBytes(); |
| } |
| bool URLRequestJob::FilterHasData() { |