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

Unified Diff: media/base/media_keys_session_promise.cc

Issue 265993002: Add Promises for EME (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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/media_keys_session_promise.cc
diff --git a/media/base/media_keys_session_promise.cc b/media/base/media_keys_session_promise.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e0762910b1b29aa6800315fe7f8980fe13fc0e16
--- /dev/null
+++ b/media/base/media_keys_session_promise.cc
@@ -0,0 +1,45 @@
+// 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/media_keys_session_promise.h"
+
+namespace media {
+
+MediaKeysSessionPromise::MediaKeysSessionPromise() {}
+
+MediaKeysSessionPromise::MediaKeysSessionPromise(
+ PromiseResolvedCB resolve_cb,
+ PromiseResolvedWithSessionCB resolve_with_session_cb,
+ PromiseRejectedCB rejected_cb)
+ : resolve_cb_(resolve_cb),
+ resolve_with_session_cb_(resolve_with_session_cb),
+ rejected_cb_(rejected_cb) {
+ DCHECK(!resolve_cb.is_null() || !resolve_with_session_cb.is_null());
+ DCHECK(!rejected_cb_.is_null());
+}
+
+MediaKeysSessionPromise::~MediaKeysSessionPromise() {
xhwang 2014/05/05 20:46:42 We should be able to DCHECK that the promise is al
jrummell 2014/05/08 23:37:45 Good idea. Done.
+}
+
+void MediaKeysSessionPromise::resolve() {
+ if (!resolve_cb_.is_null())
+ resolve_cb_.Run();
+ else
+ reject("InvalidStateError", 0, std::string());
xhwang 2014/05/05 20:46:42 When could this happen? Shall we just DCHECK(!reso
jrummell 2014/05/08 23:37:45 Not needed anymore now that the classes are done b
+}
+
+void MediaKeysSessionPromise::resolve(const std::string& web_session_id) {
+ if (!resolve_with_session_cb_.is_null())
+ resolve_with_session_cb_.Run(web_session_id);
+ else
+ reject("InvalidStateError", 0, std::string());
+}
+
+void MediaKeysSessionPromise::reject(const std::string& error_name,
+ uint32 system_code,
+ const std::string& error_message) {
+ rejected_cb_.Run(error_name, system_code, error_message);
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698