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

Side by Side Diff: chrome/browser/permissions/permission_uma_util.cc

Issue 1921533004: Add a low-frequency RAPPOR configuration, and use it for Safe Browsing and Permissions metrics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/permissions/permission_uma_util.h" 5 #include "chrome/browser/permissions/permission_uma_util.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 18 matching lines...) Expand all
29 PERMISSION_ACTION_NUM); \ 29 PERMISSION_ACTION_NUM); \
30 } else { \ 30 } else { \
31 UMA_HISTOGRAM_ENUMERATION(permission_insecure, action, \ 31 UMA_HISTOGRAM_ENUMERATION(permission_insecure, action, \
32 PERMISSION_ACTION_NUM); \ 32 PERMISSION_ACTION_NUM); \
33 } 33 }
34 34
35 using content::PermissionType; 35 using content::PermissionType;
36 36
37 namespace { 37 namespace {
38 38
39 // Deprecated. This method is used for the single-dimensional RAPPOR metrics
40 // that are being replaced by the multi-dimensional ones.
41 const std::string GetRapporMetric(PermissionType permission, 39 const std::string GetRapporMetric(PermissionType permission,
42 PermissionAction action) { 40 PermissionAction action) {
43 std::string action_str; 41 std::string action_str;
44 switch (action) { 42 switch (action) {
45 case GRANTED: 43 case GRANTED:
46 action_str = "Granted"; 44 action_str = "Granted";
47 break; 45 break;
48 case DENIED: 46 case DENIED:
49 action_str = "Denied"; 47 action_str = "Denied";
50 break; 48 break;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // The user is not prompted for these permissions, thus there is no 135 // The user is not prompted for these permissions, thus there is no
138 // permission action recorded for them. 136 // permission action recorded for them.
139 case PermissionType::MIDI: 137 case PermissionType::MIDI:
140 case PermissionType::BACKGROUND_SYNC: 138 case PermissionType::BACKGROUND_SYNC:
141 case PermissionType::NUM: 139 case PermissionType::NUM:
142 NOTREACHED() << "PERMISSION " 140 NOTREACHED() << "PERMISSION "
143 << PermissionUtil::GetPermissionString(permission) 141 << PermissionUtil::GetPermissionString(permission)
144 << " not accounted for"; 142 << " not accounted for";
145 } 143 }
146 144
147 // There are two sets of semi-redundant RAPPOR metrics being reported:
148 // The soon-to-be-deprecated single dimensional ones, and the new
149 // multi-dimensional ones.
150 rappor::RapporService* rappor_service = g_browser_process->rappor_service();
151 const std::string rappor_metric = GetRapporMetric(permission, action); 145 const std::string rappor_metric = GetRapporMetric(permission, action);
152 if (!rappor_metric.empty()) 146 if (!rappor_metric.empty()) {
153 rappor::SampleDomainAndRegistryFromGURL( 147 // TODO(dominickn): remove this deprecated metric - crbug.com/605836.
154 rappor_service, rappor_metric, requesting_origin); 148 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
149 rappor_metric, requesting_origin);
155 150
156 // Add multi-dimensional RAPPOR reporting for safe-browsing users. 151 std::string new_rappor_metric =
157 std::string permission_str = 152 base::StringPrintf("%s2", rappor_metric.c_str());
158 PermissionUtil::GetPermissionString(permission); 153 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
159 if (!rappor_service || permission_str.empty()) 154 new_rappor_metric,
160 return; 155 requesting_origin);
161 156 }
162 std::unique_ptr<rappor::Sample> sample =
163 rappor_service->CreateSample(rappor::SAFEBROWSING_RAPPOR_TYPE);
164 sample->SetStringField("Scheme", requesting_origin.scheme());
165 sample->SetStringField("Host", requesting_origin.host());
166 sample->SetStringField("Port", requesting_origin.port());
167 sample->SetStringField("Domain",
168 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin));
169 sample->SetFlagsField("Actions", static_cast<uint64_t>(1) << action,
170 PermissionAction::PERMISSION_ACTION_NUM);
171 rappor_service->RecordSampleObj("Permissions.Action." + permission_str,
172 std::move(sample));
173 } 157 }
174 158
175 void RecordPermissionRequest(PermissionType permission, 159 void RecordPermissionRequest(PermissionType permission,
176 const GURL& requesting_origin, 160 const GURL& requesting_origin,
177 const GURL& embedding_origin, 161 const GURL& embedding_origin,
178 Profile* profile) { 162 Profile* profile) {
179 bool secure_origin = content::IsOriginSecure(requesting_origin); 163 bool secure_origin = content::IsOriginSecure(requesting_origin);
180 if (permission == PermissionType::GEOLOCATION) { 164 if (permission == PermissionType::GEOLOCATION) {
165 // TODO(dominickn): remove this deprecated metric - crbug.com/605836.
181 rappor::SampleDomainAndRegistryFromGURL( 166 rappor::SampleDomainAndRegistryFromGURL(
182 g_browser_process->rappor_service(), 167 g_browser_process->rappor_service(),
183 "ContentSettings.PermissionRequested.Geolocation.Url", 168 "ContentSettings.PermissionRequested.Geolocation.Url",
184 requesting_origin); 169 requesting_origin);
170 rappor::SampleDomainAndRegistryFromGURL(
171 g_browser_process->rappor_service(),
172 "ContentSettings.PermissionRequested.Geolocation.Url2",
173 requesting_origin);
185 } else if (permission == PermissionType::NOTIFICATIONS) { 174 } else if (permission == PermissionType::NOTIFICATIONS) {
175 // TODO(dominickn): remove this deprecated metric - crbug.com/605836.
186 rappor::SampleDomainAndRegistryFromGURL( 176 rappor::SampleDomainAndRegistryFromGURL(
187 g_browser_process->rappor_service(), 177 g_browser_process->rappor_service(),
188 "ContentSettings.PermissionRequested.Notifications.Url", 178 "ContentSettings.PermissionRequested.Notifications.Url",
189 requesting_origin); 179 requesting_origin);
180 rappor::SampleDomainAndRegistryFromGURL(
181 g_browser_process->rappor_service(),
182 "ContentSettings.PermissionRequested.Notifications.Url2",
183 requesting_origin);
190 } 184 }
191 UMA_HISTOGRAM_ENUMERATION( 185 UMA_HISTOGRAM_ENUMERATION(
192 "ContentSettings.PermissionRequested", 186 "ContentSettings.PermissionRequested",
193 static_cast<base::HistogramBase::Sample>(permission), 187 static_cast<base::HistogramBase::Sample>(permission),
194 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); 188 static_cast<base::HistogramBase::Sample>(PermissionType::NUM));
195 if (secure_origin) { 189 if (secure_origin) {
196 UMA_HISTOGRAM_ENUMERATION( 190 UMA_HISTOGRAM_ENUMERATION(
197 "ContentSettings.PermissionRequested_SecureOrigin", 191 "ContentSettings.PermissionRequested_SecureOrigin",
198 static_cast<base::HistogramBase::Sample>(permission), 192 static_cast<base::HistogramBase::Sample>(permission),
199 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); 193 static_cast<base::HistogramBase::Sample>(PermissionType::NUM));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 const std::vector<PermissionBubbleRequest*>& requests) { 274 const std::vector<PermissionBubbleRequest*>& requests) {
281 DCHECK(!requests.empty()); 275 DCHECK(!requests.empty());
282 PermissionBubbleType permission_prompt_type = PermissionBubbleType::MULTIPLE; 276 PermissionBubbleType permission_prompt_type = PermissionBubbleType::MULTIPLE;
283 if (requests.size() == 1) 277 if (requests.size() == 1)
284 permission_prompt_type = requests[0]->GetPermissionBubbleType(); 278 permission_prompt_type = requests[0]->GetPermissionBubbleType();
285 UMA_HISTOGRAM_ENUMERATION( 279 UMA_HISTOGRAM_ENUMERATION(
286 "Permissions.Prompt.Shown", 280 "Permissions.Prompt.Shown",
287 static_cast<base::HistogramBase::Sample>(permission_prompt_type), 281 static_cast<base::HistogramBase::Sample>(permission_prompt_type),
288 static_cast<base::HistogramBase::Sample>(PermissionBubbleType::NUM)); 282 static_cast<base::HistogramBase::Sample>(PermissionBubbleType::NUM));
289 } 283 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698