OLD | NEW |
---|---|
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 "chrome/browser/net/chrome_network_delegate.h" | 5 #include "chrome/browser/net/chrome_network_delegate.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request, | 344 void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request, |
345 int net_error) { | 345 int net_error) { |
346 extensions_delegate_->OnResponseStarted(request, net_error); | 346 extensions_delegate_->OnResponseStarted(request, net_error); |
347 } | 347 } |
348 | 348 |
349 void ChromeNetworkDelegate::OnNetworkBytesReceived(net::URLRequest* request, | 349 void ChromeNetworkDelegate::OnNetworkBytesReceived(net::URLRequest* request, |
350 int64_t bytes_received) { | 350 int64_t bytes_received) { |
351 #if !defined(OS_ANDROID) | 351 #if !defined(OS_ANDROID) |
352 // Note: Currently, OnNetworkBytesReceived is only implemented for HTTP jobs, | 352 // Note: Currently, OnNetworkBytesReceived is only implemented for HTTP jobs, |
353 // not FTP or other types, so those kinds of bytes will not be reported here. | 353 // not FTP or other types, so those kinds of bytes will not be reported here. |
354 task_manager::TaskManagerInterface::OnRawBytesRead(*request, bytes_received); | 354 |
355 // Only net::URLRequestJob instances created by the ResourceDispatcherHost | |
356 // have an associated ResourceRequestInfo and a render frame associated. | |
357 // All other jobs will have -1 returned for the render process child and | |
358 // routing ids - the jobs may still match a resource based on their origin id, | |
359 // otherwise BytesRead() will attribute the activity to the Browser resource. | |
360 const content::ResourceRequestInfo* info = | |
361 content::ResourceRequestInfo::ForRequest(request); | |
362 int child_id = -1; | |
363 int route_id = -1; | |
364 | |
365 if (info) | |
366 info->GetAssociatedRenderFrame(&child_id, &route_id); | |
367 | |
368 // Get the origin PID of the request's originator. This will only be set for | |
369 // plugins - for renderer or browser initiated requests it will be zero. | |
370 int origin_pid = info ? info->GetOriginPID() : 0; | |
371 task_manager::BytesTransferredKey key = {origin_pid, child_id, route_id}; | |
372 int64_t bytes_sent = 0; | |
373 task_manager::TaskManagerInterface::OnRawBytesTransferred(key, bytes_received, | |
374 bytes_sent); | |
355 #endif // !defined(OS_ANDROID) | 375 #endif // !defined(OS_ANDROID) |
356 | 376 |
357 ReportDataUsageStats(request, 0 /* tx_bytes */, bytes_received); | 377 ReportDataUsageStats(request, 0 /* tx_bytes */, bytes_received); |
358 } | 378 } |
359 | 379 |
360 void ChromeNetworkDelegate::OnNetworkBytesSent(net::URLRequest* request, | 380 void ChromeNetworkDelegate::OnNetworkBytesSent(net::URLRequest* request, |
361 int64_t bytes_sent) { | 381 int64_t bytes_sent) { |
362 #if !defined(OS_ANDROID) | 382 #if !defined(OS_ANDROID) |
363 // Note: Currently, OnNetworkBytesSent is only implemented for HTTP jobs, | 383 // Note: Currently, OnNetworkBytesSent is only implemented for HTTP jobs, |
364 // not FTP or other types, so those kinds of bytes will not be reported here. | 384 // not FTP or other types, so those kinds of bytes will not be reported here. |
365 task_manager::TaskManagerInterface::OnRawBytesSent(*request, bytes_sent); | 385 |
386 // Only net::URLRequestJob instances created by the ResourceDispatcherHost | |
387 // have an associated ResourceRequestInfo and a render frame associated. | |
388 // All other jobs will have -1 returned for the render process child and | |
389 // routing ids - the jobs may still match a resource based on their origin id, | |
390 // otherwise BytesRead() will attribute the activity to the Browser resource. | |
391 const content::ResourceRequestInfo* info = | |
392 content::ResourceRequestInfo::ForRequest(request); | |
393 int child_id = -1; | |
394 int route_id = -1; | |
395 | |
396 if (info) | |
397 info->GetAssociatedRenderFrame(&child_id, &route_id); | |
398 | |
399 // Get the origin PID of the request's originator. This will only be set for | |
400 // plugins - for renderer or browser initiated requests it will be zero. | |
401 int origin_pid = info ? info->GetOriginPID() : 0; | |
402 task_manager::BytesTransferredKey key = {origin_pid, child_id, route_id}; | |
403 int bytes_received = 0; | |
404 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.
| |
405 bytes_sent); | |
366 #endif // !defined(OS_ANDROID) | 406 #endif // !defined(OS_ANDROID) |
367 | 407 |
368 ReportDataUsageStats(request, bytes_sent, 0 /* rx_bytes */); | 408 ReportDataUsageStats(request, bytes_sent, 0 /* rx_bytes */); |
369 } | 409 } |
370 | 410 |
371 void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request, | 411 void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request, |
372 bool started, | 412 bool started, |
373 int net_error) { | 413 int net_error) { |
374 DCHECK_NE(net::ERR_IO_PENDING, net_error); | 414 DCHECK_NE(net::ERR_IO_PENDING, net_error); |
375 | 415 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 if (!data_use_aggregator_) | 647 if (!data_use_aggregator_) |
608 return; | 648 return; |
609 | 649 |
610 if (is_data_usage_off_the_record_) { | 650 if (is_data_usage_off_the_record_) { |
611 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); | 651 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); |
612 return; | 652 return; |
613 } | 653 } |
614 | 654 |
615 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); | 655 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); |
616 } | 656 } |
OLD | NEW |