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"
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
{
29 OneTimeReporter(const std::string
& key_system
, KeySystemSupportStatus status
);
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() {
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_
);
63 class KeySystemsSupportUMA::Reporter
{
65 explicit Reporter(const std::string
& key_system
);
68 void Report(bool has_type
, bool is_supported
);
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();
91 call_with_type_reporter_
.Report();
96 support_reporter_
.Report();
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
,
112 Reporter
* reporter
= GetReporter(key_system
);
115 reporter
->Report(has_type
, false);
118 void KeySystemsSupportUMA::ReportKeySystemSupport(const std::string
& key_system
,
120 Reporter
* reporter
= GetReporter(key_system
);
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())
131 return reporter
->second
;