| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/data_use_measurement/core/data_use_measurement.h" | 5 #include "components/data_use_measurement/core/data_use_measurement.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/metrics/sparse_histogram.h" | 8 #include "base/metrics/sparse_histogram.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 base::Bind(&DataUseMeasurement::OnApplicationStateChange, | 81 base::Bind(&DataUseMeasurement::OnApplicationStateChange, |
| 82 base::Unretained(this)))), | 82 base::Unretained(this)))), |
| 83 rx_bytes_os_(0), | 83 rx_bytes_os_(0), |
| 84 tx_bytes_os_(0), | 84 tx_bytes_os_(0), |
| 85 bytes_transferred_since_last_traffic_stats_query_(0), | 85 bytes_transferred_since_last_traffic_stats_query_(0), |
| 86 no_reads_since_background_(false) | 86 no_reads_since_background_(false) |
| 87 #endif | 87 #endif |
| 88 { | 88 { |
| 89 DCHECK(ascriber_); | 89 DCHECK(ascriber_); |
| 90 DCHECK(url_request_classifier_); | 90 DCHECK(url_request_classifier_); |
| 91 |
| 92 #if defined(OS_ANDROID) |
| 93 int64_t bytes = 0; |
| 94 // Query Android traffic stats. |
| 95 if (net::android::traffic_stats::GetCurrentUidRxBytes(&bytes)) |
| 96 rx_bytes_os_ = bytes; |
| 97 |
| 98 if (net::android::traffic_stats::GetCurrentUidTxBytes(&bytes)) |
| 99 tx_bytes_os_ = bytes; |
| 100 #endif |
| 91 } | 101 } |
| 92 | 102 |
| 93 DataUseMeasurement::~DataUseMeasurement(){}; | 103 DataUseMeasurement::~DataUseMeasurement(){}; |
| 94 | 104 |
| 95 void DataUseMeasurement::OnBeforeURLRequest(net::URLRequest* request) { | 105 void DataUseMeasurement::OnBeforeURLRequest(net::URLRequest* request) { |
| 96 DataUseUserData* data_use_user_data = reinterpret_cast<DataUseUserData*>( | 106 DataUseUserData* data_use_user_data = reinterpret_cast<DataUseUserData*>( |
| 97 request->GetUserData(DataUseUserData::kUserDataKey)); | 107 request->GetUserData(DataUseUserData::kUserDataKey)); |
| 98 if (!data_use_user_data) { | 108 if (!data_use_user_data) { |
| 99 DataUseUserData::ServiceName service_name = | 109 DataUseUserData::ServiceName service_name = |
| 100 DataUseUserData::ServiceName::NOT_TAGGED; | 110 DataUseUserData::ServiceName::NOT_TAGGED; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 return; | 315 return; |
| 306 } | 316 } |
| 307 bytes_transferred_since_last_traffic_stats_query_ = 0; | 317 bytes_transferred_since_last_traffic_stats_query_ = 0; |
| 308 int64_t bytes = 0; | 318 int64_t bytes = 0; |
| 309 // Query Android traffic stats directly instead of registering with the | 319 // Query Android traffic stats directly instead of registering with the |
| 310 // DataUseAggregator since the latter does not provide notifications for | 320 // DataUseAggregator since the latter does not provide notifications for |
| 311 // the incognito traffic. | 321 // the incognito traffic. |
| 312 if (net::android::traffic_stats::GetCurrentUidRxBytes(&bytes)) { | 322 if (net::android::traffic_stats::GetCurrentUidRxBytes(&bytes)) { |
| 313 if (rx_bytes_os_ != 0) { | 323 if (rx_bytes_os_ != 0) { |
| 314 DCHECK_GE(bytes, rx_bytes_os_); | 324 DCHECK_GE(bytes, rx_bytes_os_); |
| 315 UMA_HISTOGRAM_COUNTS("DataUse.BytesReceived.OS", bytes - rx_bytes_os_); | 325 if (bytes > rx_bytes_os_) { |
| 326 // Do not record samples with value 0. |
| 327 UMA_HISTOGRAM_COUNTS("DataUse.BytesReceived.OS", bytes - rx_bytes_os_); |
| 328 } |
| 316 } | 329 } |
| 317 rx_bytes_os_ = bytes; | 330 rx_bytes_os_ = bytes; |
| 318 } | 331 } |
| 319 | 332 |
| 320 if (net::android::traffic_stats::GetCurrentUidTxBytes(&bytes)) { | 333 if (net::android::traffic_stats::GetCurrentUidTxBytes(&bytes)) { |
| 321 if (tx_bytes_os_ != 0) { | 334 if (tx_bytes_os_ != 0) { |
| 322 DCHECK_GE(bytes, tx_bytes_os_); | 335 DCHECK_GE(bytes, tx_bytes_os_); |
| 323 UMA_HISTOGRAM_COUNTS("DataUse.BytesSent.OS", bytes - tx_bytes_os_); | 336 if (bytes > tx_bytes_os_) { |
| 337 // Do not record samples with value 0. |
| 338 UMA_HISTOGRAM_COUNTS("DataUse.BytesSent.OS", bytes - tx_bytes_os_); |
| 339 } |
| 324 } | 340 } |
| 325 tx_bytes_os_ = bytes; | 341 tx_bytes_os_ = bytes; |
| 326 } | 342 } |
| 327 } | 343 } |
| 328 #endif | 344 #endif |
| 329 | 345 |
| 330 void DataUseMeasurement::ReportServicesMessageSizeUMA( | 346 void DataUseMeasurement::ReportServicesMessageSizeUMA( |
| 331 const net::URLRequest& request) { | 347 const net::URLRequest& request) { |
| 332 bool is_user_traffic = url_request_classifier_->IsUserRequest(request); | 348 bool is_user_traffic = url_request_classifier_->IsUserRequest(request); |
| 333 bool is_connection_cellular = | 349 bool is_connection_cellular = |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 STATIC_HISTOGRAM_POINTER_BLOCK( | 434 STATIC_HISTOGRAM_POINTER_BLOCK( |
| 419 "DataUse.ContentType.Services", AddCount(content_type, bytes), | 435 "DataUse.ContentType.Services", AddCount(content_type, bytes), |
| 420 base::LinearHistogram::FactoryGet( | 436 base::LinearHistogram::FactoryGet( |
| 421 "DataUse.ContentType.Services", 1, DataUseUserData::TYPE_MAX, | 437 "DataUse.ContentType.Services", 1, DataUseUserData::TYPE_MAX, |
| 422 DataUseUserData::TYPE_MAX + 1, | 438 DataUseUserData::TYPE_MAX + 1, |
| 423 base::HistogramBase::kUmaTargetedHistogramFlag)); | 439 base::HistogramBase::kUmaTargetedHistogramFlag)); |
| 424 } | 440 } |
| 425 } | 441 } |
| 426 | 442 |
| 427 } // namespace data_use_measurement | 443 } // namespace data_use_measurement |
| OLD | NEW |