Index: media/blink/webencryptedmediaclient_impl.cc |
diff --git a/media/blink/webencryptedmediaclient_impl.cc b/media/blink/webencryptedmediaclient_impl.cc |
index af7b7f487a99cc44cf5254257835e1d4c8fbdfe9..7027d817fa831ca48d81347d85f7aaf0c5348a4e 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); |
+ 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 |