OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "media/base/key_systems_support_uma.h" | |
6 | |
7 #include "base/metrics/histogram.h" | |
8 #include "media/base/key_systems.h" | |
9 | |
10 namespace media { | |
11 | |
12 namespace { | |
13 | |
14 const char kKeySystemSupportUMAPrefix[] = "Media.EME.KeySystemSupport."; | |
15 | |
16 // These values are reported to UMA. Do not change the existing values! | |
17 enum KeySystemSupportStatus { | |
18 KEY_SYSTEM_QUERIED = 0, | |
19 KEY_SYSTEM_SUPPORTED = 1, | |
20 KEY_SYSTEM_WITH_TYPE_QUERIED = 2, | |
21 KEY_SYSTEM_WITH_TYPE_SUPPORTED = 3, | |
22 KEY_SYSTEM_SUPPORT_STATUS_COUNT | |
23 }; | |
24 | |
25 // Reports an event only once. | |
26 class OneTimeReporter { | |
27 public: | |
28 OneTimeReporter(const std::string& key_system, KeySystemSupportStatus status); | |
29 ~OneTimeReporter(); | |
30 | |
31 void Report(); | |
32 | |
33 private: | |
34 bool is_reported_; | |
35 const std::string key_system_; | |
36 const KeySystemSupportStatus status_; | |
37 }; | |
38 | |
39 OneTimeReporter::OneTimeReporter(const std::string& key_system, | |
40 KeySystemSupportStatus status) | |
41 : is_reported_(false), key_system_(key_system), status_(status) { | |
42 } | |
43 | |
44 OneTimeReporter::~OneTimeReporter() {} | |
45 | |
46 void OneTimeReporter::Report() { | |
47 if (is_reported_) | |
48 return; | |
49 | |
50 // Not using UMA_HISTOGRAM_ENUMERATION directly because UMA_* macros require | |
51 // the names to be constant throughout the process' lifetime. | |
52 base::LinearHistogram::FactoryGet( | |
53 kKeySystemSupportUMAPrefix + GetKeySystemNameForUMA(key_system_), 1, | |
54 KEY_SYSTEM_SUPPORT_STATUS_COUNT, KEY_SYSTEM_SUPPORT_STATUS_COUNT + 1, | |
55 base::Histogram::kUmaTargetedHistogramFlag)->Add(status_); | |
56 | |
57 is_reported_ = true; | |
58 } | |
59 | |
60 } // namespace | |
61 | |
62 class KeySystemsSupportUMA::Reporter { | |
63 public: | |
64 explicit Reporter(const std::string& key_system); | |
65 ~Reporter(); | |
66 | |
67 void Report(bool has_type, bool is_supported); | |
68 | |
69 private: | |
70 const std::string key_system_; | |
71 | |
72 OneTimeReporter call_reporter_; | |
73 OneTimeReporter call_with_type_reporter_; | |
74 OneTimeReporter support_reporter_; | |
75 OneTimeReporter support_with_type_reporter_; | |
76 }; | |
77 | |
78 KeySystemsSupportUMA::Reporter::Reporter(const std::string& key_system) | |
79 : key_system_(key_system), | |
80 call_reporter_(key_system, KEY_SYSTEM_QUERIED), | |
81 call_with_type_reporter_(key_system, KEY_SYSTEM_WITH_TYPE_QUERIED), | |
82 support_reporter_(key_system, KEY_SYSTEM_SUPPORTED), | |
83 support_with_type_reporter_(key_system, KEY_SYSTEM_WITH_TYPE_SUPPORTED) {} | |
84 | |
85 KeySystemsSupportUMA::Reporter::~Reporter() {} | |
86 | |
87 void KeySystemsSupportUMA::Reporter::Report(bool has_type, bool is_supported) { | |
88 call_reporter_.Report(); | |
89 if (has_type) | |
90 call_with_type_reporter_.Report(); | |
91 | |
92 if (!is_supported) | |
93 return; | |
94 | |
95 support_reporter_.Report(); | |
96 if (has_type) | |
97 support_with_type_reporter_.Report(); | |
98 } | |
99 | |
100 KeySystemsSupportUMA::KeySystemsSupportUMA() {} | |
101 | |
102 KeySystemsSupportUMA::~KeySystemsSupportUMA() {} | |
103 | |
104 void KeySystemsSupportUMA::AddKeySystemToReport(const std::string& key_system) { | |
105 DCHECK(!GetReporter(key_system)); | |
106 reporters_.set(key_system, scoped_ptr<Reporter>(new Reporter(key_system))); | |
107 } | |
108 | |
109 void KeySystemsSupportUMA::ReportKeySystemQuery(const std::string& key_system, | |
110 bool has_type) { | |
111 Reporter* reporter = GetReporter(key_system); | |
112 if (!reporter) | |
113 return; | |
114 reporter->Report(has_type, false); | |
115 } | |
116 | |
117 void KeySystemsSupportUMA::ReportKeySystemSupport(const std::string& key_system, | |
118 bool has_type) { | |
119 Reporter* reporter = GetReporter(key_system); | |
120 if (!reporter) | |
121 return; | |
122 reporter->Report(has_type, true); | |
123 } | |
124 | |
125 KeySystemsSupportUMA::Reporter* KeySystemsSupportUMA::GetReporter( | |
126 const std::string& key_system) { | |
127 Reporters::iterator reporter = reporters_.find(key_system); | |
128 if (reporter == reporters_.end()) | |
129 return NULL; | |
130 return reporter->second; | |
131 } | |
132 | |
133 } // namespace media | |
OLD | NEW |