| 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..195ca8516301f7206e3b40df471d811feaf5cbfe 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,28 @@ void URLRequestJob::SetProxyServer(const HostPortPair& proxy_server) {
|
| request_->proxy_server_ = proxy_server;
|
| }
|
|
|
| +void URLRequestJob::MaybeNotifyNetworkBytes() {
|
| + if (!request_ || !network_delegate_)
|
| + return;
|
| +
|
| + int64_t 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. Note that
|
| + // URLRequestHttpJob calls MaybeNotifyNetworkBytes shortly before killing the
|
| + // transaction in these cases.
|
| + 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 +893,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() {
|
|
|