[Android] Add kkimlabs@ as enhanced bookmark ONWER.
[chromium-blink-merge.git] / media / base / key_systems_support_uma.cc
blob60070263e0ba3cdf165b443c4349f97b1b386ee4
1 // Copyright 2013 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 "media/base/key_systems_support_uma.h"
8 #include "base/metrics/histogram.h"
9 #include "media/base/key_systems.h"
11 namespace media {
13 namespace {
15 const char kKeySystemSupportUMAPrefix[] = "Media.EME.KeySystemSupport.";
17 // These values are reported to UMA. Do not change the existing values!
18 enum KeySystemSupportStatus {
19 KEY_SYSTEM_QUERIED = 0,
20 KEY_SYSTEM_SUPPORTED = 1,
21 KEY_SYSTEM_WITH_TYPE_QUERIED = 2,
22 KEY_SYSTEM_WITH_TYPE_SUPPORTED = 3,
23 KEY_SYSTEM_SUPPORT_STATUS_COUNT
26 // Reports an event only once.
27 class OneTimeReporter {
28 public:
29 OneTimeReporter(const std::string& key_system, KeySystemSupportStatus status);
30 ~OneTimeReporter();
32 void Report();
34 private:
35 bool is_reported_;
36 const std::string key_system_;
37 const KeySystemSupportStatus status_;
40 OneTimeReporter::OneTimeReporter(const std::string& key_system,
41 KeySystemSupportStatus status)
42 : is_reported_(false), key_system_(key_system), status_(status) {
45 OneTimeReporter::~OneTimeReporter() {}
47 void OneTimeReporter::Report() {
48 if (is_reported_)
49 return;
51 // Not using UMA_HISTOGRAM_ENUMERATION directly because UMA_* macros require
52 // the names to be constant throughout the process' lifetime.
53 base::LinearHistogram::FactoryGet(
54 kKeySystemSupportUMAPrefix + GetKeySystemNameForUMA(key_system_), 1,
55 KEY_SYSTEM_SUPPORT_STATUS_COUNT, KEY_SYSTEM_SUPPORT_STATUS_COUNT + 1,
56 base::Histogram::kUmaTargetedHistogramFlag)->Add(status_);
58 is_reported_ = true;
61 } // namespace
63 class KeySystemsSupportUMA::Reporter {
64 public:
65 explicit Reporter(const std::string& key_system);
66 ~Reporter();
68 void Report(bool has_type, bool is_supported);
70 private:
71 const std::string key_system_;
73 OneTimeReporter call_reporter_;
74 OneTimeReporter call_with_type_reporter_;
75 OneTimeReporter support_reporter_;
76 OneTimeReporter support_with_type_reporter_;
79 KeySystemsSupportUMA::Reporter::Reporter(const std::string& key_system)
80 : key_system_(key_system),
81 call_reporter_(key_system, KEY_SYSTEM_QUERIED),
82 call_with_type_reporter_(key_system, KEY_SYSTEM_WITH_TYPE_QUERIED),
83 support_reporter_(key_system, KEY_SYSTEM_SUPPORTED),
84 support_with_type_reporter_(key_system, KEY_SYSTEM_WITH_TYPE_SUPPORTED) {}
86 KeySystemsSupportUMA::Reporter::~Reporter() {}
88 void KeySystemsSupportUMA::Reporter::Report(bool has_type, bool is_supported) {
89 call_reporter_.Report();
90 if (has_type)
91 call_with_type_reporter_.Report();
93 if (!is_supported)
94 return;
96 support_reporter_.Report();
97 if (has_type)
98 support_with_type_reporter_.Report();
101 KeySystemsSupportUMA::KeySystemsSupportUMA() {}
103 KeySystemsSupportUMA::~KeySystemsSupportUMA() {}
105 void KeySystemsSupportUMA::AddKeySystemToReport(const std::string& key_system) {
106 DCHECK(!GetReporter(key_system));
107 reporters_.set(key_system, scoped_ptr<Reporter>(new Reporter(key_system)));
110 void KeySystemsSupportUMA::ReportKeySystemQuery(const std::string& key_system,
111 bool has_type) {
112 Reporter* reporter = GetReporter(key_system);
113 if (!reporter)
114 return;
115 reporter->Report(has_type, false);
118 void KeySystemsSupportUMA::ReportKeySystemSupport(const std::string& key_system,
119 bool has_type) {
120 Reporter* reporter = GetReporter(key_system);
121 if (!reporter)
122 return;
123 reporter->Report(has_type, true);
126 KeySystemsSupportUMA::Reporter* KeySystemsSupportUMA::GetReporter(
127 const std::string& key_system) {
128 Reporters::iterator reporter = reporters_.find(key_system);
129 if (reporter == reporters_.end())
130 return NULL;
131 return reporter->second;
134 } // namespace media