Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Unified Diff: media/blink/webencryptedmediaclient_impl.cc

Issue 881853002: Add UMA to report requests for key systems using RequestMediaKeyAccess (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lazy Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/blink/webencryptedmediaclient_impl.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/blink/webencryptedmediaclient_impl.cc
diff --git a/media/blink/webencryptedmediaclient_impl.cc b/media/blink/webencryptedmediaclient_impl.cc
index af7b7f487a99cc44cf5254257835e1d4c8fbdfe9..187892c39987e7000281caa72099548c6ca46a53 100644
--- a/media/blink/webencryptedmediaclient_impl.cc
+++ b/media/blink/webencryptedmediaclient_impl.cc
@@ -5,6 +5,7 @@
#include "webencryptedmediaclient_impl.h"
#include "base/logging.h"
+#include "base/metrics/histogram.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "media/base/key_systems.h"
@@ -17,6 +18,10 @@
namespace media {
+// These names are used by UMA.
+const char kKeySystemSupportUMAPrefix[] =
+ "Media.EME.RequestMediaKeySystemAccess.";
+
static bool IsSupportedContentType(
const std::string& key_system,
const std::string& mime_type,
@@ -130,6 +135,56 @@ static bool GetSupportedConfiguration(
return true;
}
+// Report usage of key system to UMA. There are 2 different counts logged:
+// 1. The key system is requested.
+// 2. The requested key system and options are supported.
+// Each stat is only reported once per renderer frame per key system.
+// Note that WebEncryptedMediaClientImpl is only created once by each
+// renderer frame.
+class WebEncryptedMediaClientImpl::Reporter {
+ public:
+ enum KeySystemSupportStatus {
+ KEY_SYSTEM_REQUESTED = 0,
+ KEY_SYSTEM_SUPPORTED = 1,
+ KEY_SYSTEM_SUPPORT_STATUS_COUNT
+ };
+
+ explicit Reporter(const std::string& key_system_for_uma)
+ : uma_name_(kKeySystemSupportUMAPrefix + key_system_for_uma),
+ is_request_reported_(false),
+ is_support_reported_(false) {}
+ ~Reporter() {}
+
+ void ReportRequested() {
+ if (is_request_reported_)
+ return;
+ Report(KEY_SYSTEM_REQUESTED);
+ is_request_reported_ = true;
+ }
+
+ void ReportSupported() {
+ DCHECK(is_request_reported_);
+ if (is_support_reported_)
+ return;
+ Report(KEY_SYSTEM_SUPPORTED);
+ is_support_reported_ = true;
+ }
+
+ private:
+ void Report(KeySystemSupportStatus status) {
+ // Not using UMA_HISTOGRAM_ENUMERATION directly because UMA_* macros
+ // require the names to be constant throughout the process' lifetime.
+ base::LinearHistogram::FactoryGet(
+ uma_name_, 1, KEY_SYSTEM_SUPPORT_STATUS_COUNT,
+ KEY_SYSTEM_SUPPORT_STATUS_COUNT + 1,
+ base::Histogram::kUmaTargetedHistogramFlag)->Add(status);
+ }
+
+ const std::string uma_name_;
+ bool is_request_reported_;
+ bool is_support_reported_;
+};
+
WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl(
scoped_ptr<CdmFactory> cdm_factory)
: cdm_factory_(cdm_factory.Pass()) {
@@ -154,6 +209,11 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess(
}
std::string key_system = base::UTF16ToASCII(request.keySystem());
+
+ // Report this request to the appropriate Reporter.
+ Reporter* reporter = GetReporter(key_system);
+ reporter->ReportRequested();
+
if (!IsConcreteSupportedKeySystem(key_system)) {
request.requestNotSupported("Unsupported keySystem");
return;
@@ -170,6 +230,7 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess(
const blink::WebVector<blink::WebMediaKeySystemConfiguration>&
configurations = request.supportedConfigurations();
if (configurations.isEmpty()) {
+ reporter->ReportSupported();
request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create(
request.keySystem(), request.securityOrigin(), cdm_factory_.get()));
return;
@@ -186,6 +247,7 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess(
&accumulated_configuration)) {
// TODO(sandersd): Pass the accumulated configuration along.
// http://crbug.com/447059.
+ reporter->ReportSupported();
request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create(
request.keySystem(), request.securityOrigin(), cdm_factory_.get()));
return;
@@ -197,4 +259,19 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess(
"None of the requested configurations were supported.");
}
+// Lazily create Reporters.
+WebEncryptedMediaClientImpl::Reporter* WebEncryptedMediaClientImpl::GetReporter(
+ const std::string& key_system) {
+ std::string uma_name = GetKeySystemNameForUMA(key_system);
+ Reporters::iterator reporter_lookup = reporters_.find(uma_name);
xhwang 2015/01/29 23:40:48 you can just use get().
jrummell 2015/01/30 01:54:02 Done.
+ if (reporter_lookup != reporters_.end())
+ return reporter_lookup->second;
+
+ // Reporter not found, so create one.
+ scoped_ptr<Reporter> reporter(new Reporter(uma_name));
+ Reporter* result = reporter.get();
+ reporters_.set(uma_name, reporter.Pass());
xhwang 2015/01/29 23:40:48 You can probably just return the return value of s
jrummell 2015/01/30 01:54:02 Done.
+ return result;
+}
+
} // namespace media
« no previous file with comments | « media/blink/webencryptedmediaclient_impl.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698