| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 bytes_transferred_since_last_traffic_stats_query_ += bytes_sent; | 136 bytes_transferred_since_last_traffic_stats_query_ += bytes_sent; |
| 137 #endif | 137 #endif |
| 138 } | 138 } |
| 139 | 139 |
| 140 void DataUseMeasurement::OnCompleted(const net::URLRequest& request, | 140 void DataUseMeasurement::OnCompleted(const net::URLRequest& request, |
| 141 bool started) { | 141 bool started) { |
| 142 // TODO(amohammadkhan): Verify that there is no double recording in data use | 142 // TODO(amohammadkhan): Verify that there is no double recording in data use |
| 143 // of redirected requests. | 143 // of redirected requests. |
| 144 UpdateDataUsePrefs(request); | 144 UpdateDataUsePrefs(request); |
| 145 ReportServicesMessageSizeUMA(request); | 145 ReportServicesMessageSizeUMA(request); |
| 146 RecordPageTransitionUMA(request); |
| 146 #if defined(OS_ANDROID) | 147 #if defined(OS_ANDROID) |
| 147 MaybeRecordNetworkBytesOS(); | 148 MaybeRecordNetworkBytesOS(); |
| 148 #endif | 149 #endif |
| 149 } | 150 } |
| 150 | 151 |
| 151 void DataUseMeasurement::ReportDataUseUMA(const net::URLRequest& request, | 152 void DataUseMeasurement::ReportDataUseUMA(const net::URLRequest& request, |
| 152 TrafficDirection dir, | 153 TrafficDirection dir, |
| 153 int64_t bytes) { | 154 int64_t bytes) { |
| 154 bool is_user_traffic = url_request_classifier_->IsUserRequest(request); | 155 bool is_user_traffic = url_request_classifier_->IsUserRequest(request); |
| 155 bool is_connection_cellular = | 156 bool is_connection_cellular = |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 GetHistogramName("DataUse.MessageSize.AllServices", dir, app_state, | 341 GetHistogramName("DataUse.MessageSize.AllServices", dir, app_state, |
| 341 is_connection_cellular), | 342 is_connection_cellular), |
| 342 service, message_size); | 343 service, message_size); |
| 343 } | 344 } |
| 344 } | 345 } |
| 345 | 346 |
| 346 void DataUseMeasurement::RecordTabStateHistogram( | 347 void DataUseMeasurement::RecordTabStateHistogram( |
| 347 TrafficDirection dir, | 348 TrafficDirection dir, |
| 348 DataUseUserData::AppState app_state, | 349 DataUseUserData::AppState app_state, |
| 349 bool is_tab_visible, | 350 bool is_tab_visible, |
| 350 int64_t bytes) { | 351 int64_t bytes) const { |
| 351 if (app_state == DataUseUserData::UNKNOWN) | 352 if (app_state == DataUseUserData::UNKNOWN) |
| 352 return; | 353 return; |
| 353 | 354 |
| 354 std::string histogram_name = "DataUse.AppTabState."; | 355 std::string histogram_name = "DataUse.AppTabState."; |
| 355 histogram_name.append(dir == UPSTREAM ? "Upstream." : "Downstream."); | 356 histogram_name.append(dir == UPSTREAM ? "Upstream." : "Downstream."); |
| 356 if (app_state == DataUseUserData::BACKGROUND) { | 357 if (app_state == DataUseUserData::BACKGROUND) { |
| 357 histogram_name.append("AppBackground"); | 358 histogram_name.append("AppBackground"); |
| 358 } else if (is_tab_visible) { | 359 } else if (is_tab_visible) { |
| 359 histogram_name.append("AppForeground.TabForeground"); | 360 histogram_name.append("AppForeground.TabForeground"); |
| 360 } else { | 361 } else { |
| 361 histogram_name.append("AppForeground.TabBackground"); | 362 histogram_name.append("AppForeground.TabBackground"); |
| 362 } | 363 } |
| 363 RecordUMAHistogramCount(histogram_name, bytes); | 364 RecordUMAHistogramCount(histogram_name, bytes); |
| 364 } | 365 } |
| 365 | 366 |
| 367 void DataUseMeasurement::RecordPageTransitionUMA( |
| 368 const net::URLRequest& request) const { |
| 369 if (!url_request_classifier_->IsUserRequest(request)) |
| 370 return; |
| 371 |
| 372 const DataUseRecorder* recorder = ascriber_->GetDataUseRecorder(request); |
| 373 if (recorder) { |
| 374 url_request_classifier_->RecordPageTransitionUMA( |
| 375 recorder->page_transition(), request.GetTotalReceivedBytes()); |
| 376 } |
| 377 } |
| 378 |
| 366 } // namespace data_use_measurement | 379 } // namespace data_use_measurement |
| OLD | NEW |