Commit de870139 authored by jrummell's avatar jrummell Committed by Commit bot

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}
parent ed8d517f
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "webencryptedmediaclient_impl.h" #include "webencryptedmediaclient_impl.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "media/base/key_systems.h" #include "media/base/key_systems.h"
...@@ -18,6 +19,10 @@ ...@@ -18,6 +19,10 @@
namespace media { namespace media {
// These names are used by UMA.
const char kKeySystemSupportUMAPrefix[] =
"Media.EME.RequestMediaKeySystemAccess.";
static bool IsSupportedContentType( static bool IsSupportedContentType(
const std::string& key_system, const std::string& key_system,
const std::string& mime_type, const std::string& mime_type,
...@@ -131,6 +136,56 @@ static bool GetSupportedConfiguration( ...@@ -131,6 +136,56 @@ static bool GetSupportedConfiguration(
return true; 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( WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl(
scoped_ptr<CdmFactory> cdm_factory, scoped_ptr<CdmFactory> cdm_factory,
MediaPermission* /* media_permission */) MediaPermission* /* media_permission */)
...@@ -158,6 +213,11 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( ...@@ -158,6 +213,11 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess(
} }
std::string key_system = base::UTF16ToASCII(request.keySystem()); 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)) { if (!IsConcreteSupportedKeySystem(key_system)) {
request.requestNotSupported("Unsupported keySystem"); request.requestNotSupported("Unsupported keySystem");
return; return;
...@@ -173,6 +233,7 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( ...@@ -173,6 +233,7 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess(
// TODO(sandersd): Remove once Blink requires the configurations parameter for // TODO(sandersd): Remove once Blink requires the configurations parameter for
// requestMediaKeySystemAccess(). // requestMediaKeySystemAccess().
if (configurations.isEmpty()) { if (configurations.isEmpty()) {
reporter->ReportSupported();
request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create(
request.keySystem(), blink::WebMediaKeySystemConfiguration(), request.keySystem(), blink::WebMediaKeySystemConfiguration(),
request.securityOrigin(), cdm_factory_.get())); request.securityOrigin(), cdm_factory_.get()));
...@@ -185,6 +246,7 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( ...@@ -185,6 +246,7 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess(
if (GetSupportedConfiguration(key_system, candidate, if (GetSupportedConfiguration(key_system, candidate,
request.securityOrigin(), request.securityOrigin(),
&accumulated_configuration)) { &accumulated_configuration)) {
reporter->ReportSupported();
request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create(
request.keySystem(), accumulated_configuration, request.keySystem(), accumulated_configuration,
request.securityOrigin(), cdm_factory_.get())); request.securityOrigin(), cdm_factory_.get()));
...@@ -197,4 +259,19 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( ...@@ -197,4 +259,19 @@ void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess(
"None of the requested configurations were supported."); "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 } // namespace media
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
#ifndef MEDIA_BLINK_WEBENCRYPTEDMEDIACLIENT_IMPL_H_ #ifndef MEDIA_BLINK_WEBENCRYPTEDMEDIACLIENT_IMPL_H_
#define 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 "base/memory/scoped_ptr.h"
#include "media/base/cdm_factory.h" #include "media/base/cdm_factory.h"
#include "media/base/media_export.h" #include "media/base/media_export.h"
...@@ -27,6 +30,20 @@ class MEDIA_EXPORT WebEncryptedMediaClientImpl ...@@ -27,6 +30,20 @@ class MEDIA_EXPORT WebEncryptedMediaClientImpl
blink::WebEncryptedMediaRequest request); blink::WebEncryptedMediaRequest request);
private: 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_; scoped_ptr<CdmFactory> cdm_factory_;
}; };
......
...@@ -12472,6 +12472,16 @@ Therefore, the affected-histogram name has to have at least one dot in it. ...@@ -12472,6 +12472,16 @@ Therefore, the affected-histogram name has to have at least one dot in it.
</summary> </summary>
</histogram> </histogram>
<histogram name="Media.EME.RequestMediaKeySystemAccess"
enum="RequestMediaKeySystemAccessStatus">
<owner>sandersd@chromium.org</owner>
<summary>
Key system support query status and result, as reported by
RequestMediaKeySystemAccess. Each value will be reported at most once per
renderer process.
</summary>
</histogram>
<histogram name="Media.EME.Unknown" enum="CdmPromiseResult"> <histogram name="Media.EME.Unknown" enum="CdmPromiseResult">
<owner>sandersd@chromium.org</owner> <owner>sandersd@chromium.org</owner>
<summary> <summary>
...@@ -55777,6 +55787,11 @@ To add a new entry, add it with any value and run test to compute valid value. ...@@ -55777,6 +55787,11 @@ To add a new entry, add it with any value and run test to compute valid value.
</int> </int>
</enum> </enum>
<enum name="RequestMediaKeySystemAccessStatus" type="int">
<int value="0" label="Requested"/>
<int value="1" label="Supported"/>
</enum>
<enum name="ResolutionCategory" type="int"> <enum name="ResolutionCategory" type="int">
<int value="0" label="RESOLVE_SUCCESS"/> <int value="0" label="RESOLVE_SUCCESS"/>
<int value="1" label="RESOLVE_FAIL"/> <int value="1" label="RESOLVE_FAIL"/>
...@@ -62746,6 +62761,14 @@ To add a new entry, add it with any value and run test to compute valid value. ...@@ -62746,6 +62761,14 @@ To add a new entry, add it with any value and run test to compute valid value.
<affected-histogram name="Event.Latency.RendererImpl"/> <affected-histogram name="Event.Latency.RendererImpl"/>
</histogram_suffixes> </histogram_suffixes>
<histogram_suffixes name="RequestMediaKeySystemAccessKeySystems" separator=".">
<suffix name="ClearKey" label="Requests for the Clear Key key system."/>
<suffix name="Unknown"
label="Requests for an unknown or unsupported key system."/>
<suffix name="Widevine" label="Requests for the Widevine key system."/>
<affected-histogram name="Media.EME.RequestMediaKeySystemAccess"/>
</histogram_suffixes>
<histogram_suffixes name="ResourcePrefetchPredictorNetworkTypePrefetch" <histogram_suffixes name="ResourcePrefetchPredictorNetworkTypePrefetch"
separator="."> separator=".">
<suffix name="NotPrefetched" <suffix name="NotPrefetched"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment