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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 domain_reliability::DomainReliabilityUploader:: | 101 domain_reliability::DomainReliabilityUploader:: |
102 OriginatedFromDomainReliability(*request)) { | 102 OriginatedFromDomainReliability(*request)) { |
103 // Detect if the request originated from DomainReliability. | 103 // Detect if the request originated from DomainReliability. |
104 // DataUseUserData::AttachToFetcher() cannot be called from domain | 104 // DataUseUserData::AttachToFetcher() cannot be called from domain |
105 // reliability, since it sets userdata on URLFetcher for its purposes. | 105 // reliability, since it sets userdata on URLFetcher for its purposes. |
106 service_name = DataUseUserData::ServiceName::NOT_TAGGED; | 106 service_name = DataUseUserData::ServiceName::NOT_TAGGED; |
107 } | 107 } |
108 | 108 |
109 data_use_user_data = new DataUseUserData(service_name, CurrentAppState()); | 109 data_use_user_data = new DataUseUserData(service_name, CurrentAppState()); |
110 request->SetUserData(DataUseUserData::kUserDataKey, data_use_user_data); | 110 request->SetUserData(DataUseUserData::kUserDataKey, data_use_user_data); |
111 } else { | |
112 data_use_user_data->set_app_state(CurrentAppState()); | |
111 } | 113 } |
112 } | 114 } |
113 | 115 |
114 void DataUseMeasurement::OnBeforeRedirect(const net::URLRequest& request, | 116 void DataUseMeasurement::OnBeforeRedirect(const net::URLRequest& request, |
115 const GURL& new_location) { | 117 const GURL& new_location) { |
116 // Recording data use of request on redirects. | 118 // Recording data use of request on redirects. |
117 // TODO(rajendrant): May not be needed when http://crbug/651957 is fixed. | 119 // TODO(rajendrant): May not be needed when http://crbug/651957 is fixed. |
118 UpdateDataUsePrefs(request); | 120 UpdateDataUsePrefs(request); |
119 ReportServicesMessageSizeUMA(request); | 121 ReportServicesMessageSizeUMA(request); |
120 } | 122 } |
121 | 123 |
124 void DataUseMeasurement::OnHeadersReceived( | |
125 net::URLRequest* request, | |
126 const net::HttpResponseHeaders* response_headers) { | |
127 DataUseUserData* data_use_user_data = reinterpret_cast<DataUseUserData*>( | |
128 request->GetUserData(DataUseUserData::kUserDataKey)); | |
129 if (data_use_user_data) { | |
130 data_use_user_data->set_content_type( | |
131 url_request_classifier_->GetContentType(*request, *response_headers)); | |
132 } | |
133 } | |
134 | |
122 void DataUseMeasurement::OnNetworkBytesReceived(const net::URLRequest& request, | 135 void DataUseMeasurement::OnNetworkBytesReceived(const net::URLRequest& request, |
123 int64_t bytes_received) { | 136 int64_t bytes_received) { |
124 UMA_HISTOGRAM_COUNTS("DataUse.BytesReceived.Delegate", bytes_received); | 137 UMA_HISTOGRAM_COUNTS("DataUse.BytesReceived.Delegate", bytes_received); |
125 ReportDataUseUMA(request, DOWNSTREAM, bytes_received); | 138 ReportDataUseUMA(request, DOWNSTREAM, bytes_received); |
126 #if defined(OS_ANDROID) | 139 #if defined(OS_ANDROID) |
127 bytes_transferred_since_last_traffic_stats_query_ += bytes_received; | 140 bytes_transferred_since_last_traffic_stats_query_ += bytes_received; |
128 #endif | 141 #endif |
129 } | 142 } |
130 | 143 |
131 void DataUseMeasurement::OnNetworkBytesSent(const net::URLRequest& request, | 144 void DataUseMeasurement::OnNetworkBytesSent(const net::URLRequest& request, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 if (no_reads_since_background_) { | 202 if (no_reads_since_background_) { |
190 no_reads_since_background_ = false; | 203 no_reads_since_background_ = false; |
191 IncrementLatencyHistogramByCount( | 204 IncrementLatencyHistogramByCount( |
192 is_user_traffic ? "DataUse.BackgroundToFirstDownstream.User" | 205 is_user_traffic ? "DataUse.BackgroundToFirstDownstream.User" |
193 : "DataUse.BackgroundToFirstDownstream.System", | 206 : "DataUse.BackgroundToFirstDownstream.System", |
194 time_since_background, 1); | 207 time_since_background, 1); |
195 } | 208 } |
196 } | 209 } |
197 #endif | 210 #endif |
198 | 211 |
212 bool is_tab_visible = false; | |
213 | |
199 if (is_user_traffic) { | 214 if (is_user_traffic) { |
200 const DataUseRecorder* recorder = ascriber_->GetDataUseRecorder(request); | 215 const DataUseRecorder* recorder = ascriber_->GetDataUseRecorder(request); |
201 if (recorder) { | 216 if (recorder) { |
217 is_tab_visible = recorder->is_visible(); | |
202 RecordTabStateHistogram(dir, new_app_state, recorder->is_visible(), | 218 RecordTabStateHistogram(dir, new_app_state, recorder->is_visible(), |
203 bytes); | 219 bytes); |
204 } | 220 } |
205 } | 221 } |
222 if (attached_service_data && dir == DOWNSTREAM && | |
223 new_app_state != DataUseUserData::UNKNOWN) { | |
224 RecordContentTypeHistogram(attached_service_data->content_type(), | |
225 is_user_traffic, new_app_state, is_tab_visible, | |
226 bytes); | |
227 } | |
206 } | 228 } |
207 | 229 |
208 void DataUseMeasurement::UpdateDataUsePrefs( | 230 void DataUseMeasurement::UpdateDataUsePrefs( |
209 const net::URLRequest& request) const { | 231 const net::URLRequest& request) const { |
210 bool is_connection_cellular = | 232 bool is_connection_cellular = |
211 net::NetworkChangeNotifier::IsConnectionCellular( | 233 net::NetworkChangeNotifier::IsConnectionCellular( |
212 net::NetworkChangeNotifier::GetConnectionType()); | 234 net::NetworkChangeNotifier::GetConnectionType()); |
213 | 235 |
214 DataUseUserData* attached_service_data = static_cast<DataUseUserData*>( | 236 DataUseUserData* attached_service_data = static_cast<DataUseUserData*>( |
215 request.GetUserData(DataUseUserData::kUserDataKey)); | 237 request.GetUserData(DataUseUserData::kUserDataKey)); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 if (app_state == DataUseUserData::BACKGROUND) { | 378 if (app_state == DataUseUserData::BACKGROUND) { |
357 histogram_name.append("AppBackground"); | 379 histogram_name.append("AppBackground"); |
358 } else if (is_tab_visible) { | 380 } else if (is_tab_visible) { |
359 histogram_name.append("AppForeground.TabForeground"); | 381 histogram_name.append("AppForeground.TabForeground"); |
360 } else { | 382 } else { |
361 histogram_name.append("AppForeground.TabBackground"); | 383 histogram_name.append("AppForeground.TabBackground"); |
362 } | 384 } |
363 RecordUMAHistogramCount(histogram_name, bytes); | 385 RecordUMAHistogramCount(histogram_name, bytes); |
364 } | 386 } |
365 | 387 |
388 void DataUseMeasurement::RecordContentTypeHistogram( | |
389 DataUseUserData::DataUseContentType content_type, | |
390 bool is_user_traffic, | |
391 DataUseUserData::AppState app_state, | |
392 bool is_tab_visible, | |
393 int64_t bytes) { | |
394 if (content_type == DataUseUserData::AUDIO) { | |
395 content_type = app_state != DataUseUserData::FOREGROUND | |
396 ? DataUseUserData::AUDIO_APPBACKGROUND | |
397 : (!is_tab_visible ? DataUseUserData::AUDIO_TABBACKGROUND | |
398 : DataUseUserData::AUDIO); | |
399 } else if (content_type == DataUseUserData::VIDEO) { | |
400 content_type = app_state != DataUseUserData::FOREGROUND | |
401 ? DataUseUserData::VIDEO_APPBACKGROUND | |
402 : (!is_tab_visible ? DataUseUserData::VIDEO_TABBACKGROUND | |
403 : DataUseUserData::VIDEO); | |
404 } | |
405 if (is_user_traffic) { | |
406 STATIC_HISTOGRAM_POINTER_BLOCK( | |
Mark P
2016/12/22 21:40:29
Please use the standard UMA macro UMA_HISTOGRAM_EN
Raj
2016/12/22 23:14:37
Added comments. UMA_HISTOGRAM_ENUMERATION cannot b
| |
407 "DataUse.ContentType.UserTraffic", AddCount(content_type, bytes), | |
408 base::LinearHistogram::FactoryGet( | |
409 "DataUse.ContentType.UserTraffic", 1, DataUseUserData::TYPE_MAX, | |
410 DataUseUserData::TYPE_MAX + 1, | |
411 base::HistogramBase::kUmaTargetedHistogramFlag)); | |
412 } else { | |
413 STATIC_HISTOGRAM_POINTER_BLOCK( | |
414 "DataUse.ContentType.Services", AddCount(content_type, bytes), | |
415 base::LinearHistogram::FactoryGet( | |
416 "DataUse.ContentType.Services", 1, DataUseUserData::TYPE_MAX, | |
417 DataUseUserData::TYPE_MAX + 1, | |
418 base::HistogramBase::kUmaTargetedHistogramFlag)); | |
419 } | |
420 } | |
421 | |
366 } // namespace data_use_measurement | 422 } // namespace data_use_measurement |
OLD | NEW |