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 "content/renderer/media/crypto/key_systems_support_uma.h"
9 #include "content/public/renderer/render_thread.h"
10 #include "content/renderer/media/crypto/key_systems.h"
16 const char kKeySystemSupportActionPrefix
[] = "KeySystemSupport.";
18 // Reports an event only once.
19 class OneTimeReporter
{
21 OneTimeReporter(const std::string
& key_system
,
23 const std::string
& event
);
33 OneTimeReporter::OneTimeReporter(const std::string
& key_system
,
35 const std::string
& event
)
36 : is_reported_(false) {
37 action_
= kKeySystemSupportActionPrefix
+ KeySystemNameForUMA(key_system
);
39 action_
+= "WithType";
40 action_
+= '.' + event
;
43 OneTimeReporter::~OneTimeReporter() {}
45 void OneTimeReporter::Report() {
48 RenderThread::Get()->RecordComputedAction(action_
);
54 class KeySystemsSupportUMA::Reporter
{
56 explicit Reporter(const std::string
& key_system
);
59 void Report(bool has_type
, bool is_supported
);
62 const std::string key_system_
;
64 OneTimeReporter call_reporter_
;
65 OneTimeReporter call_with_type_reporter_
;
66 OneTimeReporter support_reporter_
;
67 OneTimeReporter support_with_type_reporter_
;
70 KeySystemsSupportUMA::Reporter::Reporter(const std::string
& key_system
)
71 : key_system_(key_system
),
72 call_reporter_(key_system
, false, "Queried"),
73 call_with_type_reporter_(key_system
, true, "Queried"),
74 support_reporter_(key_system
, false, "Supported"),
75 support_with_type_reporter_(key_system
, true, "Supported") {}
77 KeySystemsSupportUMA::Reporter::~Reporter() {}
79 void KeySystemsSupportUMA::Reporter::Report(bool has_type
, bool is_supported
) {
80 call_reporter_
.Report();
82 call_with_type_reporter_
.Report();
87 support_reporter_
.Report();
89 support_with_type_reporter_
.Report();
92 KeySystemsSupportUMA::KeySystemsSupportUMA() {}
94 KeySystemsSupportUMA::~KeySystemsSupportUMA() {}
96 void KeySystemsSupportUMA::AddKeySystemToReport(const std::string
& key_system
) {
97 DCHECK(!GetReporter(key_system
));
98 reporters_
.set(key_system
, scoped_ptr
<Reporter
>(new Reporter(key_system
)));
101 void KeySystemsSupportUMA::ReportKeySystemQuery(const std::string
& key_system
,
103 Reporter
* reporter
= GetReporter(key_system
);
106 reporter
->Report(has_type
, false);
109 void KeySystemsSupportUMA::ReportKeySystemSupport(const std::string
& key_system
,
111 Reporter
* reporter
= GetReporter(key_system
);
114 reporter
->Report(has_type
, true);
117 KeySystemsSupportUMA::Reporter
* KeySystemsSupportUMA::GetReporter(
118 const std::string
& key_system
) {
119 Reporters::iterator reporter
= reporters_
.find(key_system
);
120 if (reporter
== reporters_
.end())
122 return reporter
->second
;
125 } // namespace content