diff options
author | jrummell <jrummell@chromium.org> | 2015-01-30 11:10:22 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-30 19:11:38 +0000 |
commit | de870139c90af7fc5957d42c8c2b0fbb09f95591 (patch) | |
tree | 81b6983bf6ee97c41088b4345630f40e7b451b7b /media | |
parent | ed8d517fc97a8b0c3542669279b0482727255a32 (diff) | |
download | chromium_src-de870139c90af7fc5957d42c8c2b0fbb09f95591.zip chromium_src-de870139c90af7fc5957d42c8c2b0fbb09f95591.tar.gz chromium_src-de870139c90af7fc5957d42c8c2b0fbb09f95591.tar.bz2 |
Add UMA to report requests for key systems using RequestMediaKeyAccess
Adding a UMA to keep track of the number of times RequestMediaKeyAccess
is called with a particular key system, and the number of times the
request succeeds. The counts are only incremented once per renderer
frame.
BUG=351501
TEST=existing EME tests pass, verified UMA locally
Review URL: https://codereview.chromium.org/881853002
Cr-Commit-Position: refs/heads/master@{#313956}
Diffstat (limited to 'media')
-rw-r--r-- | media/blink/webencryptedmediaclient_impl.cc | 77 | ||||
-rw-r--r-- | media/blink/webencryptedmediaclient_impl.h | 17 |
2 files changed, 94 insertions, 0 deletions
diff --git a/media/blink/webencryptedmediaclient_impl.cc b/media/blink/webencryptedmediaclient_impl.cc index 0050b43..90b62d0 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" @@ -18,6 +19,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, @@ -131,6 +136,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, MediaPermission* /* media_permission */) @@ -158,6 +213,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; @@ -173,6 +233,7 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( // TODO(sandersd): Remove once Blink requires the configurations parameter for // requestMediaKeySystemAccess(). if (configurations.isEmpty()) { + reporter->ReportSupported(); request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( request.keySystem(), blink::WebMediaKeySystemConfiguration(), request.securityOrigin(), cdm_factory_.get())); @@ -185,6 +246,7 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( if (GetSupportedConfiguration(key_system, candidate, request.securityOrigin(), &accumulated_configuration)) { + reporter->ReportSupported(); request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( request.keySystem(), accumulated_configuration, request.securityOrigin(), cdm_factory_.get())); @@ -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); + Reporter* reporter = reporters_.get(uma_name); + if (reporter != nullptr) + return reporter; + + // Reporter not found, so create one. + auto result = + reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); + DCHECK(result.second); + return result.first->second; +} + } // namespace media diff --git a/media/blink/webencryptedmediaclient_impl.h b/media/blink/webencryptedmediaclient_impl.h index 7aadfc2..d101ecb 100644 --- a/media/blink/webencryptedmediaclient_impl.h +++ b/media/blink/webencryptedmediaclient_impl.h @@ -5,6 +5,9 @@ #ifndef MEDIA_BLINK_WEBENCRYPTEDMEDIACLIENT_IMPL_H_ #define MEDIA_BLINK_WEBENCRYPTEDMEDIACLIENT_IMPL_H_ +#include <string> + +#include "base/containers/scoped_ptr_hash_map.h" #include "base/memory/scoped_ptr.h" #include "media/base/cdm_factory.h" #include "media/base/media_export.h" @@ -27,6 +30,20 @@ class MEDIA_EXPORT WebEncryptedMediaClientImpl blink::WebEncryptedMediaRequest request); private: + // 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. + class Reporter; + + // Gets the Reporter for |key_system|. If it doesn't already exist, + // create one. + Reporter* GetReporter(const std::string& key_system); + + // Key system <-> Reporter map. + typedef base::ScopedPtrHashMap<std::string, Reporter> Reporters; + Reporters reporters_; + scoped_ptr<CdmFactory> cdm_factory_; }; |