Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: media/blink/webencryptedmediaclient_impl.cc

Issue 881853002: Add UMA to report requests for key systems using RequestMediaKeyAccess (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lazy Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/blink/webencryptedmediaclient_impl.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webencryptedmediaclient_impl.h" 5 #include "webencryptedmediaclient_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
8 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "media/base/key_systems.h" 11 #include "media/base/key_systems.h"
11 #include "net/base/mime_util.h" 12 #include "net/base/mime_util.h"
12 #include "third_party/WebKit/public/platform/WebEncryptedMediaRequest.h" 13 #include "third_party/WebKit/public/platform/WebEncryptedMediaRequest.h"
13 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h" 14 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h"
14 #include "third_party/WebKit/public/platform/WebString.h" 15 #include "third_party/WebKit/public/platform/WebString.h"
15 #include "third_party/WebKit/public/platform/WebVector.h" 16 #include "third_party/WebKit/public/platform/WebVector.h"
16 #include "webcontentdecryptionmoduleaccess_impl.h" 17 #include "webcontentdecryptionmoduleaccess_impl.h"
17 18
18 namespace media { 19 namespace media {
19 20
21 // These names are used by UMA.
22 const char kKeySystemSupportUMAPrefix[] =
23 "Media.EME.RequestMediaKeySystemAccess.";
24
20 static bool IsSupportedContentType( 25 static bool IsSupportedContentType(
21 const std::string& key_system, 26 const std::string& key_system,
22 const std::string& mime_type, 27 const std::string& mime_type,
23 const std::string& codecs) { 28 const std::string& codecs) {
24 // Per RFC 6838, "Both top-level type and subtype names are case-insensitive." 29 // Per RFC 6838, "Both top-level type and subtype names are case-insensitive."
25 // TODO(sandersd): Check that |container| matches the capability: 30 // TODO(sandersd): Check that |container| matches the capability:
26 // - audioCapabilitys: audio/mp4 or audio/webm. 31 // - audioCapabilitys: audio/mp4 or audio/webm.
27 // - videoCapabilitys: video/mp4 or video/webm. 32 // - videoCapabilitys: video/mp4 or video/webm.
28 // http://crbug.com/429781. 33 // http://crbug.com/429781.
29 std::string container = base::StringToLowerASCII(mime_type); 34 std::string container = base::StringToLowerASCII(mime_type);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 accumulated_configuration->videoCapabilities = video_capabilities; 128 accumulated_configuration->videoCapabilities = video_capabilities;
124 } 129 }
125 130
126 // TODO(sandersd): Prompt for distinctive identifiers and/or persistent state 131 // TODO(sandersd): Prompt for distinctive identifiers and/or persistent state
127 // if required. Make sure that future checks are silent. 132 // if required. Make sure that future checks are silent.
128 // http://crbug.com/446263. 133 // http://crbug.com/446263.
129 134
130 return true; 135 return true;
131 } 136 }
132 137
138 // Report usage of key system to UMA. There are 2 different counts logged:
139 // 1. The key system is requested.
140 // 2. The requested key system and options are supported.
141 // Each stat is only reported once per renderer frame per key system.
142 // Note that WebEncryptedMediaClientImpl is only created once by each
143 // renderer frame.
144 class WebEncryptedMediaClientImpl::Reporter {
145 public:
146 enum KeySystemSupportStatus {
147 KEY_SYSTEM_REQUESTED = 0,
148 KEY_SYSTEM_SUPPORTED = 1,
149 KEY_SYSTEM_SUPPORT_STATUS_COUNT
150 };
151
152 explicit Reporter(const std::string& key_system_for_uma)
153 : uma_name_(kKeySystemSupportUMAPrefix + key_system_for_uma),
154 is_request_reported_(false),
155 is_support_reported_(false) {}
156 ~Reporter() {}
157
158 void ReportRequested() {
159 if (is_request_reported_)
160 return;
161 Report(KEY_SYSTEM_REQUESTED);
162 is_request_reported_ = true;
163 }
164
165 void ReportSupported() {
166 DCHECK(is_request_reported_);
167 if (is_support_reported_)
168 return;
169 Report(KEY_SYSTEM_SUPPORTED);
170 is_support_reported_ = true;
171 }
172
173 private:
174 void Report(KeySystemSupportStatus status) {
175 // Not using UMA_HISTOGRAM_ENUMERATION directly because UMA_* macros
176 // require the names to be constant throughout the process' lifetime.
177 base::LinearHistogram::FactoryGet(
178 uma_name_, 1, KEY_SYSTEM_SUPPORT_STATUS_COUNT,
179 KEY_SYSTEM_SUPPORT_STATUS_COUNT + 1,
180 base::Histogram::kUmaTargetedHistogramFlag)->Add(status);
181 }
182
183 const std::string uma_name_;
184 bool is_request_reported_;
185 bool is_support_reported_;
186 };
187
133 WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl( 188 WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl(
134 scoped_ptr<CdmFactory> cdm_factory) 189 scoped_ptr<CdmFactory> cdm_factory)
135 : cdm_factory_(cdm_factory.Pass()) { 190 : cdm_factory_(cdm_factory.Pass()) {
136 } 191 }
137 192
138 WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() { 193 WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() {
139 } 194 }
140 195
141 void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( 196 void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess(
142 blink::WebEncryptedMediaRequest request) { 197 blink::WebEncryptedMediaRequest request) {
143 // TODO(jrummell): This should be asynchronous. 198 // TODO(jrummell): This should be asynchronous.
144 199
145 // Continued from requestMediaKeySystemAccess(), step 7, from 200 // Continued from requestMediaKeySystemAccess(), step 7, from
146 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess 201 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess
147 // 202 //
148 // 7.1 If keySystem is not one of the Key Systems supported by the user 203 // 7.1 If keySystem is not one of the Key Systems supported by the user
149 // agent, reject promise with with a new DOMException whose name is 204 // agent, reject promise with with a new DOMException whose name is
150 // NotSupportedError. String comparison is case-sensitive. 205 // NotSupportedError. String comparison is case-sensitive.
151 if (!base::IsStringASCII(request.keySystem())) { 206 if (!base::IsStringASCII(request.keySystem())) {
152 request.requestNotSupported("Only ASCII keySystems are supported"); 207 request.requestNotSupported("Only ASCII keySystems are supported");
153 return; 208 return;
154 } 209 }
155 210
156 std::string key_system = base::UTF16ToASCII(request.keySystem()); 211 std::string key_system = base::UTF16ToASCII(request.keySystem());
212
213 // Report this request to the appropriate Reporter.
214 Reporter* reporter = GetReporter(key_system);
215 reporter->ReportRequested();
216
157 if (!IsConcreteSupportedKeySystem(key_system)) { 217 if (!IsConcreteSupportedKeySystem(key_system)) {
158 request.requestNotSupported("Unsupported keySystem"); 218 request.requestNotSupported("Unsupported keySystem");
159 return; 219 return;
160 } 220 }
161 221
162 // 7.2 Let implementation be the implementation of keySystem. 222 // 7.2 Let implementation be the implementation of keySystem.
163 // 7.3 Follow the steps for the first matching condition from the following 223 // 7.3 Follow the steps for the first matching condition from the following
164 // list: 224 // list:
165 // - If supportedConfigurations was not provided, run the Is Key System 225 // - If supportedConfigurations was not provided, run the Is Key System
166 // Supported? algorithm and if successful, resolve promise with access 226 // Supported? algorithm and if successful, resolve promise with access
167 // and abort these steps. 227 // and abort these steps.
168 // TODO(sandersd): Remove pending the resolution of 228 // TODO(sandersd): Remove pending the resolution of
169 // https://github.com/w3c/encrypted-media/issues/1. 229 // https://github.com/w3c/encrypted-media/issues/1.
170 const blink::WebVector<blink::WebMediaKeySystemConfiguration>& 230 const blink::WebVector<blink::WebMediaKeySystemConfiguration>&
171 configurations = request.supportedConfigurations(); 231 configurations = request.supportedConfigurations();
172 if (configurations.isEmpty()) { 232 if (configurations.isEmpty()) {
233 reporter->ReportSupported();
173 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( 234 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create(
174 request.keySystem(), request.securityOrigin(), cdm_factory_.get())); 235 request.keySystem(), request.securityOrigin(), cdm_factory_.get()));
175 return; 236 return;
176 } 237 }
177 238
178 // - Otherwise, for each value in supportedConfigurations, run the 239 // - Otherwise, for each value in supportedConfigurations, run the
179 // GetSuppored Configuration algorithm and if successful, resolve 240 // GetSuppored Configuration algorithm and if successful, resolve
180 // promise with access and abort these steps. 241 // promise with access and abort these steps.
181 for (size_t i = 0; i < configurations.size(); i++) { 242 for (size_t i = 0; i < configurations.size(); i++) {
182 const blink::WebMediaKeySystemConfiguration& candidate = configurations[i]; 243 const blink::WebMediaKeySystemConfiguration& candidate = configurations[i];
183 blink::WebMediaKeySystemConfiguration accumulated_configuration; 244 blink::WebMediaKeySystemConfiguration accumulated_configuration;
184 if (GetSupportedConfiguration(key_system, candidate, 245 if (GetSupportedConfiguration(key_system, candidate,
185 request.securityOrigin(), 246 request.securityOrigin(),
186 &accumulated_configuration)) { 247 &accumulated_configuration)) {
187 // TODO(sandersd): Pass the accumulated configuration along. 248 // TODO(sandersd): Pass the accumulated configuration along.
188 // http://crbug.com/447059. 249 // http://crbug.com/447059.
250 reporter->ReportSupported();
189 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( 251 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create(
190 request.keySystem(), request.securityOrigin(), cdm_factory_.get())); 252 request.keySystem(), request.securityOrigin(), cdm_factory_.get()));
191 return; 253 return;
192 } 254 }
193 } 255 }
194 256
195 // 7.4 Reject promise with a new DOMException whose name is NotSupportedError. 257 // 7.4 Reject promise with a new DOMException whose name is NotSupportedError.
196 request.requestNotSupported( 258 request.requestNotSupported(
197 "None of the requested configurations were supported."); 259 "None of the requested configurations were supported.");
198 } 260 }
199 261
262 // Lazily create Reporters.
263 WebEncryptedMediaClientImpl::Reporter* WebEncryptedMediaClientImpl::GetReporter(
264 const std::string& key_system) {
265 std::string uma_name = GetKeySystemNameForUMA(key_system);
266 Reporters::iterator reporter_lookup = reporters_.find(uma_name);
xhwang 2015/01/29 23:40:48 you can just use get().
jrummell 2015/01/30 01:54:02 Done.
267 if (reporter_lookup != reporters_.end())
268 return reporter_lookup->second;
269
270 // Reporter not found, so create one.
271 scoped_ptr<Reporter> reporter(new Reporter(uma_name));
272 Reporter* result = reporter.get();
273 reporters_.set(uma_name, reporter.Pass());
xhwang 2015/01/29 23:40:48 You can probably just return the return value of s
jrummell 2015/01/30 01:54:02 Done.
274 return result;
275 }
276
200 } // namespace media 277 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/webencryptedmediaclient_impl.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698