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"
9 #include "base/metrics/histogram.h"
10 #include "media/base/key_systems.h"
16 const char kKeySystemSupportUMAPrefix
[] = "Media.EME.KeySystemSupport.";
18 // These values are reported to UMA. Do not change the existing values!
19 enum KeySystemSupportStatus
{
20 KEY_SYSTEM_QUERIED
= 0,
21 KEY_SYSTEM_SUPPORTED
= 1,
22 KEY_SYSTEM_WITH_TYPE_QUERIED
= 2,
23 KEY_SYSTEM_WITH_TYPE_SUPPORTED
= 3,
24 KEY_SYSTEM_SUPPORT_STATUS_COUNT
27 // Reports an event only once.
28 class OneTimeReporter
{
30 OneTimeReporter(const std::string
& key_system
, KeySystemSupportStatus status
);
37 const std::string key_system_
;
38 const KeySystemSupportStatus status_
;
41 OneTimeReporter::OneTimeReporter(const std::string
& key_system
,
42 KeySystemSupportStatus status
)
43 : is_reported_(false), key_system_(key_system
), status_(status
) {
46 OneTimeReporter::~OneTimeReporter() {}
48 void OneTimeReporter::Report() {
52 // Not using UMA_HISTOGRAM_ENUMERATION directly because UMA_* macros require
53 // the names to be constant throughout the process' lifetime.
54 base::LinearHistogram::FactoryGet(
55 kKeySystemSupportUMAPrefix
+ GetKeySystemNameForUMA(key_system_
), 1,
56 KEY_SYSTEM_SUPPORT_STATUS_COUNT
, KEY_SYSTEM_SUPPORT_STATUS_COUNT
+ 1,
57 base::Histogram::kUmaTargetedHistogramFlag
)->Add(status_
);
64 class KeySystemsSupportUMA::Reporter
{
66 explicit Reporter(const std::string
& key_system
);
69 void Report(bool has_type
, bool is_supported
);
72 const std::string key_system_
;
74 OneTimeReporter call_reporter_
;
75 OneTimeReporter call_with_type_reporter_
;
76 OneTimeReporter support_reporter_
;
77 OneTimeReporter support_with_type_reporter_
;
80 KeySystemsSupportUMA::Reporter::Reporter(const std::string
& key_system
)
81 : key_system_(key_system
),
82 call_reporter_(key_system
, KEY_SYSTEM_QUERIED
),
83 call_with_type_reporter_(key_system
, KEY_SYSTEM_WITH_TYPE_QUERIED
),
84 support_reporter_(key_system
, KEY_SYSTEM_SUPPORTED
),
85 support_with_type_reporter_(key_system
, KEY_SYSTEM_WITH_TYPE_SUPPORTED
) {}
87 KeySystemsSupportUMA::Reporter::~Reporter() {}
89 void KeySystemsSupportUMA::Reporter::Report(bool has_type
, bool is_supported
) {
90 call_reporter_
.Report();
92 call_with_type_reporter_
.Report();
97 support_reporter_
.Report();
99 support_with_type_reporter_
.Report();
102 KeySystemsSupportUMA::KeySystemsSupportUMA() {}
104 KeySystemsSupportUMA::~KeySystemsSupportUMA() {}
106 void KeySystemsSupportUMA::AddKeySystemToReport(const std::string
& key_system
) {
107 DCHECK(!GetReporter(key_system
));
108 reporters_
.set(key_system
, scoped_ptr
<Reporter
>(new Reporter(key_system
)));
111 void KeySystemsSupportUMA::ReportKeySystemQuery(const std::string
& key_system
,
113 Reporter
* reporter
= GetReporter(key_system
);
116 reporter
->Report(has_type
, false);
119 void KeySystemsSupportUMA::ReportKeySystemSupport(const std::string
& key_system
,
121 Reporter
* reporter
= GetReporter(key_system
);
124 reporter
->Report(has_type
, true);
127 KeySystemsSupportUMA::Reporter
* KeySystemsSupportUMA::GetReporter(
128 const std::string
& key_system
) {
129 Reporters::iterator reporter
= reporters_
.find(key_system
);
130 if (reporter
== reporters_
.end())
132 return reporter
->second
;