Chromium Code Reviews| Index: chrome/browser/content_settings/permission_context_uma_util.cc |
| diff --git a/chrome/browser/content_settings/permission_context_uma_util.cc b/chrome/browser/content_settings/permission_context_uma_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..800ff5dd644502c9a4cedeeaffdffd20f21bafb4 |
| --- /dev/null |
| +++ b/chrome/browser/content_settings/permission_context_uma_util.cc |
| @@ -0,0 +1,87 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/metrics/histogram.h" |
| +#include "chrome/browser/content_settings/permission_context_uma_util.h" |
| + |
| +namespace { |
| + |
| +// Enum for UMA purposes, make sure you update histograms.xml if you |
| +// add new permission actions. Never delete or reorder |
| +// an entry; only add new entries immediately before PERMISSION_NUM |
| +enum PermissionAction { |
| + REQUESTED = 0, |
| + GRANTED = 1, |
| + DENIED = 2, |
| + DISMISSED = 3, |
| + IGNORED = 4, |
| + |
| + // Always keep this at the end. |
| + PERMISSION_ACTION_NUM, |
| +}; |
| + |
| +static const char* kMidiUmaKey = "ContentSettings.PermisionActions_MidiSysEx"; |
| +static const char* kPushMessageUmaKey = |
| + "ContentSettings.PermisionActions_PushMessaging"; |
| + |
| +void PermissionUmaInternal( |
| + ContentSettingsType permission, PermissionAction action) { |
| + switch (permission) { |
| + case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| + // TODO(miguelg): support geolocation through |
| + // the generic permission class. |
| + break; |
| + case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
| + UMA_HISTOGRAM_ENUMERATION(kMidiUmaKey, |
| + action, |
| + PERMISSION_ACTION_NUM); |
| + break; |
| + case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: |
| + UMA_HISTOGRAM_ENUMERATION(kPushMessageUmaKey, |
| + action, |
| + PERMISSION_ACTION_NUM); |
| + break; |
| +#if defined(OS_ANDROID) |
| + case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: |
| + // TODO(miguelg): support protected media through |
| + // the generic permission class. |
| + break; |
| +#endif |
| + default: |
| + NOTREACHED() << "PERMISSION " << permission << " not accounted for"; |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| + |
| +// Make sure you update histograms.xml permission histogram_suffix if you |
| +// add new permission |
| +// static |
|
Bernhard Bauer
2014/07/14 15:22:15
Nit: static could come immediately before the meth
Miguel Garcia
2014/07/14 16:57:50
I removed it, it is clear from the class that they
|
| + |
| +void PermissionContextUmaUtil::PermissionRequested( |
| + ContentSettingsType permission) { |
| + PermissionUmaInternal(permission, REQUESTED); |
| +} |
| + |
| + |
| +void PermissionContextUmaUtil::PermissionGranted( |
| + ContentSettingsType permission) { |
| + PermissionUmaInternal(permission, GRANTED); |
| +} |
| + |
| +void PermissionContextUmaUtil::PermissionDenied( |
| + ContentSettingsType permission) { |
| + PermissionUmaInternal(permission, DENIED); |
| +} |
| + |
| +void PermissionContextUmaUtil::PermissionDismissed( |
| + ContentSettingsType permission) { |
| + PermissionUmaInternal(permission, DISMISSED); |
| +} |
| + |
| +void PermissionContextUmaUtil::PermissionIgnored( |
| + ContentSettingsType permission) { |
| + PermissionUmaInternal(permission, IGNORED); |
| +} |