Chromium Code Reviews| Index: chrome/browser/net/chrome_network_delegate.cc |
| diff --git a/chrome/browser/net/chrome_network_delegate.cc b/chrome/browser/net/chrome_network_delegate.cc |
| index fae150e3c1cbafe3022030df11c97765e4a47f92..5f576301c2a186c6091dc4dbd38530eb9570da5e 100644 |
| --- a/chrome/browser/net/chrome_network_delegate.cc |
| +++ b/chrome/browser/net/chrome_network_delegate.cc |
| @@ -351,7 +351,27 @@ void ChromeNetworkDelegate::OnNetworkBytesReceived(net::URLRequest* request, |
| #if !defined(OS_ANDROID) |
| // Note: Currently, OnNetworkBytesReceived is only implemented for HTTP jobs, |
| // not FTP or other types, so those kinds of bytes will not be reported here. |
| - task_manager::TaskManagerInterface::OnRawBytesRead(*request, bytes_received); |
| + |
| + // Only net::URLRequestJob instances created by the ResourceDispatcherHost |
| + // have an associated ResourceRequestInfo and a render frame associated. |
| + // All other jobs will have -1 returned for the render process child and |
| + // routing ids - the jobs may still match a resource based on their origin id, |
| + // otherwise BytesRead() will attribute the activity to the Browser resource. |
| + const content::ResourceRequestInfo* info = |
| + content::ResourceRequestInfo::ForRequest(request); |
| + int child_id = -1; |
| + int route_id = -1; |
| + |
| + if (info) |
| + info->GetAssociatedRenderFrame(&child_id, &route_id); |
| + |
| + // Get the origin PID of the request's originator. This will only be set for |
| + // plugins - for renderer or browser initiated requests it will be zero. |
| + int origin_pid = info ? info->GetOriginPID() : 0; |
| + task_manager::BytesTransferredKey key = {origin_pid, child_id, route_id}; |
| + int64_t bytes_sent = 0; |
| + task_manager::TaskManagerInterface::OnRawBytesTransferred(key, bytes_received, |
| + bytes_sent); |
| #endif // !defined(OS_ANDROID) |
| ReportDataUsageStats(request, 0 /* tx_bytes */, bytes_received); |
| @@ -362,7 +382,27 @@ void ChromeNetworkDelegate::OnNetworkBytesSent(net::URLRequest* request, |
| #if !defined(OS_ANDROID) |
| // Note: Currently, OnNetworkBytesSent is only implemented for HTTP jobs, |
| // not FTP or other types, so those kinds of bytes will not be reported here. |
| - task_manager::TaskManagerInterface::OnRawBytesSent(*request, bytes_sent); |
| + |
| + // Only net::URLRequestJob instances created by the ResourceDispatcherHost |
| + // have an associated ResourceRequestInfo and a render frame associated. |
| + // All other jobs will have -1 returned for the render process child and |
| + // routing ids - the jobs may still match a resource based on their origin id, |
| + // otherwise BytesRead() will attribute the activity to the Browser resource. |
| + const content::ResourceRequestInfo* info = |
| + content::ResourceRequestInfo::ForRequest(request); |
| + int child_id = -1; |
| + int route_id = -1; |
| + |
| + if (info) |
| + info->GetAssociatedRenderFrame(&child_id, &route_id); |
| + |
| + // Get the origin PID of the request's originator. This will only be set for |
| + // plugins - for renderer or browser initiated requests it will be zero. |
| + int origin_pid = info ? info->GetOriginPID() : 0; |
| + task_manager::BytesTransferredKey key = {origin_pid, child_id, route_id}; |
| + int bytes_received = 0; |
| + task_manager::TaskManagerInterface::OnRawBytesTransferred(key, bytes_received, |
|
ncarter (slow)
2017/06/29 23:40:00
Let's adjust this layering slightly. It shouldn't
cburn
2017/06/30 18:04:38
Done. That is a much better solution.
|
| + bytes_sent); |
| #endif // !defined(OS_ANDROID) |
| ReportDataUsageStats(request, bytes_sent, 0 /* rx_bytes */); |