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

Unified Diff: components/data_use_measurement/core/data_use_measurement.cc

Issue 2595503002: Record the data use by content type (Closed)
Patch Set: fixed nits Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: components/data_use_measurement/core/data_use_measurement.cc
diff --git a/components/data_use_measurement/core/data_use_measurement.cc b/components/data_use_measurement/core/data_use_measurement.cc
index 6508f99ade7c1e38116388d23aa7e36c89949ba4..4408bc3625acba7330e0930721debf4139472207 100644
--- a/components/data_use_measurement/core/data_use_measurement.cc
+++ b/components/data_use_measurement/core/data_use_measurement.cc
@@ -103,11 +103,13 @@ void DataUseMeasurement::OnBeforeURLRequest(net::URLRequest* request) {
// Detect if the request originated from DomainReliability.
// DataUseUserData::AttachToFetcher() cannot be called from domain
// reliability, since it sets userdata on URLFetcher for its purposes.
- service_name = DataUseUserData::ServiceName::NOT_TAGGED;
+ service_name = DataUseUserData::ServiceName::DOMAIN_RELIABILITY;
}
data_use_user_data = new DataUseUserData(service_name, CurrentAppState());
request->SetUserData(DataUseUserData::kUserDataKey, data_use_user_data);
+ } else {
+ data_use_user_data->set_app_state(CurrentAppState());
}
}
@@ -119,6 +121,17 @@ void DataUseMeasurement::OnBeforeRedirect(const net::URLRequest& request,
ReportServicesMessageSizeUMA(request);
}
+void DataUseMeasurement::OnHeadersReceived(
+ net::URLRequest* request,
+ const net::HttpResponseHeaders* response_headers) {
+ DataUseUserData* data_use_user_data = reinterpret_cast<DataUseUserData*>(
+ request->GetUserData(DataUseUserData::kUserDataKey));
+ if (data_use_user_data) {
+ data_use_user_data->set_content_type(
+ url_request_classifier_->GetContentType(*request, *response_headers));
+ }
+}
+
void DataUseMeasurement::OnNetworkBytesReceived(const net::URLRequest& request,
int64_t bytes_received) {
UMA_HISTOGRAM_COUNTS("DataUse.BytesReceived.Delegate", bytes_received);
@@ -196,13 +209,22 @@ void DataUseMeasurement::ReportDataUseUMA(const net::URLRequest& request,
}
#endif
+ bool is_tab_visible = false;
+
if (is_user_traffic) {
const DataUseRecorder* recorder = ascriber_->GetDataUseRecorder(request);
if (recorder) {
+ is_tab_visible = recorder->is_visible();
RecordTabStateHistogram(dir, new_app_state, recorder->is_visible(),
bytes);
}
}
+ if (attached_service_data && dir == DOWNSTREAM &&
+ new_app_state != DataUseUserData::UNKNOWN) {
+ RecordContentTypeHistogram(attached_service_data->content_type(),
+ is_user_traffic, new_app_state, is_tab_visible,
+ bytes);
+ }
}
void DataUseMeasurement::UpdateDataUsePrefs(
@@ -363,4 +385,40 @@ void DataUseMeasurement::RecordTabStateHistogram(
RecordUMAHistogramCount(histogram_name, bytes);
}
+void DataUseMeasurement::RecordContentTypeHistogram(
+ DataUseUserData::DataUseContentType content_type,
+ bool is_user_traffic,
+ DataUseUserData::AppState app_state,
+ bool is_tab_visible,
+ int64_t bytes) {
+ if (content_type == DataUseUserData::AUDIO) {
+ content_type = app_state != DataUseUserData::FOREGROUND
+ ? DataUseUserData::AUDIO_APPBACKGROUND
+ : (!is_tab_visible ? DataUseUserData::AUDIO_TABBACKGROUND
+ : DataUseUserData::AUDIO);
+ } else if (content_type == DataUseUserData::VIDEO) {
+ content_type = app_state != DataUseUserData::FOREGROUND
+ ? DataUseUserData::VIDEO_APPBACKGROUND
+ : (!is_tab_visible ? DataUseUserData::VIDEO_TABBACKGROUND
+ : DataUseUserData::VIDEO);
+ }
+ // Use the more primitive STATIC_HISTOGRAM_POINTER_BLOCK macro because the
+ // simple UMA_HISTOGRAM_ENUMERATION macros don't expose 'AddCount'.
+ if (is_user_traffic) {
+ STATIC_HISTOGRAM_POINTER_BLOCK(
+ "DataUse.ContentType.UserTraffic", AddCount(content_type, bytes),
+ base::LinearHistogram::FactoryGet(
+ "DataUse.ContentType.UserTraffic", 1, DataUseUserData::TYPE_MAX,
+ DataUseUserData::TYPE_MAX + 1,
+ base::HistogramBase::kUmaTargetedHistogramFlag));
+ } else {
+ STATIC_HISTOGRAM_POINTER_BLOCK(
+ "DataUse.ContentType.Services", AddCount(content_type, bytes),
+ base::LinearHistogram::FactoryGet(
+ "DataUse.ContentType.Services", 1, DataUseUserData::TYPE_MAX,
+ DataUseUserData::TYPE_MAX + 1,
+ base::HistogramBase::kUmaTargetedHistogramFlag));
+ }
+}
+
} // namespace data_use_measurement

Powered by Google App Engine
This is Rietveld 408576698