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
3 // found in the LICENSE file.
5 #include "base/metrics/histogram.h"
6 #include "chrome/browser/content_settings/permission_context_uma_util.h"
7 #include "content/public/browser/permission_type.h"
10 // UMA keys need to be statically initialized so plain function would not
11 // work. Use a Macro instead.
12 #define PERMISSION_ACTION_UMA(secure_origin, \
13 permission, permission_secure, permission_insecure, action) \
14 UMA_HISTOGRAM_ENUMERATION( \
17 PERMISSION_ACTION_NUM); \
18 if (secure_origin) { \
19 UMA_HISTOGRAM_ENUMERATION(permission_secure, \
21 PERMISSION_ACTION_NUM); \
23 UMA_HISTOGRAM_ENUMERATION(permission_insecure, \
25 PERMISSION_ACTION_NUM); \
31 // Enum for UMA purposes, make sure you update histograms.xml if you add new
32 // permission actions. Never delete or reorder an entry; only add new entries
33 // immediately before PERMISSION_NUM
34 enum PermissionAction
{
40 // Always keep this at the end.
41 PERMISSION_ACTION_NUM
,
44 void RecordPermissionAction(
45 ContentSettingsType permission
,
46 PermissionAction action
,
49 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
50 PERMISSION_ACTION_UMA(
52 "ContentSettings.PermissionActions_Geolocation",
53 "ContentSettings.PermissionActionsSecureOrigin_Geolocation",
54 "ContentSettings.PermissionActionsInsecureOrigin_Geolocation",
57 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
58 PERMISSION_ACTION_UMA(
60 "ContentSettings.PermissionActions_Notifications",
61 "ContentSettings.PermissionActionsSecureOrigin_Notifications",
62 "ContentSettings.PermissionActionsInsecureOrigin_Notifications",
65 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
66 PERMISSION_ACTION_UMA(
68 "ContentSettings.PermissionActions_MidiSysEx",
69 "ContentSettings.PermissionActionsSecureOrigin_MidiSysEx",
70 "ContentSettings.PermissionActionsInsecureOrigin_MidiSysEx",
73 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
:
74 PERMISSION_ACTION_UMA(
76 "ContentSettings.PermissionActions_PushMessaging",
77 "ContentSettings.PermissionActionsSecureOrigin_PushMessaging",
78 "ContentSettings.PermissionActionsInsecureOrigin_PushMessaging",
81 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
82 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
:
83 PERMISSION_ACTION_UMA(
85 "ContentSettings.PermissionActions_ProtectedMedia",
86 "ContentSettings.PermissionActionsSecureOrigin_ProtectedMedia",
87 "ContentSettings.PermissionActionsInsecureOrigin_ProtectedMedia",
92 NOTREACHED() << "PERMISSION " << permission
<< " not accounted for";
96 void RecordPermissionRequest(
97 ContentSettingsType permission
, bool secure_origin
) {
98 content::PermissionType type
;
100 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
101 type
= content::PERMISSION_GEOLOCATION
;
103 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
104 type
= content::PERMISSION_NOTIFICATIONS
;
106 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
107 type
= content::PERMISSION_MIDI_SYSEX
;
109 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
:
110 type
= content::PERMISSION_PUSH_MESSAGING
;
112 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
113 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
:
114 type
= content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER
;
118 NOTREACHED() << "PERMISSION " << permission
<< " not accounted for";
121 UMA_HISTOGRAM_ENUMERATION(
122 "ContentSettings.PermissionRequested", type
, content::PERMISSION_NUM
);
124 UMA_HISTOGRAM_ENUMERATION(
125 "ContentSettings.PermissionRequested_SecureOrigin",
127 content::PERMISSION_NUM
);
129 UMA_HISTOGRAM_ENUMERATION(
130 "ContentSettings.PermissionRequested_InsecureOrigin",
132 content::PERMISSION_NUM
);
138 // Make sure you update histograms.xml permission histogram_suffix if you
139 // add new permission
140 void PermissionContextUmaUtil::PermissionRequested(
141 ContentSettingsType permission
, const GURL
& requesting_origin
) {
142 RecordPermissionRequest(permission
, requesting_origin
.SchemeIsSecure());
145 void PermissionContextUmaUtil::PermissionGranted(
146 ContentSettingsType permission
, const GURL
& requesting_origin
) {
147 RecordPermissionAction(permission
, GRANTED
,
148 requesting_origin
.SchemeIsSecure());
151 void PermissionContextUmaUtil::PermissionDenied(
152 ContentSettingsType permission
, const GURL
& requesting_origin
) {
153 RecordPermissionAction(permission
, DENIED
,
154 requesting_origin
.SchemeIsSecure());
157 void PermissionContextUmaUtil::PermissionDismissed(
158 ContentSettingsType permission
, const GURL
& requesting_origin
) {
159 RecordPermissionAction(permission
, DISMISSED
,
160 requesting_origin
.SchemeIsSecure());
163 void PermissionContextUmaUtil::PermissionIgnored(
164 ContentSettingsType permission
, const GURL
& requesting_origin
) {
165 RecordPermissionAction(permission
, IGNORED
,
166 requesting_origin
.SchemeIsSecure());