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

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

Issue 2145373002: Revert of Add hooks to permission layer for permission action reporting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-reporter-implementation
Patch Set: Created 4 years, 5 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/command_line.h"
10 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
11 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
12 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/permissions/permission_manager.h" 12 #include "chrome/browser/permissions/permission_manager.h"
14 #include "chrome/browser/permissions/permission_util.h" 13 #include "chrome/browser/permissions/permission_util.h"
15 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
17 #include "chrome/browser/safe_browsing/ui_manager.h"
18 #include "chrome/browser/sync/profile_sync_service_factory.h"
19 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" 15 #include "chrome/browser/ui/website_settings/permission_bubble_request.h"
20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/pref_names.h"
22 #include "components/browser_sync/browser/profile_sync_service.h"
23 #include "components/prefs/pref_service.h"
24 #include "components/rappor/rappor_service.h" 16 #include "components/rappor/rappor_service.h"
25 #include "components/rappor/rappor_utils.h" 17 #include "components/rappor/rappor_utils.h"
26 #include "content/public/browser/permission_type.h" 18 #include "content/public/browser/permission_type.h"
27 #include "content/public/common/origin_util.h" 19 #include "content/public/common/origin_util.h"
28 #include "url/gurl.h" 20 #include "url/gurl.h"
29 21
30 // UMA keys need to be statically initialized so plain function would not 22 // UMA keys need to be statically initialized so plain function would not
31 // work. Use macros instead. 23 // work. Use macros instead.
32 #define PERMISSION_ACTION_UMA(secure_origin, permission, permission_secure, \ 24 #define PERMISSION_ACTION_UMA(secure_origin, permission, permission_secure, \
33 permission_insecure, action) \ 25 permission_insecure, action) \
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 67 }
76 68
77 std::string permission_str = 69 std::string permission_str =
78 PermissionUtil::GetPermissionString(permission); 70 PermissionUtil::GetPermissionString(permission);
79 if (permission_str.empty()) 71 if (permission_str.empty())
80 return ""; 72 return "";
81 return base::StringPrintf("ContentSettings.PermissionActions_%s.%s.Url", 73 return base::StringPrintf("ContentSettings.PermissionActions_%s.%s.Url",
82 permission_str.c_str(), action_str.c_str()); 74 permission_str.c_str(), action_str.c_str());
83 } 75 }
84 76
77 void RecordPermissionAction(PermissionType permission,
78 PermissionAction action,
79 const GURL& requesting_origin) {
80 bool secure_origin = content::IsOriginSecure(requesting_origin);
81
82 switch (permission) {
83 case PermissionType::GEOLOCATION:
84 PERMISSION_ACTION_UMA(
85 secure_origin,
86 "Permissions.Action.Geolocation",
87 "Permissions.Action.SecureOrigin.Geolocation",
88 "Permissions.Action.InsecureOrigin.Geolocation",
89 action);
90 break;
91 case PermissionType::NOTIFICATIONS:
92 PERMISSION_ACTION_UMA(
93 secure_origin,
94 "Permissions.Action.Notifications",
95 "Permissions.Action.SecureOrigin.Notifications",
96 "Permissions.Action.InsecureOrigin.Notifications",
97 action);
98 break;
99 case PermissionType::MIDI_SYSEX:
100 PERMISSION_ACTION_UMA(
101 secure_origin,
102 "Permissions.Action.MidiSysEx",
103 "Permissions.Action.SecureOrigin.MidiSysEx",
104 "Permissions.Action.InsecureOrigin.MidiSysEx",
105 action);
106 break;
107 case PermissionType::PUSH_MESSAGING:
108 PERMISSION_ACTION_UMA(
109 secure_origin,
110 "Permissions.Action.PushMessaging",
111 "Permissions.Action.SecureOrigin.PushMessaging",
112 "Permissions.Action.InsecureOrigin.PushMessaging",
113 action);
114 break;
115 case PermissionType::PROTECTED_MEDIA_IDENTIFIER:
116 PERMISSION_ACTION_UMA(
117 secure_origin,
118 "Permissions.Action.ProtectedMedia",
119 "Permissions.Action.SecureOrigin.ProtectedMedia",
120 "Permissions.Action.InsecureOrigin.ProtectedMedia",
121 action);
122 break;
123 case PermissionType::DURABLE_STORAGE:
124 PERMISSION_ACTION_UMA(
125 secure_origin,
126 "Permissions.Action.DurableStorage",
127 "Permissions.Action.SecureOrigin.DurableStorage",
128 "Permissions.Action.InsecureOrigin.DurableStorage",
129 action);
130 break;
131 case PermissionType::AUDIO_CAPTURE:
132 // Media permissions are disabled on insecure origins, so there's no
133 // need to record metrics for secure/insecue.
134 UMA_HISTOGRAM_ENUMERATION("Permissions.Action.AudioCapture", action,
135 PERMISSION_ACTION_NUM);
136 break;
137 case PermissionType::VIDEO_CAPTURE:
138 UMA_HISTOGRAM_ENUMERATION("Permissions.Action.VideoCapture", action,
139 PERMISSION_ACTION_NUM);
140 break;
141 // The user is not prompted for these permissions, thus there is no
142 // permission action recorded for them.
143 case PermissionType::MIDI:
144 case PermissionType::BACKGROUND_SYNC:
145 case PermissionType::NUM:
146 NOTREACHED() << "PERMISSION "
147 << PermissionUtil::GetPermissionString(permission)
148 << " not accounted for";
149 }
150
151 // Retrieve the name of the RAPPOR metric. Currently, the new metric name is
152 // the deprecated name with "2" on the end, e.g.
153 // ContentSettings.PermissionActions_Geolocation.Granted.Url2. For simplicity,
154 // we retrieve the deprecated name and append the "2" for the new name.
155 // TODO(dominickn): remove the deprecated metric and replace it solely with
156 // the new one in GetRapporMetric - crbug.com/605836.
157 const std::string deprecated_metric = GetRapporMetric(permission, action);
158 rappor::RapporService* rappor_service = g_browser_process->rappor_service();
159 if (!deprecated_metric.empty() && rappor_service) {
160 rappor::SampleDomainAndRegistryFromGURL(rappor_service, deprecated_metric,
161 requesting_origin);
162
163 std::string rappor_metric = deprecated_metric + "2";
164 rappor_service->RecordSample(
165 rappor_metric, rappor::LOW_FREQUENCY_ETLD_PLUS_ONE_RAPPOR_TYPE,
166 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin));
167 }
168 }
169
85 void RecordPermissionRequest(PermissionType permission, 170 void RecordPermissionRequest(PermissionType permission,
86 const GURL& requesting_origin, 171 const GURL& requesting_origin,
87 const GURL& embedding_origin, 172 const GURL& embedding_origin,
88 Profile* profile) { 173 Profile* profile) {
89 rappor::RapporService* rappor_service = g_browser_process->rappor_service(); 174 rappor::RapporService* rappor_service = g_browser_process->rappor_service();
90 if (rappor_service) { 175 if (rappor_service) {
91 if (permission == PermissionType::GEOLOCATION) { 176 if (permission == PermissionType::GEOLOCATION) {
92 // TODO(dominickn): remove this deprecated metric - crbug.com/605836. 177 // TODO(dominickn): remove this deprecated metric - crbug.com/605836.
93 rappor::SampleDomainAndRegistryFromGURL( 178 rappor::SampleDomainAndRegistryFromGURL(
94 rappor_service, 179 rappor_service,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // add new permission 273 // add new permission
189 void PermissionUmaUtil::PermissionRequested(PermissionType permission, 274 void PermissionUmaUtil::PermissionRequested(PermissionType permission,
190 const GURL& requesting_origin, 275 const GURL& requesting_origin,
191 const GURL& embedding_origin, 276 const GURL& embedding_origin,
192 Profile* profile) { 277 Profile* profile) {
193 RecordPermissionRequest(permission, requesting_origin, embedding_origin, 278 RecordPermissionRequest(permission, requesting_origin, embedding_origin,
194 profile); 279 profile);
195 } 280 }
196 281
197 void PermissionUmaUtil::PermissionGranted(PermissionType permission, 282 void PermissionUmaUtil::PermissionGranted(PermissionType permission,
198 const GURL& requesting_origin, 283 const GURL& requesting_origin) {
199 Profile* profile) { 284 RecordPermissionAction(permission, GRANTED, requesting_origin);
200 RecordPermissionAction(permission, GRANTED, requesting_origin, profile);
201 } 285 }
202 286
203 void PermissionUmaUtil::PermissionDenied(PermissionType permission, 287 void PermissionUmaUtil::PermissionDenied(PermissionType permission,
204 const GURL& requesting_origin, 288 const GURL& requesting_origin) {
205 Profile* profile) { 289 RecordPermissionAction(permission, DENIED, requesting_origin);
206 RecordPermissionAction(permission, DENIED, requesting_origin, profile);
207 } 290 }
208 291
209 void PermissionUmaUtil::PermissionDismissed(PermissionType permission, 292 void PermissionUmaUtil::PermissionDismissed(PermissionType permission,
210 const GURL& requesting_origin, 293 const GURL& requesting_origin) {
211 Profile* profile) { 294 RecordPermissionAction(permission, DISMISSED, requesting_origin);
212 RecordPermissionAction(permission, DISMISSED, requesting_origin, profile);
213 } 295 }
214 296
215 void PermissionUmaUtil::PermissionIgnored(PermissionType permission, 297 void PermissionUmaUtil::PermissionIgnored(PermissionType permission,
216 const GURL& requesting_origin, 298 const GURL& requesting_origin) {
217 Profile* profile) { 299 RecordPermissionAction(permission, IGNORED, requesting_origin);
218 RecordPermissionAction(permission, IGNORED, requesting_origin, profile);
219 } 300 }
220 301
221 void PermissionUmaUtil::PermissionRevoked(PermissionType permission, 302 void PermissionUmaUtil::PermissionRevoked(PermissionType permission,
222 const GURL& revoked_origin, 303 const GURL& revoked_origin) {
223 Profile* profile) {
224 // TODO(tsergeant): Expand metrics definitions for revocation to include all 304 // TODO(tsergeant): Expand metrics definitions for revocation to include all
225 // permissions. 305 // permissions.
226 if (permission == PermissionType::NOTIFICATIONS || 306 if (permission == PermissionType::NOTIFICATIONS ||
227 permission == PermissionType::GEOLOCATION || 307 permission == PermissionType::GEOLOCATION ||
228 permission == PermissionType::AUDIO_CAPTURE || 308 permission == PermissionType::AUDIO_CAPTURE ||
229 permission == PermissionType::VIDEO_CAPTURE) { 309 permission == PermissionType::VIDEO_CAPTURE) {
230 RecordPermissionAction(permission, REVOKED, revoked_origin, profile); 310 RecordPermissionAction(permission, REVOKED, revoked_origin);
231 } 311 }
232 } 312 }
233 313
234 void PermissionUmaUtil::PermissionPromptShown( 314 void PermissionUmaUtil::PermissionPromptShown(
235 const std::vector<PermissionBubbleRequest*>& requests) { 315 const std::vector<PermissionBubbleRequest*>& requests) {
236 DCHECK(!requests.empty()); 316 DCHECK(!requests.empty());
237 317
238 PermissionBubbleType permission_prompt_type = PermissionBubbleType::MULTIPLE; 318 PermissionBubbleType permission_prompt_type = PermissionBubbleType::MULTIPLE;
239 if (requests.size() == 1) 319 if (requests.size() == 1)
240 permission_prompt_type = requests[0]->GetPermissionBubbleType(); 320 permission_prompt_type = requests[0]->GetPermissionBubbleType();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 367 }
288 368
289 void PermissionUmaUtil::PermissionPromptDenied( 369 void PermissionUmaUtil::PermissionPromptDenied(
290 const std::vector<PermissionBubbleRequest*>& requests) { 370 const std::vector<PermissionBubbleRequest*>& requests) {
291 DCHECK(!requests.empty()); 371 DCHECK(!requests.empty());
292 DCHECK(requests.size() == 1); 372 DCHECK(requests.size() == 1);
293 373
294 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptDenied, 374 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptDenied,
295 requests[0]->GetPermissionBubbleType()); 375 requests[0]->GetPermissionBubbleType());
296 } 376 }
297
298 bool PermissionUmaUtil::IsOptedIntoPermissionActionReporting(Profile* profile) {
299 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
300 switches::kEnablePermissionActionReporting))
301 return false;
302 // TODO(stefanocs): Remove this check once all callsites have been updated
303 // to not pass a nullptr.
304 if (!profile)
305 return false;
306 if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE)
307 return false;
308 if (!profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled))
309 return false;
310
311 ProfileSyncService* profile_sync_service =
312 ProfileSyncServiceFactory::GetForProfile(profile);
313
314 // Do not report if profile can't get a profile sync service due to disable
315 // sync flag.
316 if (!profile_sync_service)
317 return false;
318
319 if (!profile_sync_service->CanSyncStart())
320 return false;
321
322 syncer::ModelTypeSet preferred_data_types =
323 profile_sync_service->GetPreferredDataTypes();
324 if (!preferred_data_types.Has(syncer::PROXY_TABS))
325 return false;
326 if (!preferred_data_types.Has(syncer::PRIORITY_PREFERENCES))
327 return false;
328
329 return true;
330 }
331
332 void PermissionUmaUtil::RecordPermissionAction(PermissionType permission,
333 PermissionAction action,
334 const GURL& requesting_origin,
335 Profile* profile) {
336 if (IsOptedIntoPermissionActionReporting(profile)) {
337 // TODO(stefanocs): Add browsertests to make sure the reports are being
338 // sent.
339 g_browser_process->safe_browsing_service()
340 ->ui_manager()
341 ->ReportPermissionAction(requesting_origin, permission, action);
342 }
343
344 bool secure_origin = content::IsOriginSecure(requesting_origin);
345
346 switch (permission) {
347 case PermissionType::GEOLOCATION:
348 PERMISSION_ACTION_UMA(secure_origin, "Permissions.Action.Geolocation",
349 "Permissions.Action.SecureOrigin.Geolocation",
350 "Permissions.Action.InsecureOrigin.Geolocation",
351 action);
352 break;
353 case PermissionType::NOTIFICATIONS:
354 PERMISSION_ACTION_UMA(secure_origin, "Permissions.Action.Notifications",
355 "Permissions.Action.SecureOrigin.Notifications",
356 "Permissions.Action.InsecureOrigin.Notifications",
357 action);
358 break;
359 case PermissionType::MIDI_SYSEX:
360 PERMISSION_ACTION_UMA(secure_origin, "Permissions.Action.MidiSysEx",
361 "Permissions.Action.SecureOrigin.MidiSysEx",
362 "Permissions.Action.InsecureOrigin.MidiSysEx",
363 action);
364 break;
365 case PermissionType::PUSH_MESSAGING:
366 PERMISSION_ACTION_UMA(secure_origin, "Permissions.Action.PushMessaging",
367 "Permissions.Action.SecureOrigin.PushMessaging",
368 "Permissions.Action.InsecureOrigin.PushMessaging",
369 action);
370 break;
371 case PermissionType::PROTECTED_MEDIA_IDENTIFIER:
372 PERMISSION_ACTION_UMA(secure_origin, "Permissions.Action.ProtectedMedia",
373 "Permissions.Action.SecureOrigin.ProtectedMedia",
374 "Permissions.Action.InsecureOrigin.ProtectedMedia",
375 action);
376 break;
377 case PermissionType::DURABLE_STORAGE:
378 PERMISSION_ACTION_UMA(secure_origin, "Permissions.Action.DurableStorage",
379 "Permissions.Action.SecureOrigin.DurableStorage",
380 "Permissions.Action.InsecureOrigin.DurableStorage",
381 action);
382 break;
383 case PermissionType::AUDIO_CAPTURE:
384 // Media permissions are disabled on insecure origins, so there's no
385 // need to record metrics for secure/insecue.
386 UMA_HISTOGRAM_ENUMERATION("Permissions.Action.AudioCapture", action,
387 PERMISSION_ACTION_NUM);
388 break;
389 case PermissionType::VIDEO_CAPTURE:
390 UMA_HISTOGRAM_ENUMERATION("Permissions.Action.VideoCapture", action,
391 PERMISSION_ACTION_NUM);
392 break;
393 // The user is not prompted for these permissions, thus there is no
394 // permission action recorded for them.
395 case PermissionType::MIDI:
396 case PermissionType::BACKGROUND_SYNC:
397 case PermissionType::NUM:
398 NOTREACHED() << "PERMISSION "
399 << PermissionUtil::GetPermissionString(permission)
400 << " not accounted for";
401 }
402
403 // Retrieve the name of the RAPPOR metric. Currently, the new metric name is
404 // the deprecated name with "2" on the end, e.g.
405 // ContentSettings.PermissionActions_Geolocation.Granted.Url2. For simplicity,
406 // we retrieve the deprecated name and append the "2" for the new name.
407 // TODO(dominickn): remove the deprecated metric and replace it solely with
408 // the new one in GetRapporMetric - crbug.com/605836.
409 const std::string deprecated_metric = GetRapporMetric(permission, action);
410 rappor::RapporService* rappor_service = g_browser_process->rappor_service();
411 if (!deprecated_metric.empty() && rappor_service) {
412 rappor::SampleDomainAndRegistryFromGURL(rappor_service, deprecated_metric,
413 requesting_origin);
414
415 std::string rappor_metric = deprecated_metric + "2";
416 rappor_service->RecordSample(
417 rappor_metric, rappor::LOW_FREQUENCY_ETLD_PLUS_ONE_RAPPOR_TYPE,
418 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin));
419 }
420 }
OLDNEW
« no previous file with comments | « chrome/browser/permissions/permission_uma_util.h ('k') | chrome/browser/permissions/permission_uma_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698