OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "base/metrics/histogram.h" |
| 6 #include "chrome/browser/content_settings/permission_context_uma_util.h" |
| 7 |
| 8 namespace { |
| 9 |
| 10 // Enum for UMA purposes, make sure you update histograms.xml if you add new |
| 11 // permission actions. Never delete or reorder an entry; only add new entries |
| 12 // immediately before PERMISSION_NUM |
| 13 enum PermissionAction { |
| 14 GRANTED = 0, |
| 15 DENIED = 1, |
| 16 DISMISSED = 2, |
| 17 IGNORED = 3, |
| 18 |
| 19 // Always keep this at the end. |
| 20 PERMISSION_ACTION_NUM, |
| 21 }; |
| 22 |
| 23 // Enum for UMA purposes, make sure you update histograms.xml if you add new |
| 24 // permission actions. Never delete or reorder an entry; only add new entries |
| 25 // immediately before PERMISSION_NUM |
| 26 enum PermissionType { |
| 27 PERMISSION_UNKNOWN, |
| 28 PERMISSION_MIDI_SYSEX, |
| 29 PERMISSION_PUSH_MESSAGING, |
| 30 |
| 31 // Always keep this at the end. |
| 32 PERMISSION_NUM, |
| 33 }; |
| 34 |
| 35 static const char* kMidiUmaKey = "ContentSettings.PermisionActions_MidiSysEx"; |
| 36 static const char* kPushMessageUmaKey = |
| 37 "ContentSettings.PermisionActions_PushMessaging"; |
| 38 |
| 39 void RecordPermissionAction( |
| 40 ContentSettingsType permission, PermissionAction action) { |
| 41 switch (permission) { |
| 42 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 43 // TODO(miguelg): support geolocation through |
| 44 // the generic permission class. |
| 45 break; |
| 46 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
| 47 UMA_HISTOGRAM_ENUMERATION(kMidiUmaKey, |
| 48 action, |
| 49 PERMISSION_ACTION_NUM); |
| 50 break; |
| 51 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: |
| 52 UMA_HISTOGRAM_ENUMERATION(kPushMessageUmaKey, |
| 53 action, |
| 54 PERMISSION_ACTION_NUM); |
| 55 break; |
| 56 #if defined(OS_ANDROID) |
| 57 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: |
| 58 // TODO(miguelg): support protected media through |
| 59 // the generic permission class. |
| 60 break; |
| 61 #endif |
| 62 default: |
| 63 NOTREACHED() << "PERMISSION " << permission << " not accounted for"; |
| 64 } |
| 65 } |
| 66 |
| 67 void RecordPermissionRequest( |
| 68 ContentSettingsType permission) { |
| 69 PermissionType type; |
| 70 switch (permission) { |
| 71 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
| 72 type = PERMISSION_MIDI_SYSEX; |
| 73 break; |
| 74 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: |
| 75 type = PERMISSION_PUSH_MESSAGING; |
| 76 break; |
| 77 default: |
| 78 NOTREACHED() << "PERMISSION " << permission << " not accounted for"; |
| 79 type = PERMISSION_UNKNOWN; |
| 80 } |
| 81 UMA_HISTOGRAM_ENUMERATION("ContentSettings.PermissionRequested", type, |
| 82 PERMISSION_NUM); |
| 83 } |
| 84 |
| 85 } // namespace |
| 86 |
| 87 // Make sure you update histograms.xml permission histogram_suffix if you |
| 88 // add new permission |
| 89 void PermissionContextUmaUtil::PermissionRequested( |
| 90 ContentSettingsType permission) { |
| 91 RecordPermissionRequest(permission); |
| 92 } |
| 93 |
| 94 void PermissionContextUmaUtil::PermissionGranted( |
| 95 ContentSettingsType permission) { |
| 96 RecordPermissionAction(permission, GRANTED); |
| 97 } |
| 98 |
| 99 void PermissionContextUmaUtil::PermissionDenied( |
| 100 ContentSettingsType permission) { |
| 101 RecordPermissionAction(permission, DENIED); |
| 102 } |
| 103 |
| 104 void PermissionContextUmaUtil::PermissionDismissed( |
| 105 ContentSettingsType permission) { |
| 106 RecordPermissionAction(permission, DISMISSED); |
| 107 } |
| 108 |
| 109 void PermissionContextUmaUtil::PermissionIgnored( |
| 110 ContentSettingsType permission) { |
| 111 RecordPermissionAction(permission, IGNORED); |
| 112 } |
OLD | NEW |