Index: media/blink/webencryptedmediaclient_impl.cc |
diff --git a/media/blink/webencryptedmediaclient_impl.cc b/media/blink/webencryptedmediaclient_impl.cc |
index af7b7f487a99cc44cf5254257835e1d4c8fbdfe9..67faf25f69b8c16b8dbe9c6867f856747d401c29 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"; |
xhwang
2015/01/29 05:23:26
Can you use GetKeySystemNameForUMA(const std::stri
jrummell
2015/01/29 22:16:06
My concern was that histograms.xml needs to know a
|
+ |
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. |
xhwang
2015/01/29 05:23:25
hmm, this is not true. WebEncryptedMediaClientImpl
jrummell
2015/01/29 22:16:06
As discussed offline, once per render frame is OK.
|
+class WebEncryptedMediaClientImpl::Reporter { |
xhwang
2015/01/29 05:23:26
KeySystemsSupportUMA::Reporter is currently using
jrummell
2015/01/29 22:16:07
Acknowledged.
|
+ public: |
+ enum KeySystemSupportStatus { |
+ KEY_SYSTEM_REQUESTED = 0, |
+ KEY_SYSTEM_SUPPORTED = 1, |
+ KEY_SYSTEM_COUNT |
xhwang
2015/01/29 05:23:26
KEY_SYSTEM_COUNT is misleading, it's really KEY_SY
jrummell
2015/01/29 22:16:06
Done.
|
+ }; |
+ |
+ explicit Reporter(const std::string& key_system_for_uma) |
+ : uma_name_(kKeySystemSupportUMAPrefix + key_system_for_uma), |
+ is_requested_reported_(false), |
+ is_supported_reported_(false) {} |
xhwang
2015/01/29 05:23:26
s/requested/request
s/supported/support
jrummell
2015/01/29 22:16:07
Done.
|
+ ~Reporter() {} |
+ |
+ void ReportRequested() { |
+ if (is_requested_reported_) |
+ return; |
+ Report(KEY_SYSTEM_REQUESTED); |
+ is_requested_reported_ = true; |
+ } |
+ |
+ void ReportSupported() { |
xhwang
2015/01/29 05:23:26
DCHECK(is_requested_reported_) to make sure this i
jrummell
2015/01/29 22:16:07
Done.
|
+ 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); |
xhwang
2015/01/29 05:23:26
See comment below about lazy adding these.
jrummell
2015/01/29 22:16:07
Done.
|
} |
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 = GetReporter(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(); |
xhwang
2015/01/29 05:23:26
nit: report first, then resolve the request.
jrummell
2015/01/29 22:16:06
Done.
|
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(); |
xhwang
2015/01/29 05:23:26
ditto.
jrummell
2015/01/29 22:16:06
Done.
|
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))); |
xhwang
2015/01/29 05:23:26
nit: You can use make_scoped_ptr.
jrummell
2015/01/29 22:16:06
Not needed now.
|
+} |
+ |
+WebEncryptedMediaClientImpl::Reporter* WebEncryptedMediaClientImpl::GetReporter( |
+ 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); |
xhwang
2015/01/29 05:23:25
If you use GetKeySystemNameForUMA(), you'll get kU
jrummell
2015/01/29 22:16:07
Done.
|
+ } |
+ |
+ return reporter_lookup->second; |
+} |
+ |
} // namespace media |