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

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

Issue 2047253002: Add hooks to permission layer for permission action reporting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-reporter-implementation
Patch Set: fix nit: remove bracket Created 4 years, 6 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"
9 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
10 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
11 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/permissions/permission_manager.h" 13 #include "chrome/browser/permissions/permission_manager.h"
13 #include "chrome/browser/permissions/permission_util.h" 14 #include "chrome/browser/permissions/permission_util.h"
14 #include "chrome/browser/profiles/profile.h" 15 #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"
15 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" 19 #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"
16 #include "components/rappor/rappor_service.h" 24 #include "components/rappor/rappor_service.h"
17 #include "components/rappor/rappor_utils.h" 25 #include "components/rappor/rappor_utils.h"
18 #include "content/public/browser/permission_type.h" 26 #include "content/public/browser/permission_type.h"
19 #include "content/public/common/origin_util.h" 27 #include "content/public/common/origin_util.h"
20 #include "url/gurl.h" 28 #include "url/gurl.h"
21 29
22 // UMA keys need to be statically initialized so plain function would not 30 // UMA keys need to be statically initialized so plain function would not
23 // work. Use macros instead. 31 // work. Use macros instead.
24 #define PERMISSION_ACTION_UMA(secure_origin, permission, permission_secure, \ 32 #define PERMISSION_ACTION_UMA(secure_origin, permission, permission_secure, \
25 permission_insecure, action) \ 33 permission_insecure, action) \
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 75 }
68 76
69 std::string permission_str = 77 std::string permission_str =
70 PermissionUtil::GetPermissionString(permission); 78 PermissionUtil::GetPermissionString(permission);
71 if (permission_str.empty()) 79 if (permission_str.empty())
72 return ""; 80 return "";
73 return base::StringPrintf("ContentSettings.PermissionActions_%s.%s.Url", 81 return base::StringPrintf("ContentSettings.PermissionActions_%s.%s.Url",
74 permission_str.c_str(), action_str.c_str()); 82 permission_str.c_str(), action_str.c_str());
75 } 83 }
76 84
85 bool IsOptedInPermissionActionReporting(Profile* profile) {
86 // Do not report permission action when the permission action reporting
87 // flag is not enabled.
88 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
89 switches::kEnablePermissionActionReporting))
90 return false;
91 // Do not report if profile is null.
92 if (!profile)
raymes 2016/06/20 02:46:33 nit: perhaps add a TODO here to remove this check
stefanocs 2016/06/21 01:37:17 Done.
93 return false;
94 // Do not report if profile is incognito.
95 if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE)
96 return false;
97 // Do not report when SafeBrowsing is not enabled.
98 if (!profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled))
99 return false;
100 // Do not report if profile doesn't have profile sync service.
101 if (!ProfileSyncServiceFactory::HasProfileSyncService(profile))
102 return false;
103
104 ProfileSyncService* profile_sync_service =
105 ProfileSyncServiceFactory::GetForProfile(profile);
106 syncer::ModelTypeSet preferred_data_types =
107 profile_sync_service->GetPreferredDataTypes();
108
109 // Do not report if profile can't start sync immediately.
110 if (!profile_sync_service->CanSyncStart())
111 return false;
112 // Do not report if Chrome Tab Sync is not enabled.
113 if (!preferred_data_types.Has(syncer::PROXY_TABS))
114 return false;
115 // Do not report if Chrome Pref Sync is not enabled.
116 if (!preferred_data_types.Has(syncer::PREFERENCES))
117 return false;
118 return true;
119 }
120
77 void RecordPermissionAction(PermissionType permission, 121 void RecordPermissionAction(PermissionType permission,
78 PermissionAction action, 122 PermissionAction action,
79 const GURL& requesting_origin) { 123 const GURL& requesting_origin,
124 Profile* profile) {
125 // Send permission action report to opted-in users.
126 if (IsOptedInPermissionActionReporting(profile)) {
127 g_browser_process->safe_browsing_service()
128 ->ui_manager()
129 ->ReportPermissionAction(requesting_origin, permission, action);
130 }
131
80 bool secure_origin = content::IsOriginSecure(requesting_origin); 132 bool secure_origin = content::IsOriginSecure(requesting_origin);
81 133
82 switch (permission) { 134 switch (permission) {
83 case PermissionType::GEOLOCATION: 135 case PermissionType::GEOLOCATION:
84 PERMISSION_ACTION_UMA( 136 PERMISSION_ACTION_UMA(
85 secure_origin, 137 secure_origin,
86 "Permissions.Action.Geolocation", 138 "Permissions.Action.Geolocation",
87 "Permissions.Action.SecureOrigin.Geolocation", 139 "Permissions.Action.SecureOrigin.Geolocation",
88 "Permissions.Action.InsecureOrigin.Geolocation", 140 "Permissions.Action.InsecureOrigin.Geolocation",
89 action); 141 action);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // add new permission 325 // add new permission
274 void PermissionUmaUtil::PermissionRequested(PermissionType permission, 326 void PermissionUmaUtil::PermissionRequested(PermissionType permission,
275 const GURL& requesting_origin, 327 const GURL& requesting_origin,
276 const GURL& embedding_origin, 328 const GURL& embedding_origin,
277 Profile* profile) { 329 Profile* profile) {
278 RecordPermissionRequest(permission, requesting_origin, embedding_origin, 330 RecordPermissionRequest(permission, requesting_origin, embedding_origin,
279 profile); 331 profile);
280 } 332 }
281 333
282 void PermissionUmaUtil::PermissionGranted(PermissionType permission, 334 void PermissionUmaUtil::PermissionGranted(PermissionType permission,
283 const GURL& requesting_origin) { 335 const GURL& requesting_origin,
284 RecordPermissionAction(permission, GRANTED, requesting_origin); 336 Profile* profile) {
337 RecordPermissionAction(permission, GRANTED, requesting_origin, profile);
285 } 338 }
286 339
287 void PermissionUmaUtil::PermissionDenied(PermissionType permission, 340 void PermissionUmaUtil::PermissionDenied(PermissionType permission,
288 const GURL& requesting_origin) { 341 const GURL& requesting_origin,
289 RecordPermissionAction(permission, DENIED, requesting_origin); 342 Profile* profile) {
343 RecordPermissionAction(permission, DENIED, requesting_origin, profile);
290 } 344 }
291 345
292 void PermissionUmaUtil::PermissionDismissed(PermissionType permission, 346 void PermissionUmaUtil::PermissionDismissed(PermissionType permission,
293 const GURL& requesting_origin) { 347 const GURL& requesting_origin,
294 RecordPermissionAction(permission, DISMISSED, requesting_origin); 348 Profile* profile) {
349 RecordPermissionAction(permission, DISMISSED, requesting_origin, profile);
295 } 350 }
296 351
297 void PermissionUmaUtil::PermissionIgnored(PermissionType permission, 352 void PermissionUmaUtil::PermissionIgnored(PermissionType permission,
298 const GURL& requesting_origin) { 353 const GURL& requesting_origin,
299 RecordPermissionAction(permission, IGNORED, requesting_origin); 354 Profile* profile) {
355 RecordPermissionAction(permission, IGNORED, requesting_origin, profile);
300 } 356 }
301 357
302 void PermissionUmaUtil::PermissionRevoked(PermissionType permission, 358 void PermissionUmaUtil::PermissionRevoked(PermissionType permission,
303 const GURL& revoked_origin) { 359 const GURL& revoked_origin,
360 Profile* profile) {
304 // TODO(tsergeant): Expand metrics definitions for revocation to include all 361 // TODO(tsergeant): Expand metrics definitions for revocation to include all
305 // permissions. 362 // permissions.
306 if (permission == PermissionType::NOTIFICATIONS || 363 if (permission == PermissionType::NOTIFICATIONS ||
307 permission == PermissionType::GEOLOCATION || 364 permission == PermissionType::GEOLOCATION ||
308 permission == PermissionType::AUDIO_CAPTURE || 365 permission == PermissionType::AUDIO_CAPTURE ||
309 permission == PermissionType::VIDEO_CAPTURE) { 366 permission == PermissionType::VIDEO_CAPTURE) {
310 RecordPermissionAction(permission, REVOKED, revoked_origin); 367 RecordPermissionAction(permission, REVOKED, revoked_origin, profile);
311 } 368 }
312 } 369 }
313 370
314 void PermissionUmaUtil::PermissionPromptShown( 371 void PermissionUmaUtil::PermissionPromptShown(
315 const std::vector<PermissionBubbleRequest*>& requests) { 372 const std::vector<PermissionBubbleRequest*>& requests) {
316 DCHECK(!requests.empty()); 373 DCHECK(!requests.empty());
317 374
318 PermissionBubbleType permission_prompt_type = PermissionBubbleType::MULTIPLE; 375 PermissionBubbleType permission_prompt_type = PermissionBubbleType::MULTIPLE;
319 if (requests.size() == 1) 376 if (requests.size() == 1)
320 permission_prompt_type = requests[0]->GetPermissionBubbleType(); 377 permission_prompt_type = requests[0]->GetPermissionBubbleType();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 424 }
368 425
369 void PermissionUmaUtil::PermissionPromptDenied( 426 void PermissionUmaUtil::PermissionPromptDenied(
370 const std::vector<PermissionBubbleRequest*>& requests) { 427 const std::vector<PermissionBubbleRequest*>& requests) {
371 DCHECK(!requests.empty()); 428 DCHECK(!requests.empty());
372 DCHECK(requests.size() == 1); 429 DCHECK(requests.size() == 1);
373 430
374 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptDenied, 431 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptDenied,
375 requests[0]->GetPermissionBubbleType()); 432 requests[0]->GetPermissionBubbleType());
376 } 433 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698