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/command_line.h" |
| 10 #include "base/metrics/histogram_functions.h" |
10 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/engagement/site_engagement_service.h" |
14 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" | 16 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" |
15 #include "chrome/browser/permissions/permission_request.h" | 17 #include "chrome/browser/permissions/permission_request.h" |
16 #include "chrome/browser/permissions/permission_util.h" | 18 #include "chrome/browser/permissions/permission_util.h" |
17 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
19 #include "chrome/browser/safe_browsing/ui_manager.h" | 21 #include "chrome/browser/safe_browsing/ui_manager.h" |
20 #include "chrome/browser/sync/profile_sync_service_factory.h" | 22 #include "chrome/browser/sync/profile_sync_service_factory.h" |
21 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
23 #include "components/browser_sync/profile_sync_service.h" | 25 #include "components/browser_sync/profile_sync_service.h" |
24 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
25 #include "components/rappor/public/rappor_utils.h" | 27 #include "components/rappor/public/rappor_utils.h" |
26 #include "components/rappor/rappor_service_impl.h" | 28 #include "components/rappor/rappor_service_impl.h" |
27 #include "content/public/browser/permission_type.h" | 29 #include "content/public/browser/permission_type.h" |
| 30 #include "content/public/browser/web_contents.h" |
28 #include "content/public/common/origin_util.h" | 31 #include "content/public/common/origin_util.h" |
29 #include "url/gurl.h" | 32 #include "url/gurl.h" |
30 | 33 |
31 // UMA keys need to be statically initialized so plain function would not | 34 // UMA keys need to be statically initialized so plain function would not |
32 // work. Use macros instead. | 35 // work. Use macros instead. |
33 #define PERMISSION_ACTION_UMA(secure_origin, permission, permission_secure, \ | 36 #define PERMISSION_ACTION_UMA(secure_origin, permission, permission_secure, \ |
34 permission_insecure, action) \ | 37 permission_insecure, action) \ |
35 UMA_HISTOGRAM_ENUMERATION(permission, action, PermissionAction::NUM); \ | 38 UMA_HISTOGRAM_ENUMERATION(permission, action, PermissionAction::NUM); \ |
36 if (secure_origin) { \ | 39 if (secure_origin) { \ |
37 UMA_HISTOGRAM_ENUMERATION(permission_secure, action, \ | 40 UMA_HISTOGRAM_ENUMERATION(permission_secure, action, \ |
(...skipping 17 matching lines...) Expand all Loading... |
55 PERMISSION_BUBBLE_TYPE_UMA(no_gesture_metric_name, \ | 58 PERMISSION_BUBBLE_TYPE_UMA(no_gesture_metric_name, \ |
56 permission_bubble_type); \ | 59 permission_bubble_type); \ |
57 } | 60 } |
58 | 61 |
59 using content::PermissionType; | 62 using content::PermissionType; |
60 | 63 |
61 namespace { | 64 namespace { |
62 | 65 |
63 static bool gIsFakeOfficialBuildForTest = false; | 66 static bool gIsFakeOfficialBuildForTest = false; |
64 | 67 |
| 68 std::string GetPermissionRequestString(PermissionRequestType type) { |
| 69 switch (type) { |
| 70 case PermissionRequestType::MULTIPLE: |
| 71 return "AudioAndVideoCapture"; |
| 72 case PermissionRequestType::QUOTA: |
| 73 return "Quota"; |
| 74 case PermissionRequestType::DOWNLOAD: |
| 75 return "MultipleDownload"; |
| 76 case PermissionRequestType::REGISTER_PROTOCOL_HANDLER: |
| 77 return "RegisterProtocolHandler"; |
| 78 case PermissionRequestType::PERMISSION_GEOLOCATION: |
| 79 return "Geolocation"; |
| 80 case PermissionRequestType::PERMISSION_MIDI_SYSEX: |
| 81 return "MidiSysEx"; |
| 82 case PermissionRequestType::PERMISSION_NOTIFICATIONS: |
| 83 return "Notifications"; |
| 84 case PermissionRequestType::PERMISSION_PROTECTED_MEDIA_IDENTIFIER: |
| 85 return "ProtectedMedia"; |
| 86 case PermissionRequestType::PERMISSION_PUSH_MESSAGING: |
| 87 return "PushMessaging"; |
| 88 case PermissionRequestType::PERMISSION_FLASH: |
| 89 return "Flash"; |
| 90 case PermissionRequestType::PERMISSION_MEDIASTREAM_MIC: |
| 91 return "AudioCapture"; |
| 92 case PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA: |
| 93 return "VideoCapture"; |
| 94 default: |
| 95 NOTREACHED(); |
| 96 return ""; |
| 97 } |
| 98 } |
| 99 |
| 100 void RecordEngagementMetric(const std::vector<PermissionRequest*>& requests, |
| 101 const content::WebContents* web_contents, |
| 102 const std::string& action) { |
| 103 PermissionRequestType type = requests[0]->GetPermissionRequestType(); |
| 104 if (requests.size() > 1) |
| 105 type = PermissionRequestType::MULTIPLE; |
| 106 |
| 107 // This is only hit if kUsePermissionManagerForMediaRequests is off, since it |
| 108 // is now on by default we'll just silenty drop this. |
| 109 if (type == PermissionRequestType::MEDIA_STREAM) |
| 110 return; |
| 111 |
| 112 DCHECK(action == "Accepted" || action == "Denied" || action == "Dismissed" || |
| 113 action == "Ignored"); |
| 114 std::string name = "Permissions.Engagement." + action + '.' + |
| 115 GetPermissionRequestString(type); |
| 116 |
| 117 SiteEngagementService* site_engagement_service = SiteEngagementService::Get( |
| 118 Profile::FromBrowserContext(web_contents->GetBrowserContext())); |
| 119 double engagement_score = |
| 120 site_engagement_service->GetScore(requests[0]->GetOrigin()); |
| 121 |
| 122 base::UmaHistogramPercentage(name, engagement_score); |
| 123 } |
| 124 |
65 const std::string GetRapporMetric(ContentSettingsType permission, | 125 const std::string GetRapporMetric(ContentSettingsType permission, |
66 PermissionAction action) { | 126 PermissionAction action) { |
67 std::string action_str; | 127 std::string action_str; |
68 switch (action) { | 128 switch (action) { |
69 case PermissionAction::GRANTED: | 129 case PermissionAction::GRANTED: |
70 action_str = "Granted"; | 130 action_str = "Granted"; |
71 break; | 131 break; |
72 case PermissionAction::DENIED: | 132 case PermissionAction::DENIED: |
73 action_str = "Denied"; | 133 action_str = "Denied"; |
74 break; | 134 break; |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 requests.size(), 10); | 442 requests.size(), 10); |
383 | 443 |
384 if (requests.size() > 1) { | 444 if (requests.size() > 1) { |
385 for (const auto* request : requests) { | 445 for (const auto* request : requests) { |
386 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptMergedBubbleTypes, | 446 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptMergedBubbleTypes, |
387 request->GetPermissionRequestType()); | 447 request->GetPermissionRequestType()); |
388 } | 448 } |
389 } | 449 } |
390 } | 450 } |
391 | 451 |
392 void PermissionUmaUtil::PermissionPromptAccepted( | 452 void PermissionUmaUtil::PermissionPromptResolved( |
393 const std::vector<PermissionRequest*>& requests) { | 453 const std::vector<PermissionRequest*>& requests, |
394 RecordPromptDecided(requests, /*accepted=*/true); | 454 const content::WebContents* web_contents, |
395 } | 455 PermissionAction permission_action) { |
396 | 456 switch (permission_action) { |
397 void PermissionUmaUtil::PermissionPromptDenied( | 457 case PermissionAction::GRANTED: |
398 const std::vector<PermissionRequest*>& requests) { | 458 RecordPromptDecided(requests, /*accepted=*/true); |
399 RecordPromptDecided(requests, /*accepted=*/false); | 459 RecordEngagementMetric(requests, web_contents, "Accepted"); |
| 460 break; |
| 461 case PermissionAction::DENIED: |
| 462 RecordPromptDecided(requests, /*accepted=*/false); |
| 463 RecordEngagementMetric(requests, web_contents, "Denied"); |
| 464 break; |
| 465 case PermissionAction::DISMISSED: |
| 466 RecordEngagementMetric(requests, web_contents, "Dismissed"); |
| 467 break; |
| 468 case PermissionAction::IGNORED: |
| 469 RecordEngagementMetric(requests, web_contents, "Ignored"); |
| 470 break; |
| 471 default: |
| 472 NOTREACHED(); |
| 473 break; |
| 474 } |
400 } | 475 } |
401 | 476 |
402 void PermissionUmaUtil::RecordPermissionPromptShown( | 477 void PermissionUmaUtil::RecordPermissionPromptShown( |
403 PermissionRequestType request_type, | 478 PermissionRequestType request_type, |
404 PermissionRequestGestureType gesture_type) { | 479 PermissionRequestGestureType gesture_type) { |
405 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptShown, request_type); | 480 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptShown, request_type); |
406 PERMISSION_BUBBLE_GESTURE_TYPE_UMA( | 481 PERMISSION_BUBBLE_GESTURE_TYPE_UMA( |
407 kPermissionsPromptShownGesture, kPermissionsPromptShownNoGesture, | 482 kPermissionsPromptShownGesture, kPermissionsPromptShownNoGesture, |
408 gesture_type, request_type); | 483 gesture_type, request_type); |
409 } | 484 } |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 } | 781 } |
707 | 782 |
708 if (accepted) { | 783 if (accepted) { |
709 RecordPermissionPromptAccepted(permission_prompt_type, | 784 RecordPermissionPromptAccepted(permission_prompt_type, |
710 permission_gesture_type); | 785 permission_gesture_type); |
711 } else { | 786 } else { |
712 RecordPermissionPromptDenied(permission_prompt_type, | 787 RecordPermissionPromptDenied(permission_prompt_type, |
713 permission_gesture_type); | 788 permission_gesture_type); |
714 } | 789 } |
715 } | 790 } |
OLD | NEW |