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) { | |
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"; | |
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"); | |
raymes
2017/07/06 05:03:15
Are we interested in recording the total requests?
Timothy Loh
2017/07/19 06:03:43
I don't think we need to record the total requests
| |
113 std::string name = "Permissions.Engagement." + action + '.' + | |
114 GetPermissionRequestString(type); | |
raymes
2017/07/06 05:03:15
Hmm, I think what we're really interested in is wh
Timothy Loh
2017/07/19 06:03:43
At least as far as we only group mic+camera right
raymes
2017/07/20 03:37:13
Ok - if you think so I'm ok. It just seemed simple
| |
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 | |
raymes
2017/07/06 05:03:15
nit: no newline needed
Timothy Loh
2017/07/19 06:03:43
Done.
| |
124 base::LinearHistogram::FactoryGet( | |
125 name, 1, 101, 102, base::HistogramBase::kUmaTargetedHistogramFlag) | |
126 ->Add(engagement_score); | |
127 } | |
128 | |
65 const std::string GetRapporMetric(ContentSettingsType permission, | 129 const std::string GetRapporMetric(ContentSettingsType permission, |
66 PermissionAction action) { | 130 PermissionAction action) { |
67 std::string action_str; | 131 std::string action_str; |
68 switch (action) { | 132 switch (action) { |
69 case PermissionAction::GRANTED: | 133 case PermissionAction::GRANTED: |
70 action_str = "Granted"; | 134 action_str = "Granted"; |
71 break; | 135 break; |
72 case PermissionAction::DENIED: | 136 case PermissionAction::DENIED: |
73 action_str = "Denied"; | 137 action_str = "Denied"; |
74 break; | 138 break; |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 | 447 |
384 if (requests.size() > 1) { | 448 if (requests.size() > 1) { |
385 for (const auto* request : requests) { | 449 for (const auto* request : requests) { |
386 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptMergedBubbleTypes, | 450 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptMergedBubbleTypes, |
387 request->GetPermissionRequestType()); | 451 request->GetPermissionRequestType()); |
388 } | 452 } |
389 } | 453 } |
390 } | 454 } |
391 | 455 |
392 void PermissionUmaUtil::PermissionPromptAccepted( | 456 void PermissionUmaUtil::PermissionPromptAccepted( |
393 const std::vector<PermissionRequest*>& requests) { | 457 const std::vector<PermissionRequest*>& requests, |
458 const content::WebContents* web_contents) { | |
394 RecordPromptDecided(requests, /*accepted=*/true); | 459 RecordPromptDecided(requests, /*accepted=*/true); |
460 RecordEngagementMetric(requests, web_contents, "Accepted"); | |
395 } | 461 } |
396 | 462 |
397 void PermissionUmaUtil::PermissionPromptDenied( | 463 void PermissionUmaUtil::PermissionPromptDenied( |
398 const std::vector<PermissionRequest*>& requests) { | 464 const std::vector<PermissionRequest*>& requests, |
465 const content::WebContents* web_contents) { | |
399 RecordPromptDecided(requests, /*accepted=*/false); | 466 RecordPromptDecided(requests, /*accepted=*/false); |
467 RecordEngagementMetric(requests, web_contents, "Denied"); | |
468 } | |
469 | |
470 void PermissionUmaUtil::PermissionPromptDismissed( | |
471 const std::vector<PermissionRequest*>& requests, | |
472 const content::WebContents* web_contents) { | |
473 RecordEngagementMetric(requests, web_contents, "Dismissed"); | |
474 } | |
475 | |
476 void PermissionUmaUtil::PermissionPromptIgnored( | |
477 const std::vector<PermissionRequest*>& requests, | |
478 const content::WebContents* web_contents) { | |
479 RecordEngagementMetric(requests, web_contents, "Ignored"); | |
400 } | 480 } |
401 | 481 |
402 void PermissionUmaUtil::RecordPermissionPromptShown( | 482 void PermissionUmaUtil::RecordPermissionPromptShown( |
403 PermissionRequestType request_type, | 483 PermissionRequestType request_type, |
404 PermissionRequestGestureType gesture_type) { | 484 PermissionRequestGestureType gesture_type) { |
405 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptShown, request_type); | 485 PERMISSION_BUBBLE_TYPE_UMA(kPermissionsPromptShown, request_type); |
406 PERMISSION_BUBBLE_GESTURE_TYPE_UMA( | 486 PERMISSION_BUBBLE_GESTURE_TYPE_UMA( |
407 kPermissionsPromptShownGesture, kPermissionsPromptShownNoGesture, | 487 kPermissionsPromptShownGesture, kPermissionsPromptShownNoGesture, |
408 gesture_type, request_type); | 488 gesture_type, request_type); |
409 } | 489 } |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
706 } | 786 } |
707 | 787 |
708 if (accepted) { | 788 if (accepted) { |
709 RecordPermissionPromptAccepted(permission_prompt_type, | 789 RecordPermissionPromptAccepted(permission_prompt_type, |
710 permission_gesture_type); | 790 permission_gesture_type); |
711 } else { | 791 } else { |
712 RecordPermissionPromptDenied(permission_prompt_type, | 792 RecordPermissionPromptDenied(permission_prompt_type, |
713 permission_gesture_type); | 793 permission_gesture_type); |
714 } | 794 } |
715 } | 795 } |
OLD | NEW |