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

Unified Diff: media/base/cdm_promise.cc

Issue 265993002: Add Promises for EME (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 7 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: media/base/cdm_promise.cc
diff --git a/media/base/cdm_promise.cc b/media/base/cdm_promise.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4a1ba1a8d2f44b317fef3bab52caec161c135ff3
--- /dev/null
+++ b/media/base/cdm_promise.cc
@@ -0,0 +1,67 @@
+// 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/logging.h"
+
+namespace media {
+
+template <typename T>
+CdmPromise<T>::CdmPromise(base::Callback<void(const T&)> resolve_cb,
+ PromiseRejectedCB rejected_cb)
+ : resolve_cb_(resolve_cb), rejected_cb_(rejected_cb), is_pending_(true) {
+ DCHECK(!resolve_cb_.is_null());
+ DCHECK(!rejected_cb_.is_null());
+}
+
+template <typename T>
+CdmPromise<T>::~CdmPromise() {
+ DCHECK(!is_pending_);
+}
+
+template <typename T>
+void CdmPromise<T>::resolve(const T& result) {
+ DCHECK(is_pending_);
+ is_pending_ = false;
+ resolve_cb_.Run(result);
+}
+
+template <typename T>
+void CdmPromise<T>::reject(MediaKeys::Exception exception_code,
+ uint32 system_code,
+ const std::string& error_message) {
+ DCHECK(is_pending_);
+ is_pending_ = false;
+ rejected_cb_.Run(exception_code, system_code, error_message);
+}
+
+CdmPromise<void>::CdmPromise(base::Callback<void()> resolve_cb,
+ PromiseRejectedCB rejected_cb)
+ : resolve_cb_(resolve_cb), rejected_cb_(rejected_cb), is_pending_(true) {
+}
+
+CdmPromise<void>::~CdmPromise() {
+ DCHECK(!is_pending_);
+}
+
+void CdmPromise<void>::resolve() {
+ DCHECK(is_pending_);
+ is_pending_ = false;
+ resolve_cb_.Run();
+}
+
+void CdmPromise<void>::reject(MediaKeys::Exception exception_code,
+ uint32 system_code,
+ const std::string& error_message) {
+ DCHECK(is_pending_);
+ is_pending_ = false;
+ rejected_cb_.Run(exception_code, system_code, error_message);
+}
+
+// Explicit template instantiation for the Promises needed.
+template class MEDIA_EXPORT CdmPromise<std::string>;
+template class MEDIA_EXPORT CdmPromise<void>;
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698