| 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 "base/metrics/histogram.h" | 5 #include "base/metrics/histogram.h" |
| 6 #include "chrome/browser/content_settings/permission_context_uma_util.h" | 6 #include "chrome/browser/content_settings/permission_context_uma_util.h" |
| 7 #include "content/public/browser/permission_type.h" |
| 7 #include "url/gurl.h" | 8 #include "url/gurl.h" |
| 8 | 9 |
| 9 | |
| 10 // UMA keys need to be statically initialized so plain function would not | 10 // UMA keys need to be statically initialized so plain function would not |
| 11 // work. Use a Macro instead. | 11 // work. Use a Macro instead. |
| 12 #define PERMISSION_ACTION_UMA(secure_origin, \ | 12 #define PERMISSION_ACTION_UMA(secure_origin, \ |
| 13 permission, permission_secure, permission_insecure, action) \ | 13 permission, permission_secure, permission_insecure, action) \ |
| 14 UMA_HISTOGRAM_ENUMERATION( \ | 14 UMA_HISTOGRAM_ENUMERATION( \ |
| 15 permission, \ | 15 permission, \ |
| 16 action, \ | 16 action, \ |
| 17 PERMISSION_ACTION_NUM); \ | 17 PERMISSION_ACTION_NUM); \ |
| 18 if (secure_origin) { \ | 18 if (secure_origin) { \ |
| 19 UMA_HISTOGRAM_ENUMERATION(permission_secure, \ | 19 UMA_HISTOGRAM_ENUMERATION(permission_secure, \ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 34 enum PermissionAction { | 34 enum PermissionAction { |
| 35 GRANTED = 0, | 35 GRANTED = 0, |
| 36 DENIED = 1, | 36 DENIED = 1, |
| 37 DISMISSED = 2, | 37 DISMISSED = 2, |
| 38 IGNORED = 3, | 38 IGNORED = 3, |
| 39 | 39 |
| 40 // Always keep this at the end. | 40 // Always keep this at the end. |
| 41 PERMISSION_ACTION_NUM, | 41 PERMISSION_ACTION_NUM, |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 // Enum for UMA purposes, make sure you update histograms.xml if you add new | |
| 45 // permission actions. Never delete or reorder an entry; only add new entries | |
| 46 // immediately before PERMISSION_NUM | |
| 47 enum PermissionType { | |
| 48 PERMISSION_UNKNOWN = 0, | |
| 49 PERMISSION_MIDI_SYSEX = 1, | |
| 50 PERMISSION_PUSH_MESSAGING = 2, | |
| 51 PERMISSION_NOTIFICATIONS = 3, | |
| 52 PERMISSION_GEOLOCATION = 4, | |
| 53 | |
| 54 // Always keep this at the end. | |
| 55 PERMISSION_NUM, | |
| 56 }; | |
| 57 | |
| 58 void RecordPermissionAction( | 44 void RecordPermissionAction( |
| 59 ContentSettingsType permission, | 45 ContentSettingsType permission, |
| 60 PermissionAction action, | 46 PermissionAction action, |
| 61 bool secure_origin) { | 47 bool secure_origin) { |
| 62 switch (permission) { | 48 switch (permission) { |
| 63 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 49 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 64 PERMISSION_ACTION_UMA( | 50 PERMISSION_ACTION_UMA( |
| 65 secure_origin, | 51 secure_origin, |
| 66 "ContentSettings.PermissionActions_Geolocation", | 52 "ContentSettings.PermissionActions_Geolocation", |
| 67 "ContentSettings.PermissionActionsSecureOrigin_Geolocation", | 53 "ContentSettings.PermissionActionsSecureOrigin_Geolocation", |
| (...skipping 30 matching lines...) Expand all Loading... |
| 98 // the generic permission class. | 84 // the generic permission class. |
| 99 break; | 85 break; |
| 100 #endif | 86 #endif |
| 101 default: | 87 default: |
| 102 NOTREACHED() << "PERMISSION " << permission << " not accounted for"; | 88 NOTREACHED() << "PERMISSION " << permission << " not accounted for"; |
| 103 } | 89 } |
| 104 } | 90 } |
| 105 | 91 |
| 106 void RecordPermissionRequest( | 92 void RecordPermissionRequest( |
| 107 ContentSettingsType permission, bool secure_origin) { | 93 ContentSettingsType permission, bool secure_origin) { |
| 108 PermissionType type; | 94 content::PermissionType type; |
| 109 switch (permission) { | 95 switch (permission) { |
| 110 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 96 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 111 type = PERMISSION_GEOLOCATION; | 97 type = content::PERMISSION_GEOLOCATION; |
| 112 break; | 98 break; |
| 113 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 99 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
| 114 type = PERMISSION_NOTIFICATIONS; | 100 type = content::PERMISSION_NOTIFICATIONS; |
| 115 break; | 101 break; |
| 116 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | 102 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
| 117 type = PERMISSION_MIDI_SYSEX; | 103 type = content::PERMISSION_MIDI_SYSEX; |
| 118 break; | 104 break; |
| 119 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: | 105 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: |
| 120 type = PERMISSION_PUSH_MESSAGING; | 106 type = content::PERMISSION_PUSH_MESSAGING; |
| 121 break; | 107 break; |
| 122 default: | 108 default: |
| 123 NOTREACHED() << "PERMISSION " << permission << " not accounted for"; | 109 NOTREACHED() << "PERMISSION " << permission << " not accounted for"; |
| 124 type = PERMISSION_UNKNOWN; | 110 return; |
| 125 } | 111 } |
| 126 UMA_HISTOGRAM_ENUMERATION( | 112 UMA_HISTOGRAM_ENUMERATION( |
| 127 "ContentSettings.PermissionRequested", | 113 "ContentSettings.PermissionRequested", type, content::PERMISSION_NUM); |
| 128 type, | |
| 129 PERMISSION_NUM); | |
| 130 if (secure_origin) { | 114 if (secure_origin) { |
| 131 UMA_HISTOGRAM_ENUMERATION( | 115 UMA_HISTOGRAM_ENUMERATION( |
| 132 "ContentSettings.PermissionRequested_SecureOrigin", | 116 "ContentSettings.PermissionRequested_SecureOrigin", |
| 133 type, | 117 type, |
| 134 PERMISSION_NUM); | 118 content::PERMISSION_NUM); |
| 135 } else { | 119 } else { |
| 136 UMA_HISTOGRAM_ENUMERATION( | 120 UMA_HISTOGRAM_ENUMERATION( |
| 137 "ContentSettings.PermissionRequested_InsecureOrigin", | 121 "ContentSettings.PermissionRequested_InsecureOrigin", |
| 138 type, | 122 type, |
| 139 PERMISSION_NUM); | 123 content::PERMISSION_NUM); |
| 140 } | 124 } |
| 141 } | 125 } |
| 142 | 126 |
| 143 } // namespace | 127 } // namespace |
| 144 | 128 |
| 145 // Make sure you update histograms.xml permission histogram_suffix if you | 129 // Make sure you update histograms.xml permission histogram_suffix if you |
| 146 // add new permission | 130 // add new permission |
| 147 void PermissionContextUmaUtil::PermissionRequested( | 131 void PermissionContextUmaUtil::PermissionRequested( |
| 148 ContentSettingsType permission, const GURL& requesting_origin) { | 132 ContentSettingsType permission, const GURL& requesting_origin) { |
| 149 RecordPermissionRequest(permission, requesting_origin.SchemeIsSecure()); | 133 RecordPermissionRequest(permission, requesting_origin.SchemeIsSecure()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 165 ContentSettingsType permission, const GURL& requesting_origin) { | 149 ContentSettingsType permission, const GURL& requesting_origin) { |
| 166 RecordPermissionAction(permission, DISMISSED, | 150 RecordPermissionAction(permission, DISMISSED, |
| 167 requesting_origin.SchemeIsSecure()); | 151 requesting_origin.SchemeIsSecure()); |
| 168 } | 152 } |
| 169 | 153 |
| 170 void PermissionContextUmaUtil::PermissionIgnored( | 154 void PermissionContextUmaUtil::PermissionIgnored( |
| 171 ContentSettingsType permission, const GURL& requesting_origin) { | 155 ContentSettingsType permission, const GURL& requesting_origin) { |
| 172 RecordPermissionAction(permission, IGNORED, | 156 RecordPermissionAction(permission, IGNORED, |
| 173 requesting_origin.SchemeIsSecure()); | 157 requesting_origin.SchemeIsSecure()); |
| 174 } | 158 } |
| OLD | NEW |