Add more checks to investigate SupervisedUserPrefStore crash at startup.
[chromium-blink-merge.git] / chrome / browser / content_settings / permission_context_uma_util.cc
blob2f4963844cfdb57962ea84a418436f8dfbbab939
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"
8 #include "url/gurl.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( \
15 permission, \
16 action, \
17 PERMISSION_ACTION_NUM); \
18 if (secure_origin) { \
19 UMA_HISTOGRAM_ENUMERATION(permission_secure, \
20 action, \
21 PERMISSION_ACTION_NUM); \
22 } else { \
23 UMA_HISTOGRAM_ENUMERATION(permission_insecure, \
24 action, \
25 PERMISSION_ACTION_NUM); \
29 namespace {
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 {
35 GRANTED = 0,
36 DENIED = 1,
37 DISMISSED = 2,
38 IGNORED = 3,
40 // Always keep this at the end.
41 PERMISSION_ACTION_NUM,
44 void RecordPermissionAction(
45 ContentSettingsType permission,
46 PermissionAction action,
47 bool secure_origin) {
48 switch (permission) {
49 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
50 PERMISSION_ACTION_UMA(
51 secure_origin,
52 "ContentSettings.PermissionActions_Geolocation",
53 "ContentSettings.PermissionActionsSecureOrigin_Geolocation",
54 "ContentSettings.PermissionActionsInsecureOrigin_Geolocation",
55 action);
56 break;
57 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
58 PERMISSION_ACTION_UMA(
59 secure_origin,
60 "ContentSettings.PermissionActions_Notifications",
61 "ContentSettings.PermissionActionsSecureOrigin_Notifications",
62 "ContentSettings.PermissionActionsInsecureOrigin_Notifications",
63 action);
64 break;
65 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
66 PERMISSION_ACTION_UMA(
67 secure_origin,
68 "ContentSettings.PermissionActions_MidiSysEx",
69 "ContentSettings.PermissionActionsSecureOrigin_MidiSysEx",
70 "ContentSettings.PermissionActionsInsecureOrigin_MidiSysEx",
71 action);
72 break;
73 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
74 PERMISSION_ACTION_UMA(
75 secure_origin,
76 "ContentSettings.PermissionActions_PushMessaging",
77 "ContentSettings.PermissionActionsSecureOrigin_PushMessaging",
78 "ContentSettings.PermissionActionsInsecureOrigin_PushMessaging",
79 action);
80 break;
81 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
82 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
83 PERMISSION_ACTION_UMA(
84 secure_origin,
85 "ContentSettings.PermissionActions_ProtectedMedia",
86 "ContentSettings.PermissionActionsSecureOrigin_ProtectedMedia",
87 "ContentSettings.PermissionActionsInsecureOrigin_ProtectedMedia",
88 action);
89 break;
90 #endif
91 default:
92 NOTREACHED() << "PERMISSION " << permission << " not accounted for";
96 void RecordPermissionRequest(
97 ContentSettingsType permission, bool secure_origin) {
98 content::PermissionType type;
99 switch (permission) {
100 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
101 type = content::PERMISSION_GEOLOCATION;
102 break;
103 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
104 type = content::PERMISSION_NOTIFICATIONS;
105 break;
106 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
107 type = content::PERMISSION_MIDI_SYSEX;
108 break;
109 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
110 type = content::PERMISSION_PUSH_MESSAGING;
111 break;
112 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
113 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
114 type = content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER;
115 break;
116 #endif
117 default:
118 NOTREACHED() << "PERMISSION " << permission << " not accounted for";
119 return;
121 UMA_HISTOGRAM_ENUMERATION(
122 "ContentSettings.PermissionRequested", type, content::PERMISSION_NUM);
123 if (secure_origin) {
124 UMA_HISTOGRAM_ENUMERATION(
125 "ContentSettings.PermissionRequested_SecureOrigin",
126 type,
127 content::PERMISSION_NUM);
128 } else {
129 UMA_HISTOGRAM_ENUMERATION(
130 "ContentSettings.PermissionRequested_InsecureOrigin",
131 type,
132 content::PERMISSION_NUM);
136 } // namespace
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());