Chromium Code Reviews| 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..510b2f72ee3b9fc8b24d3c06e336a5268e99f02e 100644 |
| --- a/components/data_use_measurement/core/data_use_measurement.cc |
| +++ b/components/data_use_measurement/core/data_use_measurement.cc |
| @@ -64,6 +64,56 @@ void IncrementLatencyHistogramByCount(const std::string& name, |
| } |
| #endif |
| +// Data use broken by content type. This enum must remain synchronized |
| +// with the enum of the same name in metrics/histograms/histograms.xml. |
| +enum DataUseContenType { |
|
RyanSturm
2016/12/20 19:37:52
nit: This seems duplicative. Maybe you could conso
Raj
2016/12/22 18:44:38
Done.
|
| + MAIN_FRAME_HTML = 0, |
| + NON_MAIN_FRAME_HTML, |
| + CSS, |
| + IMAGE, |
| + JAVASCRIPT, |
| + FONT, |
| + AUDIO_APPBACKGROUND, |
| + AUDIO_TABBACKGROUND, |
| + AUDIO_TABFOREGROUND, |
| + VIDEO_APPBACKGROUND, |
| + VIDEO_TABBACKGROUND, |
| + VIDEO_TABFOREGROUND, |
| + OTHER, |
| + TYPE_MAX, |
| +}; |
| + |
| +DataUseContenType GetDataUseContentType( |
| + DataUseUserData::ContentType content_type, |
| + bool is_app_foreground, |
| + bool is_tab_visible) { |
| + switch (content_type) { |
| + case DataUseUserData::ContentType::MAIN_FRAME_HTML: |
| + return MAIN_FRAME_HTML; |
| + case DataUseUserData::ContentType::NON_MAIN_FRAME_HTML: |
| + return NON_MAIN_FRAME_HTML; |
| + case DataUseUserData::ContentType::CSS: |
| + return CSS; |
| + case DataUseUserData::ContentType::IMAGE: |
| + return IMAGE; |
| + case DataUseUserData::ContentType::FONT: |
| + return FONT; |
| + case DataUseUserData::ContentType::AUDIO: |
| + return !is_app_foreground |
| + ? AUDIO_APPBACKGROUND |
| + : (is_tab_visible ? AUDIO_TABFOREGROUND : AUDIO_TABBACKGROUND); |
| + case DataUseUserData::ContentType::VIDEO: |
| + return !is_app_foreground |
| + ? VIDEO_APPBACKGROUND |
| + : (is_tab_visible ? VIDEO_TABFOREGROUND : VIDEO_TABBACKGROUND); |
| + case DataUseUserData::ContentType::OTHER: |
| + return OTHER; |
| + default: |
| + NOTREACHED(); |
| + } |
| + return OTHER; |
| +} |
| + |
| } // namespace |
| DataUseMeasurement::DataUseMeasurement( |
| @@ -119,6 +169,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 +257,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(), |
|
RyanSturm
2016/12/20 19:37:52
nit: I just noticed now that these are sort of str
Raj
2016/12/22 18:44:37
Yes. That case is handled as follows.
These UMA ar
RyanSturm
2016/12/22 20:00:42
Awesome. Sounds like good enough granularity (FG->
|
| + is_user_traffic, new_app_state, is_tab_visible, |
| + bytes); |
| + } |
| } |
| void DataUseMeasurement::UpdateDataUsePrefs( |
| @@ -363,4 +433,23 @@ void DataUseMeasurement::RecordTabStateHistogram( |
| RecordUMAHistogramCount(histogram_name, bytes); |
| } |
| +void DataUseMeasurement::RecordContentTypeHistogram( |
| + DataUseUserData::ContentType content_type, |
| + bool is_user_traffic, |
| + DataUseUserData::AppState app_state, |
| + bool is_tab_visible, |
| + int64_t bytes) { |
| + DataUseContenType data_use_content_type = GetDataUseContentType( |
| + content_type, app_state == DataUseUserData::FOREGROUND, is_tab_visible); |
| + if (is_user_traffic) { |
| + UMA_HISTOGRAM_ENUMERATION("DataUse.ContentType.UserTraffic", |
| + data_use_content_type, |
| + DataUseContenType::TYPE_MAX); |
| + } else { |
| + UMA_HISTOGRAM_ENUMERATION("DataUse.ContentType.Services", |
| + data_use_content_type, |
| + DataUseContenType::TYPE_MAX); |
| + } |
| +} |
| + |
| } // namespace data_use_measurement |