Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: components/data_use_measurement/core/data_use_measurement.cc

Issue 2595503002: Record the data use by content type (Closed)
Patch Set: Removed loadflags Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 112 }
113 113
114 void DataUseMeasurement::OnBeforeRedirect(const net::URLRequest& request, 114 void DataUseMeasurement::OnBeforeRedirect(const net::URLRequest& request,
115 const GURL& new_location) { 115 const GURL& new_location) {
116 // Recording data use of request on redirects. 116 // Recording data use of request on redirects.
117 // TODO(rajendrant): May not be needed when http://crbug/651957 is fixed. 117 // TODO(rajendrant): May not be needed when http://crbug/651957 is fixed.
118 UpdateDataUsePrefs(request); 118 UpdateDataUsePrefs(request);
119 ReportServicesMessageSizeUMA(request); 119 ReportServicesMessageSizeUMA(request);
120 } 120 }
121 121
122 void DataUseMeasurement::OnHeadersReceived(
123 net::URLRequest* request,
124 const net::HttpResponseHeaders* response_headers) {
125 DataUseUserData* data_use_user_data = reinterpret_cast<DataUseUserData*>(
126 request->GetUserData(DataUseUserData::kUserDataKey));
127 if (data_use_user_data) {
128 data_use_user_data->set_content_type(
129 url_request_classifier_->GetContentType(*request, *response_headers));
130 }
131 }
132
122 void DataUseMeasurement::OnNetworkBytesReceived(const net::URLRequest& request, 133 void DataUseMeasurement::OnNetworkBytesReceived(const net::URLRequest& request,
123 int64_t bytes_received) { 134 int64_t bytes_received) {
124 UMA_HISTOGRAM_COUNTS("DataUse.BytesReceived.Delegate", bytes_received); 135 UMA_HISTOGRAM_COUNTS("DataUse.BytesReceived.Delegate", bytes_received);
125 ReportDataUseUMA(request, DOWNSTREAM, bytes_received); 136 ReportDataUseUMA(request, DOWNSTREAM, bytes_received);
126 #if defined(OS_ANDROID) 137 #if defined(OS_ANDROID)
127 bytes_transferred_since_last_traffic_stats_query_ += bytes_received; 138 bytes_transferred_since_last_traffic_stats_query_ += bytes_received;
128 #endif 139 #endif
129 } 140 }
130 141
131 void DataUseMeasurement::OnNetworkBytesSent(const net::URLRequest& request, 142 void DataUseMeasurement::OnNetworkBytesSent(const net::URLRequest& request,
(...skipping 29 matching lines...) Expand all
161 DataUseUserData::AppState old_app_state = DataUseUserData::FOREGROUND; 172 DataUseUserData::AppState old_app_state = DataUseUserData::FOREGROUND;
162 DataUseUserData::AppState new_app_state = DataUseUserData::UNKNOWN; 173 DataUseUserData::AppState new_app_state = DataUseUserData::UNKNOWN;
163 174
164 if (attached_service_data) 175 if (attached_service_data)
165 old_app_state = attached_service_data->app_state(); 176 old_app_state = attached_service_data->app_state();
166 177
167 if (old_app_state == CurrentAppState()) 178 if (old_app_state == CurrentAppState())
168 new_app_state = old_app_state; 179 new_app_state = old_app_state;
169 180
170 if (attached_service_data && old_app_state != new_app_state) 181 if (attached_service_data && old_app_state != new_app_state)
171 attached_service_data->set_app_state(CurrentAppState()); 182 attached_service_data->set_app_state(CurrentAppState());
RyanSturm 2016/12/22 20:00:42 Maybe this should be called in OnBeforeURLRequest
Raj 2016/12/22 21:28:04 Done.
172 183
173 RecordUMAHistogramCount( 184 RecordUMAHistogramCount(
174 GetHistogramName(is_user_traffic ? "DataUse.TrafficSize.User" 185 GetHistogramName(is_user_traffic ? "DataUse.TrafficSize.User"
175 : "DataUse.TrafficSize.System", 186 : "DataUse.TrafficSize.System",
176 dir, new_app_state, is_connection_cellular), 187 dir, new_app_state, is_connection_cellular),
177 bytes); 188 bytes);
178 189
179 #if defined(OS_ANDROID) 190 #if defined(OS_ANDROID)
180 if (dir == DOWNSTREAM && CurrentAppState() == DataUseUserData::BACKGROUND) { 191 if (dir == DOWNSTREAM && CurrentAppState() == DataUseUserData::BACKGROUND) {
181 DCHECK(!last_app_background_time_.is_null()); 192 DCHECK(!last_app_background_time_.is_null());
182 193
183 const base::TimeDelta time_since_background = 194 const base::TimeDelta time_since_background =
184 base::TimeTicks::Now() - last_app_background_time_; 195 base::TimeTicks::Now() - last_app_background_time_;
185 IncrementLatencyHistogramByCount( 196 IncrementLatencyHistogramByCount(
186 is_user_traffic ? "DataUse.BackgroundToDataRecievedPerByte.User" 197 is_user_traffic ? "DataUse.BackgroundToDataRecievedPerByte.User"
187 : "DataUse.BackgroundToDataRecievedPerByte.System", 198 : "DataUse.BackgroundToDataRecievedPerByte.System",
188 time_since_background, bytes); 199 time_since_background, bytes);
189 if (no_reads_since_background_) { 200 if (no_reads_since_background_) {
190 no_reads_since_background_ = false; 201 no_reads_since_background_ = false;
191 IncrementLatencyHistogramByCount( 202 IncrementLatencyHistogramByCount(
192 is_user_traffic ? "DataUse.BackgroundToFirstDownstream.User" 203 is_user_traffic ? "DataUse.BackgroundToFirstDownstream.User"
193 : "DataUse.BackgroundToFirstDownstream.System", 204 : "DataUse.BackgroundToFirstDownstream.System",
194 time_since_background, 1); 205 time_since_background, 1);
195 } 206 }
196 } 207 }
197 #endif 208 #endif
198 209
210 bool is_tab_visible = false;
211
199 if (is_user_traffic) { 212 if (is_user_traffic) {
200 const DataUseRecorder* recorder = ascriber_->GetDataUseRecorder(request); 213 const DataUseRecorder* recorder = ascriber_->GetDataUseRecorder(request);
201 if (recorder) { 214 if (recorder) {
215 is_tab_visible = recorder->is_visible();
202 RecordTabStateHistogram(dir, new_app_state, recorder->is_visible(), 216 RecordTabStateHistogram(dir, new_app_state, recorder->is_visible(),
203 bytes); 217 bytes);
204 } 218 }
205 } 219 }
220 if (attached_service_data && dir == DOWNSTREAM &&
221 new_app_state != DataUseUserData::UNKNOWN) {
222 RecordContentTypeHistogram(attached_service_data->content_type(),
223 is_user_traffic, new_app_state, is_tab_visible,
224 bytes);
225 }
206 } 226 }
207 227
208 void DataUseMeasurement::UpdateDataUsePrefs( 228 void DataUseMeasurement::UpdateDataUsePrefs(
209 const net::URLRequest& request) const { 229 const net::URLRequest& request) const {
210 bool is_connection_cellular = 230 bool is_connection_cellular =
211 net::NetworkChangeNotifier::IsConnectionCellular( 231 net::NetworkChangeNotifier::IsConnectionCellular(
212 net::NetworkChangeNotifier::GetConnectionType()); 232 net::NetworkChangeNotifier::GetConnectionType());
213 233
214 DataUseUserData* attached_service_data = static_cast<DataUseUserData*>( 234 DataUseUserData* attached_service_data = static_cast<DataUseUserData*>(
215 request.GetUserData(DataUseUserData::kUserDataKey)); 235 request.GetUserData(DataUseUserData::kUserDataKey));
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 if (app_state == DataUseUserData::BACKGROUND) { 376 if (app_state == DataUseUserData::BACKGROUND) {
357 histogram_name.append("AppBackground"); 377 histogram_name.append("AppBackground");
358 } else if (is_tab_visible) { 378 } else if (is_tab_visible) {
359 histogram_name.append("AppForeground.TabForeground"); 379 histogram_name.append("AppForeground.TabForeground");
360 } else { 380 } else {
361 histogram_name.append("AppForeground.TabBackground"); 381 histogram_name.append("AppForeground.TabBackground");
362 } 382 }
363 RecordUMAHistogramCount(histogram_name, bytes); 383 RecordUMAHistogramCount(histogram_name, bytes);
364 } 384 }
365 385
386 void DataUseMeasurement::RecordContentTypeHistogram(
387 DataUseUserData::DataUseContentType content_type,
388 bool is_user_traffic,
389 DataUseUserData::AppState app_state,
390 bool is_tab_visible,
391 int64_t bytes) {
392 if (content_type == DataUseUserData::AUDIO) {
393 content_type = app_state != DataUseUserData::FOREGROUND
394 ? DataUseUserData::AUDIO_APPBACKGROUND
395 : (!is_tab_visible ? DataUseUserData::AUDIO_TABBACKGROUND
396 : DataUseUserData::AUDIO);
397 } else if (content_type == DataUseUserData::VIDEO) {
398 content_type = app_state != DataUseUserData::FOREGROUND
399 ? DataUseUserData::VIDEO_APPBACKGROUND
400 : (!is_tab_visible ? DataUseUserData::VIDEO_TABBACKGROUND
401 : DataUseUserData::VIDEO);
402 }
403 if (is_user_traffic) {
404 STATIC_HISTOGRAM_POINTER_BLOCK(
405 "DataUse.ContentType.UserTraffic", AddCount(content_type, bytes),
406 base::LinearHistogram::FactoryGet(
407 "DataUse.ContentType.UserTraffic", 1, DataUseUserData::TYPE_MAX,
408 DataUseUserData::TYPE_MAX + 1,
409 base::HistogramBase::kUmaTargetedHistogramFlag));
410 } else {
411 STATIC_HISTOGRAM_POINTER_BLOCK(
412 "DataUse.ContentType.Services", AddCount(content_type, bytes),
413 base::LinearHistogram::FactoryGet(
414 "DataUse.ContentType.Services", 1, DataUseUserData::TYPE_MAX,
415 DataUseUserData::TYPE_MAX + 1,
416 base::HistogramBase::kUmaTargetedHistogramFlag));
417 }
418 }
419
366 } // namespace data_use_measurement 420 } // namespace data_use_measurement
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698