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