Chromium Code Reviews| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 base::Bind(&DataUseMeasurement::OnApplicationStateChange, | 93 base::Bind(&DataUseMeasurement::OnApplicationStateChange, |
| 94 base::Unretained(this)))), | 94 base::Unretained(this)))), |
| 95 rx_bytes_os_(0), | 95 rx_bytes_os_(0), |
| 96 tx_bytes_os_(0), | 96 tx_bytes_os_(0), |
| 97 bytes_transferred_since_last_traffic_stats_query_(0), | 97 bytes_transferred_since_last_traffic_stats_query_(0), |
| 98 no_reads_since_background_(false) | 98 no_reads_since_background_(false) |
| 99 #endif | 99 #endif |
| 100 { | 100 { |
| 101 DCHECK(ascriber_); | 101 DCHECK(ascriber_); |
| 102 DCHECK(url_request_classifier_); | 102 DCHECK(url_request_classifier_); |
| 103 memset(user_traffic_content_type_bytes_, 0, | |
| 104 sizeof(user_traffic_content_type_bytes_)); | |
| 103 | 105 |
| 104 #if defined(OS_ANDROID) | 106 #if defined(OS_ANDROID) |
| 105 int64_t bytes = 0; | 107 int64_t bytes = 0; |
| 106 // Query Android traffic stats. | 108 // Query Android traffic stats. |
| 107 if (net::android::traffic_stats::GetCurrentUidRxBytes(&bytes)) | 109 if (net::android::traffic_stats::GetCurrentUidRxBytes(&bytes)) |
| 108 rx_bytes_os_ = bytes; | 110 rx_bytes_os_ = bytes; |
| 109 | 111 |
| 110 if (net::android::traffic_stats::GetCurrentUidTxBytes(&bytes)) | 112 if (net::android::traffic_stats::GetCurrentUidTxBytes(&bytes)) |
| 111 tx_bytes_os_ = bytes; | 113 tx_bytes_os_ = bytes; |
| 112 #endif | 114 #endif |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 : DataUseUserData::AUDIO); | 440 : DataUseUserData::AUDIO); |
| 439 } else if (content_type == DataUseUserData::VIDEO) { | 441 } else if (content_type == DataUseUserData::VIDEO) { |
| 440 content_type = app_state != DataUseUserData::FOREGROUND | 442 content_type = app_state != DataUseUserData::FOREGROUND |
| 441 ? DataUseUserData::VIDEO_APPBACKGROUND | 443 ? DataUseUserData::VIDEO_APPBACKGROUND |
| 442 : (!is_tab_visible ? DataUseUserData::VIDEO_TABBACKGROUND | 444 : (!is_tab_visible ? DataUseUserData::VIDEO_TABBACKGROUND |
| 443 : DataUseUserData::VIDEO); | 445 : DataUseUserData::VIDEO); |
| 444 } | 446 } |
| 445 // Use the more primitive STATIC_HISTOGRAM_POINTER_BLOCK macro because the | 447 // Use the more primitive STATIC_HISTOGRAM_POINTER_BLOCK macro because the |
| 446 // simple UMA_HISTOGRAM_ENUMERATION macros don't expose 'AddCount'. | 448 // simple UMA_HISTOGRAM_ENUMERATION macros don't expose 'AddCount'. |
| 447 if (is_user_traffic) { | 449 if (is_user_traffic) { |
| 448 STATIC_HISTOGRAM_POINTER_BLOCK( | 450 bytes += user_traffic_content_type_bytes_[content_type]; |
| 449 "DataUse.ContentType.UserTraffic", AddCount(content_type, bytes), | 451 if (bytes >= 1024) { |
| 450 base::LinearHistogram::FactoryGet( | 452 STATIC_HISTOGRAM_POINTER_BLOCK( |
| 451 "DataUse.ContentType.UserTraffic", 1, DataUseUserData::TYPE_MAX, | 453 "DataUse.ContentType.UserTrafficKB", |
| 452 DataUseUserData::TYPE_MAX + 1, | 454 AddCount(content_type, bytes / 1024), |
| 453 base::HistogramBase::kUmaTargetedHistogramFlag)); | 455 base::LinearHistogram::FactoryGet( |
| 456 "DataUse.ContentType.UserTrafficKB", 1, DataUseUserData::TYPE_MAX, | |
|
Ilya Sherman
2017/05/02 21:28:52
This histogram would still overflow if there are ~
Ilya Sherman
2017/05/02 21:29:58
Actually, slightly less than 4.5 TB, as I was calc
| |
| 457 DataUseUserData::TYPE_MAX + 1, | |
| 458 base::HistogramBase::kUmaTargetedHistogramFlag)); | |
| 459 } | |
| 460 user_traffic_content_type_bytes_[content_type] = bytes % 1024; | |
| 454 } else { | 461 } else { |
| 455 STATIC_HISTOGRAM_POINTER_BLOCK( | 462 STATIC_HISTOGRAM_POINTER_BLOCK( |
| 456 "DataUse.ContentType.Services", AddCount(content_type, bytes), | 463 "DataUse.ContentType.Services", AddCount(content_type, bytes), |
| 457 base::LinearHistogram::FactoryGet( | 464 base::LinearHistogram::FactoryGet( |
| 458 "DataUse.ContentType.Services", 1, DataUseUserData::TYPE_MAX, | 465 "DataUse.ContentType.Services", 1, DataUseUserData::TYPE_MAX, |
| 459 DataUseUserData::TYPE_MAX + 1, | 466 DataUseUserData::TYPE_MAX + 1, |
| 460 base::HistogramBase::kUmaTargetedHistogramFlag)); | 467 base::HistogramBase::kUmaTargetedHistogramFlag)); |
| 461 } | 468 } |
| 462 } | 469 } |
| 463 | 470 |
| 464 void DataUseMeasurement::RecordPageTransitionUMA( | 471 void DataUseMeasurement::RecordPageTransitionUMA( |
| 465 const net::URLRequest& request) const { | 472 const net::URLRequest& request) const { |
| 466 if (!url_request_classifier_->IsUserRequest(request)) | 473 if (!url_request_classifier_->IsUserRequest(request)) |
| 467 return; | 474 return; |
| 468 | 475 |
| 469 const DataUseRecorder* recorder = ascriber_->GetDataUseRecorder(request); | 476 const DataUseRecorder* recorder = ascriber_->GetDataUseRecorder(request); |
| 470 if (recorder) { | 477 if (recorder) { |
| 471 url_request_classifier_->RecordPageTransitionUMA( | 478 url_request_classifier_->RecordPageTransitionUMA( |
| 472 recorder->page_transition(), request.GetTotalReceivedBytes()); | 479 recorder->page_transition(), request.GetTotalReceivedBytes()); |
| 473 } | 480 } |
| 474 } | 481 } |
| 475 | 482 |
| 476 } // namespace data_use_measurement | 483 } // namespace data_use_measurement |
| OLD | NEW |