Chromium Code Reviews| Index: components/data_use_measurement/content/data_use_measurement.cc |
| diff --git a/components/data_use_measurement/content/data_use_measurement.cc b/components/data_use_measurement/content/data_use_measurement.cc |
| index dd70ad5607af5aa785fc97068c66054f5eb9af94..40969da9d9087ee30d096a9261d2e61cf8bc1662 100644 |
| --- a/components/data_use_measurement/content/data_use_measurement.cc |
| +++ b/components/data_use_measurement/content/data_use_measurement.cc |
| @@ -14,6 +14,10 @@ |
| #include "net/http/http_response_headers.h" |
| #include "net/url_request/url_request.h" |
| +#if defined(OS_ANDROID) |
| +#include "net/android/traffic_stats.h" |
| +#endif |
| + |
| namespace data_use_measurement { |
| namespace { |
| @@ -52,7 +56,9 @@ DataUseMeasurement::DataUseMeasurement( |
| app_state_(base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES), |
| app_listener_(new base::android::ApplicationStatusListener( |
| base::Bind(&DataUseMeasurement::OnApplicationStateChange, |
| - base::Unretained(this)))) |
| + base::Unretained(this)))), |
| + rx_bytes_os_(0), |
| + tx_bytes_os_(0) |
| #endif |
| { |
| } |
| @@ -65,6 +71,18 @@ void DataUseMeasurement::OnBeforeRedirect(const net::URLRequest& request, |
| ReportDataUseUMA(request); |
| } |
| +void DataUseMeasurement::OnNetworkBytesReceived(const net::URLRequest& request, |
| + int64_t bytes_received) { |
| + UMA_HISTOGRAM_COUNTS("DataUse.BytesReceived.Delegate", bytes_received); |
| + RecordNetworkBytesReceivedOS(); |
|
sclittle
2016/09/14 21:28:13
Is it OK for performance to call this so often? No
tbansal1
2016/09/15 17:46:04
Good catch. Fixed.
|
| +} |
| + |
| +void DataUseMeasurement::OnNetworkBytesSent(const net::URLRequest& request, |
| + int64_t bytes_sent) { |
| + UMA_HISTOGRAM_COUNTS("DataUse.BytesSent.Delegate", bytes_sent); |
| + RecordNetworkBytesSentOS(); |
| +} |
| + |
| void DataUseMeasurement::OnCompleted(const net::URLRequest& request, |
| bool started) { |
| // TODO(amohammadkhan): Verify that there is no double recording in data use |
| @@ -181,4 +199,30 @@ void DataUseMeasurement::ReportDataUsageServices( |
| } |
| } |
| +void DataUseMeasurement::RecordNetworkBytesReceivedOS() { |
|
sclittle
2016/09/14 21:28:13
Is there a timing issue here? E.g., suppose there'
tbansal1
2016/09/15 17:46:04
No, because I am not attributing traffic stats byt
|
| +#if defined(OS_ANDROID) |
| + int64_t bytes = 0; |
| + if (net::android::traffic_stats::GetCurrentUidRxBytes(&bytes)) { |
| + if (rx_bytes_os_ != 0) { |
| + DCHECK_GE(bytes, rx_bytes_os_); |
|
sclittle
2016/09/14 21:28:13
Are you sure you want to crash if this condition d
tbansal1
2016/09/15 17:46:04
Yes, android provides guarantee that this is alway
|
| + UMA_HISTOGRAM_COUNTS("DataUse.BytesReceived.OS", bytes - rx_bytes_os_); |
| + } |
| + rx_bytes_os_ = bytes; |
| + } |
| +#endif |
| +} |
| + |
| +void DataUseMeasurement::RecordNetworkBytesSentOS() { |
| +#if defined(OS_ANDROID) |
| + int64_t bytes = 0; |
| + if (net::android::traffic_stats::GetCurrentUidTxBytes(&bytes)) { |
| + if (tx_bytes_os_ != 0) { |
| + DCHECK_GE(bytes, tx_bytes_os_); |
| + UMA_HISTOGRAM_COUNTS("DataUse.BytesSent.OS", bytes - tx_bytes_os_); |
| + } |
| + tx_bytes_os_ = bytes; |
| + } |
| +#endif |
| +} |
| + |
| } // namespace data_use_measurement |