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