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/content/data_use_measurement.h" | 5 #include "components/data_use_measurement/content/data_use_measurement.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.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" |
| 11 #include "content/public/browser/resource_request_info.h" | 11 #include "content/public/browser/resource_request_info.h" |
| 12 #include "components/metrics/metrics_data_use_measurements.h" | |
| 12 #include "net/base/network_change_notifier.h" | 13 #include "net/base/network_change_notifier.h" |
| 13 #include "net/base/upload_data_stream.h" | 14 #include "net/base/upload_data_stream.h" |
| 14 #include "net/http/http_response_headers.h" | 15 #include "net/http/http_response_headers.h" |
| 15 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
| 16 | 17 |
| 17 namespace data_use_measurement { | 18 namespace data_use_measurement { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Records the occurrence of |sample| in |name| histogram. Conventional UMA | 22 // Records the occurrence of |sample| in |name| histogram. Conventional UMA |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 UPSTREAM), | 82 UPSTREAM), |
| 82 total_upload_bytes); | 83 total_upload_bytes); |
| 83 RecordUMAHistogramCount( | 84 RecordUMAHistogramCount( |
| 84 GetHistogramName(is_user_traffic ? "DataUse.TrafficSize.User" | 85 GetHistogramName(is_user_traffic ? "DataUse.TrafficSize.User" |
| 85 : "DataUse.TrafficSize.System", | 86 : "DataUse.TrafficSize.System", |
| 86 DOWNSTREAM), | 87 DOWNSTREAM), |
| 87 total_received_bytes); | 88 total_received_bytes); |
| 88 | 89 |
| 89 DataUseUserData* attached_service_data = reinterpret_cast<DataUseUserData*>( | 90 DataUseUserData* attached_service_data = reinterpret_cast<DataUseUserData*>( |
| 90 request->GetUserData(DataUseUserData::kUserDataKey)); | 91 request->GetUserData(DataUseUserData::kUserDataKey)); |
| 91 | 92 DataUseUserData::ServiceName service_name = |
| 93 attached_service_data ? attached_service_data->service_name() | |
| 94 : DataUseUserData::NOT_TAGGED; | |
| 92 if (!is_user_traffic) { | 95 if (!is_user_traffic) { |
| 93 DataUseUserData::ServiceName service_name = | |
| 94 attached_service_data ? attached_service_data->service_name() | |
| 95 : DataUseUserData::NOT_TAGGED; | |
| 96 ReportDataUsageServices(service_name, UPSTREAM, total_upload_bytes); | 96 ReportDataUsageServices(service_name, UPSTREAM, total_upload_bytes); |
| 97 ReportDataUsageServices(service_name, DOWNSTREAM, total_received_bytes); | 97 ReportDataUsageServices(service_name, DOWNSTREAM, total_received_bytes); |
| 98 } | 98 } |
| 99 metrics::MetricsDataUseMeasurements::GetInstance()->UpdateMetricsUsagePrefs( | |
|
Alexei Svitkine (slow)
2016/03/18 22:23:29
We can discuss more offline, but I would prefer th
gayane -on leave until 09-2017
2016/03/29 16:06:20
Done.
| |
| 100 attached_service_data->GetServiceNameAsString(service_name), | |
| 101 total_upload_bytes + total_received_bytes); | |
| 99 } | 102 } |
| 100 | 103 |
| 101 #if defined(OS_ANDROID) | 104 #if defined(OS_ANDROID) |
| 102 void DataUseMeasurement::OnApplicationStateChangeForTesting( | 105 void DataUseMeasurement::OnApplicationStateChangeForTesting( |
| 103 base::android::ApplicationState application_state) { | 106 base::android::ApplicationState application_state) { |
| 104 app_state_ = application_state; | 107 app_state_ = application_state; |
| 105 } | 108 } |
| 106 #endif | 109 #endif |
| 107 | 110 |
| 108 DataUseMeasurement::AppState DataUseMeasurement::CurrentAppState() const { | 111 DataUseMeasurement::AppState DataUseMeasurement::CurrentAppState() const { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 138 int64_t message_size) const { | 141 int64_t message_size) const { |
| 139 RecordUMAHistogramCount( | 142 RecordUMAHistogramCount( |
| 140 "DataUse.MessageSize." + DataUseUserData::GetServiceNameAsString(service), | 143 "DataUse.MessageSize." + DataUseUserData::GetServiceNameAsString(service), |
| 141 message_size); | 144 message_size); |
| 142 if (message_size > 0) { | 145 if (message_size > 0) { |
| 143 IncreaseSparseHistogramByValue( | 146 IncreaseSparseHistogramByValue( |
| 144 GetHistogramName("DataUse.MessageSize.AllServices", dir), service, | 147 GetHistogramName("DataUse.MessageSize.AllServices", dir), service, |
| 145 message_size); | 148 message_size); |
| 146 } | 149 } |
| 147 } | 150 } |
| 148 | |
| 149 } // namespace data_use_measurement | 151 } // namespace data_use_measurement |
| OLD | NEW |