Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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) | |
| 93 return false; | |
| 94 // Do not report if profile is incognito. | |
| 95 if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE) { | |
|
stefanocs
2016/06/17 00:42:08
Nathan, can this be used instead for the incognito
| |
| 96 return false; | |
| 97 } | |
| 98 // Do not report when SafeBrowsing is not enabled. | |
| 99 if (!profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) | |
| 100 return false; | |
| 101 // Do not report if profile doesn't have profile sync service. | |
| 102 if (!ProfileSyncServiceFactory::HasProfileSyncService(profile)) | |
| 103 return false; | |
| 104 | |
| 105 ProfileSyncService* profile_sync_service = | |
| 106 ProfileSyncServiceFactory::GetForProfile(profile); | |
| 107 syncer::ModelTypeSet preferred_data_types = | |
| 108 profile_sync_service->GetPreferredDataTypes(); | |
| 109 | |
| 110 // Do not report if profile can't start sync immediately. | |
| 111 if (!profile_sync_service->CanSyncStart()) | |
| 112 return false; | |
| 113 // Do not report if Chrome Tab Sync is not enabled. | |
| 114 if (!preferred_data_types.Has(syncer::PROXY_TABS)) | |
| 115 return false; | |
| 116 // Do not report if Chrome Pref Sync is not enabled. | |
| 117 if (!preferred_data_types.Has(syncer::PREFERENCES)) | |
| 118 return false; | |
| 119 return true; | |
| 120 } | |
| 121 | |
| 77 void RecordPermissionAction(PermissionType permission, | 122 void RecordPermissionAction(PermissionType permission, |
| 78 PermissionAction action, | 123 PermissionAction action, |
| 79 const GURL& requesting_origin) { | 124 const GURL& requesting_origin, |
| 125 Profile* profile) { | |
| 126 // Send permission action report to opted-in users. | |
| 127 if (IsOptedInPermissionActionReporting(profile)) { | |
| 128 g_browser_process->safe_browsing_service() | |
| 129 ->ui_manager() | |
| 130 ->ReportPermissionAction(requesting_origin, permission, action); | |
| 131 } | |
| 132 | |
| 80 bool secure_origin = content::IsOriginSecure(requesting_origin); | 133 bool secure_origin = content::IsOriginSecure(requesting_origin); |
| 81 | 134 |
| 82 switch (permission) { | 135 switch (permission) { |
| 83 case PermissionType::GEOLOCATION: | 136 case PermissionType::GEOLOCATION: |
| 84 PERMISSION_ACTION_UMA( | 137 PERMISSION_ACTION_UMA( |
| 85 secure_origin, | 138 secure_origin, |
| 86 "Permissions.Action.Geolocation", | 139 "Permissions.Action.Geolocation", |
| 87 "Permissions.Action.SecureOrigin.Geolocation", | 140 "Permissions.Action.SecureOrigin.Geolocation", |
| 88 "Permissions.Action.InsecureOrigin.Geolocation", | 141 "Permissions.Action.InsecureOrigin.Geolocation", |
| 89 action); | 142 action); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 // add new permission | 326 // add new permission |
| 274 void PermissionUmaUtil::PermissionRequested(PermissionType permission, | 327 void PermissionUmaUtil::PermissionRequested(PermissionType permission, |
| 275 const GURL& requesting_origin, | 328 const GURL& requesting_origin, |
| 276 const GURL& embedding_origin, | 329 const GURL& embedding_origin, |
| 277 Profile* profile) { | 330 Profile* profile) { |
| 278 RecordPermissionRequest(permission, requesting_origin, embedding_origin, | 331 RecordPermissionRequest(permission, requesting_origin, embedding_origin, |
| 279 profile); | 332 profile); |
| 280 } | 333 } |
| 281 | 334 |
| 282 void PermissionUmaUtil::PermissionGranted(PermissionType permission, | 335 void PermissionUmaUtil::PermissionGranted(PermissionType permission, |
| 283 const GURL& requesting_origin) { | 336 const GURL& requesting_origin, |
| 284 RecordPermissionAction(permission, GRANTED, requesting_origin); | 337 Profile* profile) { |
| 338 RecordPermissionAction(permission, GRANTED, requesting_origin, profile); | |
| 285 } | 339 } |
| 286 | 340 |
| 287 void PermissionUmaUtil::PermissionDenied(PermissionType permission, | 341 void PermissionUmaUtil::PermissionDenied(PermissionType permission, |
| 288 const GURL& requesting_origin) { | 342 const GURL& requesting_origin, |
| 289 RecordPermissionAction(permission, DENIED, requesting_origin); | 343 Profile* profile) { |
| 344 RecordPermissionAction(permission, DENIED, requesting_origin, profile); | |
| 290 } | 345 } |
| 291 | 346 |
| 292 void PermissionUmaUtil::PermissionDismissed(PermissionType permission, | 347 void PermissionUmaUtil::PermissionDismissed(PermissionType permission, |
| 293 const GURL& requesting_origin) { | 348 const GURL& requesting_origin, |
| 294 RecordPermissionAction(permission, DISMISSED, requesting_origin); | 349 Profile* profile) { |
| 350 RecordPermissionAction(permission, DISMISSED, requesting_origin, profile); | |
| 295 } | 351 } |
| 296 | 352 |
| 297 void PermissionUmaUtil::PermissionIgnored(PermissionType permission, | 353 void PermissionUmaUtil::PermissionIgnored(PermissionType permission, |
| 298 const GURL& requesting_origin) { | 354 const GURL& requesting_origin, |
| 299 RecordPermissionAction(permission, IGNORED, requesting_origin); | 355 Profile* profile) { |
| 356 RecordPermissionAction(permission, IGNORED, requesting_origin, profile); | |
| 300 } | 357 } |
| 301 | 358 |
| 302 void PermissionUmaUtil::PermissionRevoked(PermissionType permission, | 359 void PermissionUmaUtil::PermissionRevoked(PermissionType permission, |
| 303 const GURL& revoked_origin) { | 360 const GURL& revoked_origin, |
| 361 Profile* profile) { | |
| 304 // TODO(tsergeant): Expand metrics definitions for revocation to include all | 362 // TODO(tsergeant): Expand metrics definitions for revocation to include all |
| 305 // permissions. | 363 // permissions. |
| 306 if (permission == PermissionType::NOTIFICATIONS || | 364 if (permission == PermissionType::NOTIFICATIONS || |
| 307 permission == PermissionType::GEOLOCATION || | 365 permission == PermissionType::GEOLOCATION || |
| 308 permission == PermissionType::AUDIO_CAPTURE || | 366 permission == PermissionType::AUDIO_CAPTURE || |
| 309 permission == PermissionType::VIDEO_CAPTURE) { | 367 permission == PermissionType::VIDEO_CAPTURE) { |
| 310 RecordPermissionAction(permission, REVOKED, revoked_origin); | 368 RecordPermissionAction(permission, REVOKED, revoked_origin, profile); |
| 311 } | 369 } |
| 312 } | 370 } |
| 313 | 371 |
| 314 void PermissionUmaUtil::PermissionPromptShown( | 372 void PermissionUmaUtil::PermissionPromptShown( |
| 315 const std::vector<PermissionBubbleRequest*>& requests) { | 373 const std::vector<PermissionBubbleRequest*>& requests) { |
| 316 DCHECK(!requests.empty()); | 374 DCHECK(!requests.empty()); |
| 317 | 375 |
| 318 PermissionBubbleType permission_prompt_type = PermissionBubbleType::MULTIPLE; | 376 PermissionBubbleType permission_prompt_type = PermissionBubbleType::MULTIPLE; |
| 319 if (requests.size() == 1) | 377 if (requests.size() == 1) |
| 320 permission_prompt_type = requests[0]->GetPermissionBubbleType(); | 378 permission_prompt_type = requests[0]->GetPermissionBubbleType(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 } | 425 } |
| 368 | 426 |
| 369 void PermissionUmaUtil::PermissionPromptDenied( | 427 void PermissionUmaUtil::PermissionPromptDenied( |
| 370 const std::vector<PermissionBubbleRequest*>& requests) { | 428 const std::vector<PermissionBubbleRequest*>& requests) { |
| 371 DCHECK(!requests.empty()); | 429 DCHECK(!requests.empty()); |
| 372 DCHECK(requests.size() == 1); | 430 DCHECK(requests.size() == 1); |
| 373 | 431 |
| 374 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptDenied, | 432 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptDenied, |
| 375 requests[0]->GetPermissionBubbleType()); | 433 requests[0]->GetPermissionBubbleType()); |
| 376 } | 434 } |
| OLD | NEW |