summaryrefslogtreecommitdiffstats
path: root/media/base/cdm_promise.cc
diff options
context:
space:
mode:
authorjrummell@chromium.org <jrummell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-07 08:54:25 +0000
committerjrummell@chromium.org <jrummell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-07 08:54:25 +0000
commit0dbea5feff930c613725b56c11ab9663bfe949c5 (patch)
treebfbe08b3d3cfa12e6ce402b83c986f5a41c7033b /media/base/cdm_promise.cc
parentc29f10f1305b954d7629a05cf1cc59e56b482cf1 (diff)
downloadchromium_src-0dbea5feff930c613725b56c11ab9663bfe949c5.zip
chromium_src-0dbea5feff930c613725b56c11ab9663bfe949c5.tar.gz
chromium_src-0dbea5feff930c613725b56c11ab9663bfe949c5.tar.bz2
Add Promises for EME (Chromium side)
Now that the EME-WD spec has changed to specify promises, implement them on the Chromium side. They currently get converted back to events before passing them to blink:: until the blink interface gets changed. Additional changes in this CL: 1. Pass a reference to the promise though PPAPI. 2. Roll DEPS for CDM.h to include CDM_5. 3. Update cdm_adapter to use CDM_5 (in addition to existing CDM_4). 4. Change External Clear Key to use CDM_5. 5. Since CDM_5 references sessions by the actual session id (a string, web_session_id), switch to using it rather than the previously used session_id (which is an integer, and used as a reference). BUG=358271 TEST=all existing encrypted media layout and browser tests pass Review URL: https://codereview.chromium.org/265993002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275656 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/cdm_promise.cc')
-rw-r--r--media/base/cdm_promise.cc74
1 files changed, 74 insertions, 0 deletions
diff --git a/media/base/cdm_promise.cc b/media/base/cdm_promise.cc
new file mode 100644
index 0000000..ec5e913
--- /dev/null
+++ b/media/base/cdm_promise.cc
@@ -0,0 +1,74 @@
+// 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 "media/base/cdm_promise.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+
+namespace media {
+
+CdmPromise::CdmPromise() : is_pending_(true) {
+}
+
+CdmPromise::CdmPromise(PromiseRejectedCB reject_cb)
+ : reject_cb_(reject_cb), is_pending_(true) {
+ DCHECK(!reject_cb_.is_null());
+}
+
+CdmPromise::~CdmPromise() {
+ DCHECK(!is_pending_);
+}
+
+void CdmPromise::reject(MediaKeys::Exception exception_code,
+ uint32 system_code,
+ const std::string& error_message) {
+ DCHECK(is_pending_);
+ is_pending_ = false;
+ reject_cb_.Run(exception_code, system_code, error_message);
+}
+
+template <typename T>
+CdmPromiseTemplate<T>::CdmPromiseTemplate(
+ base::Callback<void(const T&)> resolve_cb,
+ PromiseRejectedCB reject_cb)
+ : CdmPromise(reject_cb), resolve_cb_(resolve_cb) {
+ DCHECK(!resolve_cb_.is_null());
+}
+
+template <typename T>
+CdmPromiseTemplate<T>::~CdmPromiseTemplate() {
+ DCHECK(!is_pending_);
+}
+
+template <typename T>
+void CdmPromiseTemplate<T>::resolve(const T& result) {
+ DCHECK(is_pending_);
+ is_pending_ = false;
+ resolve_cb_.Run(result);
+}
+
+CdmPromiseTemplate<void>::CdmPromiseTemplate(base::Callback<void()> resolve_cb,
+ PromiseRejectedCB reject_cb)
+ : CdmPromise(reject_cb), resolve_cb_(resolve_cb) {
+ DCHECK(!resolve_cb_.is_null());
+}
+
+CdmPromiseTemplate<void>::CdmPromiseTemplate() {
+}
+
+CdmPromiseTemplate<void>::~CdmPromiseTemplate() {
+ DCHECK(!is_pending_);
+}
+
+void CdmPromiseTemplate<void>::resolve() {
+ DCHECK(is_pending_);
+ is_pending_ = false;
+ resolve_cb_.Run();
+}
+
+// Explicit template instantiation for the Promises needed.
+template class MEDIA_EXPORT CdmPromiseTemplate<std::string>;
+
+} // namespace media