Index: media/blink/webencryptedmediaclient_impl.cc |
diff --git a/media/blink/webencryptedmediaclient_impl.cc b/media/blink/webencryptedmediaclient_impl.cc |
index af7b7f487a99cc44cf5254257835e1d4c8fbdfe9..c09f90ff7c1b4e6eb72af5a9aace0f35a918a45c 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,13 @@ |
namespace media { |
+// These names are used by UMA. |
+const char kKeySystemSupportUMAPrefix[] = |
+ "Media.EME.RequestMediaKeySystemAccess."; |
+const char kClearKeyKeySystemNameForUMA[] = "ClearKey"; |
+const char kUnknownKeySystemNameForUMA[] = "Unknown"; |
+const char kWidevineKeySystemNameForUMA[] = "Widevine"; |
+ |
static bool IsSupportedContentType( |
const std::string& key_system, |
const std::string& mime_type, |
@@ -130,9 +138,62 @@ 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 process per key system. |
+// Note that WebEncryptedMediaClientImpl is only created once by each |
+// renderer process. |
+class WebEncryptedMediaClientImpl::Reporter { |
+ public: |
+ enum KeySystemSupportStatus { |
+ KEY_SYSTEM_REQUESTED = 0, |
+ KEY_SYSTEM_SUPPORTED = 1, |
+ KEY_SYSTEM_COUNT |
+ }; |
+ |
+ explicit Reporter(const std::string& key_system_for_uma) |
+ : uma_name_(kKeySystemSupportUMAPrefix + key_system_for_uma), |
+ is_requested_reported_(false), |
+ is_supported_reported_(false) {} |
+ ~Reporter() {} |
+ |
+ void ReportRequested() { |
+ if (is_requested_reported_) |
+ return; |
+ Report(KEY_SYSTEM_REQUESTED); |
+ is_requested_reported_ = true; |
+ } |
+ |
+ void ReportSupported() { |
+ if (is_supported_reported_) |
+ return; |
+ Report(KEY_SYSTEM_SUPPORTED); |
+ is_supported_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_COUNT, KEY_SYSTEM_COUNT + 1, |
+ base::Histogram::kUmaTargetedHistogramFlag)->Add(status); |
+ } |
+ |
+ const std::string uma_name_; |
+ bool is_requested_reported_; |
+ bool is_supported_reported_; |
+}; |
+ |
WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl( |
scoped_ptr<CdmFactory> cdm_factory) |
: cdm_factory_(cdm_factory.Pass()) { |
+ // Generate the possible set of UMA reporters. If this list is updated |
+ // then the appropriate list in histograms.xml needs to be updated. |
+ AddReporter(kClearKeyKeySystemNameForUMA); |
+ AddReporter(kUnknownKeySystemNameForUMA); |
+ AddReporter(kWidevineKeySystemNameForUMA); |
} |
WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() { |
@@ -154,6 +215,11 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( |
} |
std::string key_system = base::UTF16ToASCII(request.keySystem()); |
+ |
+ // Report this request to the appropriate Reporter. |
+ Reporter* reporter = LocateReporter(key_system); |
+ reporter->ReportRequested(); |
+ |
if (!IsConcreteSupportedKeySystem(key_system)) { |
request.requestNotSupported("Unsupported keySystem"); |
return; |
@@ -172,6 +238,7 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( |
if (configurations.isEmpty()) { |
request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( |
request.keySystem(), request.securityOrigin(), cdm_factory_.get())); |
+ reporter->ReportSupported(); |
return; |
} |
@@ -188,6 +255,7 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( |
// http://crbug.com/447059. |
request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( |
request.keySystem(), request.securityOrigin(), cdm_factory_.get())); |
+ reporter->ReportSupported(); |
return; |
} |
} |
@@ -197,4 +265,23 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( |
"None of the requested configurations were supported."); |
} |
+void WebEncryptedMediaClientImpl::AddReporter(const std::string& key_system) { |
+ reporters_.set(key_system, scoped_ptr<Reporter>(new Reporter(key_system))); |
+} |
+ |
+WebEncryptedMediaClientImpl::Reporter* |
+WebEncryptedMediaClientImpl::LocateReporter(const std::string& key_system) { |
+ Reporters::iterator reporter_lookup = |
+ reporters_.find(GetKeySystemNameForUMA(key_system)); |
+ |
+ if (reporter_lookup == reporters_.end()) { |
+ // All valid names should have been registered. Since we can't find one, |
+ // assume |key_system| becomes "Unknown". |
+ NOTREACHED() << "Unable to locate Reporter for " << key_system; |
+ reporter_lookup = reporters_.find(kUnknownKeySystemNameForUMA); |
+ } |
+ |
+ return reporter_lookup->second; |
+} |
+ |
} // namespace media |