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

Side by Side Diff: components/data_use_measurement/content/content_url_request_classifier.cc

Issue 2614203002: Record data use of user traffic by different core page transition types (Closed)
Patch Set: rebased Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/content/content_url_request_classifier .h" 5 #include "components/data_use_measurement/content/content_url_request_classifier .h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/metrics/histogram_macros.h"
10 #include "base/metrics/sparse_histogram.h"
9 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
10 #include "content/public/browser/resource_request_info.h" 12 #include "content/public/browser/resource_request_info.h"
11 #include "content/public/common/resource_type.h" 13 #include "content/public/common/resource_type.h"
12 #include "net/http/http_response_headers.h" 14 #include "net/http/http_response_headers.h"
13 #include "net/url_request/url_request.h" 15 #include "net/url_request/url_request.h"
16 #include "ui/base/page_transition_types.h"
17
18 namespace {
19
20 // Data use broken by page transition type. This enum must remain synchronized
21 // with the enum of the same name in metrics/histograms/histograms.xml. The enum
22 // values have the same meaning as ui::PageTransition in
23 // ui/base/page_transition_types.h. These values are written to logs. New enum
24 // values can be added, but existing enums must never be renumbered or deleted
25 // and reused.
26 enum DataUsePageTransition {
27 LINK = 0,
28 TYPED = 1,
29 AUTO_BOOKMARK = 2,
30 SUBFRAME = 3, // AUTO_SUBFRAME and MANUAL_SUBFRAME transitions.
31 GENERATED = 4,
32 AUTO_TOPLEVEL = 5,
33 FORM_SUBMIT = 6,
34 RELOAD = 7,
35 KEYWORD = 8, // KEYWORD and KEYWORD_GENERATED transitions.
36 FORWARD_BACK = 9,
37 HOME_PAGE = 10,
38 TRANSITION_MAX = 11,
39 };
40
41 } // namespace
14 42
15 namespace data_use_measurement { 43 namespace data_use_measurement {
16 44
17 bool IsUserRequest(const net::URLRequest& request) { 45 bool IsUserRequest(const net::URLRequest& request) {
18 // The presence of ResourecRequestInfo in |request| implies that this request 46 // The presence of ResourecRequestInfo in |request| implies that this request
19 // was created for a content::WebContents. For now we could add a condition to 47 // was created for a content::WebContents. For now we could add a condition to
20 // check ProcessType in info is content::PROCESS_TYPE_RENDERER, but it won't 48 // check ProcessType in info is content::PROCESS_TYPE_RENDERER, but it won't
21 // be compatible with upcoming PlzNavigate architecture. So just existence of 49 // be compatible with upcoming PlzNavigate architecture. So just existence of
22 // ResourceRequestInfo is verified, and the current check should be compatible 50 // ResourceRequestInfo is verified, and the current check should be compatible
23 // with upcoming changes in PlzNavigate. 51 // with upcoming changes in PlzNavigate.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 base::CompareCase::SENSITIVE)) { 88 base::CompareCase::SENSITIVE)) {
61 return DataUseUserData::AUDIO; 89 return DataUseUserData::AUDIO;
62 } else if (base::StartsWith(mime_type, "video/", 90 } else if (base::StartsWith(mime_type, "video/",
63 base::CompareCase::SENSITIVE)) { 91 base::CompareCase::SENSITIVE)) {
64 return DataUseUserData::VIDEO; 92 return DataUseUserData::VIDEO;
65 } 93 }
66 } 94 }
67 return DataUseUserData::OTHER; 95 return DataUseUserData::OTHER;
68 } 96 }
69 97
98 void ContentURLRequestClassifier::RecordPageTransitionUMA(
99 uint64_t page_transition,
100 int64_t received_bytes) const {
101 DataUsePageTransition data_use_page_transition =
102 DataUsePageTransition::TRANSITION_MAX;
103 if (received_bytes <= 0)
104 return;
105
106 if (page_transition & ui::PAGE_TRANSITION_FORWARD_BACK) {
107 data_use_page_transition = DataUsePageTransition::FORWARD_BACK;
108 } else if (page_transition & ui::PAGE_TRANSITION_HOME_PAGE) {
109 data_use_page_transition = DataUsePageTransition::HOME_PAGE;
110 } else {
111 switch (page_transition & ui::PAGE_TRANSITION_CORE_MASK) {
112 case ui::PAGE_TRANSITION_LINK:
113 data_use_page_transition = DataUsePageTransition::LINK;
114 break;
115 case ui::PAGE_TRANSITION_TYPED:
116 data_use_page_transition = DataUsePageTransition::TYPED;
117 break;
118 case ui::PAGE_TRANSITION_AUTO_BOOKMARK:
119 data_use_page_transition = DataUsePageTransition::AUTO_BOOKMARK;
120 break;
121 case ui::PAGE_TRANSITION_AUTO_SUBFRAME:
122 case ui::PAGE_TRANSITION_MANUAL_SUBFRAME:
123 data_use_page_transition = DataUsePageTransition::SUBFRAME;
124 break;
125 case ui::PAGE_TRANSITION_GENERATED:
126 data_use_page_transition = DataUsePageTransition::GENERATED;
127 break;
128 case ui::PAGE_TRANSITION_AUTO_TOPLEVEL:
129 data_use_page_transition = DataUsePageTransition::AUTO_TOPLEVEL;
130 break;
131 case ui::PAGE_TRANSITION_FORM_SUBMIT:
132 data_use_page_transition = DataUsePageTransition::FORM_SUBMIT;
133 break;
134 case ui::PAGE_TRANSITION_RELOAD:
135 data_use_page_transition = DataUsePageTransition::RELOAD;
136 break;
137 case ui::PAGE_TRANSITION_KEYWORD:
138 case ui::PAGE_TRANSITION_KEYWORD_GENERATED:
139 data_use_page_transition = DataUsePageTransition::KEYWORD;
140 break;
141 default:
142 return;
143 }
144 }
145 DCHECK_NE(DataUsePageTransition::TRANSITION_MAX, data_use_page_transition);
146
147 // Use the more primitive STATIC_HISTOGRAM_POINTER_BLOCK macro because the
148 // simple UMA_HISTOGRAM_ENUMERATION macros don't expose 'AddCount'.
149 STATIC_HISTOGRAM_POINTER_BLOCK(
150 "DataUse.PageTransition.UserTraffic",
151 AddCount(data_use_page_transition, received_bytes),
152 base::LinearHistogram::FactoryGet(
153 "DataUse.PageTransition.UserTraffic", 1,
154 DataUsePageTransition::TRANSITION_MAX,
155 DataUsePageTransition::TRANSITION_MAX + 1,
156 base::HistogramBase::kUmaTargetedHistogramFlag));
157 }
158
70 } // namespace data_use_measurement 159 } // namespace data_use_measurement
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698