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

Unified Diff: content/renderer/media/cdm_result_promise.cc

Issue 555223004: Update MediaKeys interface for EME (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rename Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/cdm_result_promise.cc
diff --git a/content/renderer/media/cdm_result_promise.cc b/content/renderer/media/cdm_result_promise.cc
new file mode 100644
index 0000000000000000000000000000000000000000..aed9bdb7bb96c42207b7d81cad252e9c83efe1b9
--- /dev/null
+++ b/content/renderer/media/cdm_result_promise.cc
@@ -0,0 +1,114 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/media/cdm_result_promise.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "third_party/WebKit/public/platform/WebString.h"
+
+namespace content {
+
+static blink::WebContentDecryptionModuleException ConvertException(
+ media::MediaKeys::Exception exception_code) {
+ switch (exception_code) {
+ case media::MediaKeys::NOT_SUPPORTED_ERROR:
+ return blink::WebContentDecryptionModuleExceptionNotSupportedError;
+ case media::MediaKeys::INVALID_STATE_ERROR:
+ return blink::WebContentDecryptionModuleExceptionInvalidStateError;
+ case media::MediaKeys::INVALID_ACCESS_ERROR:
+ return blink::WebContentDecryptionModuleExceptionInvalidAccessError;
+ case media::MediaKeys::QUOTA_EXCEEDED_ERROR:
+ return blink::WebContentDecryptionModuleExceptionQuotaExceededError;
+ case media::MediaKeys::UNKNOWN_ERROR:
+ return blink::WebContentDecryptionModuleExceptionUnknownError;
+ case media::MediaKeys::CLIENT_ERROR:
+ return blink::WebContentDecryptionModuleExceptionClientError;
+ case media::MediaKeys::OUTPUT_ERROR:
+ return blink::WebContentDecryptionModuleExceptionOutputError;
+ default:
+ NOTREACHED();
+ return blink::WebContentDecryptionModuleExceptionUnknownError;
+ }
+}
+
+template <typename T>
+CdmResultPromise<T>::CdmResultPromise(
+ blink::WebContentDecryptionModuleResult result)
+ : media::CdmPromiseTemplate<T>(
+ base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)),
+ base::Bind(&CdmResultPromise::OnReject, base::Unretained(this))),
xhwang 2014/09/25 05:11:46 This patten is a bit tricky. Might worth some docu
jrummell 2014/09/25 20:33:24 Discussed offline. Will be cleaned up in a future
+ webCDMResult_(result) {
+}
+
+template <typename T>
+CdmResultPromise<T>::CdmResultPromise(
+ blink::WebContentDecryptionModuleResult result,
+ const std::string& uma_name)
+ : media::CdmPromiseTemplate<T>(
+ base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)),
+ base::Bind(&CdmResultPromise::OnReject, base::Unretained(this)),
+ uma_name),
+ webCDMResult_(result) {
+}
xhwang 2014/09/25 05:11:46 Is it possible to only keep the version with uma_n
jrummell 2014/09/25 20:33:24 CdmPromise() does a DCHECK on uma_name if specifie
+
+template <>
+void CdmResultPromise<std::string>::OnResolve(const std::string& result) {
+ // This must be overridden in a subclass.
+ NOTIMPLEMENTED();
xhwang 2014/09/25 05:11:46 NOTREACHED
jrummell 2014/09/25 20:33:24 Done.
+}
+
+template <>
+void CdmResultPromise<media::KeyIdsVector>::OnResolve(
+ const media::KeyIdsVector& result) {
+ // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to
+ // handle the set of keys.
+ OnReject(media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not implemented.");
+}
+
+template <typename T>
+void CdmResultPromise<T>::OnReject(media::MediaKeys::Exception exception_code,
+ uint32 system_code,
+ const std::string& error_message) {
+ webCDMResult_.completeWithError(ConvertException(exception_code),
+ system_code,
+ blink::WebString::fromUTF8(error_message));
+}
+
+CdmResultPromise<void>::CdmResultPromise(
+ blink::WebContentDecryptionModuleResult result)
+ : media::CdmPromiseTemplate<void>(
+ base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)),
+ base::Bind(&CdmResultPromise::OnReject, base::Unretained(this))),
+ webCDMResult_(result) {
+}
+
+CdmResultPromise<void>::CdmResultPromise(
+ blink::WebContentDecryptionModuleResult result,
+ const std::string& uma_name)
+ : media::CdmPromiseTemplate<void>(
+ base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)),
+ base::Bind(&CdmResultPromise::OnReject, base::Unretained(this)),
+ uma_name),
+ webCDMResult_(result) {
+}
+
+void CdmResultPromise<void>::OnResolve() {
+ webCDMResult_.complete();
+}
+
+void CdmResultPromise<void>::OnReject(
+ media::MediaKeys::Exception exception_code,
+ uint32 system_code,
+ const std::string& error_message) {
+ webCDMResult_.completeWithError(ConvertException(exception_code),
+ system_code,
+ blink::WebString::fromUTF8(error_message));
+}
+
+// Explicit template instantiation for the templates needed.
+template class CdmResultPromise<std::string>;
ddorwin 2014/09/25 00:07:15 ditto - and this might allow us to avoid anyone ac
ddorwin 2014/09/25 00:16:38 Nevermind, that doesn't work with the implementati
+template class CdmResultPromise<media::KeyIdsVector>;
ddorwin 2014/09/25 00:07:15 ditto
ddorwin 2014/09/25 00:16:38 Nevermind.
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698