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

Unified Diff: media/base/cdm_callback_promise.cc

Issue 1729063003: media: Reject pending CDM promise during destruction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/blink/cdm_result_promise.h » ('j') | media/mojo/services/mojo_cdm_promise.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/cdm_callback_promise.cc
diff --git a/media/base/cdm_callback_promise.cc b/media/base/cdm_callback_promise.cc
index 496ad1aba76ce259015c26e66cf9e8d133038910..3b2c50e0ed3388adef9e3496898e98b92e4978b4 100644
--- a/media/base/cdm_callback_promise.cc
+++ b/media/base/cdm_callback_promise.cc
@@ -4,6 +4,7 @@
#include "media/base/cdm_callback_promise.h"
+#include "base/callback_helpers.h"
#include "base/logging.h"
namespace media {
@@ -19,12 +20,19 @@ CdmCallbackPromise<T...>::CdmCallbackPromise(
template <typename... T>
CdmCallbackPromise<T...>::~CdmCallbackPromise() {
+ if (resolve_cb_.is_null() || reject_cb_.is_null())
+ return;
ddorwin 2016/02/25 19:14:12 // Promise has already been settled. ? Or just ad
+
+ std::string message =
+ "Unfulfilled promise rejected automatically during destruction.";
+ DVLOG(1) << message;
+ reject(MediaKeys::INVALID_STATE_ERROR, 0, message);
}
template <typename... T>
void CdmCallbackPromise<T...>::resolve(const T&... result) {
MarkPromiseSettled();
jrummell 2016/02/25 02:30:03 This call sets a flag to indicate that the promise
xhwang 2016/02/25 07:49:21 In CdmPromiseTemplate's destructor, I can't call r
ddorwin 2016/02/25 19:14:12 Is there still a possibility that specifications/c
- resolve_cb_.Run(result...);
+ base::ResetAndReturn(&resolve_cb_).Run(result...);
}
template <typename... T>
@@ -32,7 +40,8 @@ void CdmCallbackPromise<T...>::reject(MediaKeys::Exception exception_code,
uint32_t system_code,
const std::string& error_message) {
MarkPromiseSettled();
- reject_cb_.Run(exception_code, system_code, error_message);
+ base::ResetAndReturn(&reject_cb_)
+ .Run(exception_code, system_code, error_message);
}
// Explicit template instantiation for the Promises needed.
« no previous file with comments | « no previous file | media/blink/cdm_result_promise.h » ('j') | media/mojo/services/mojo_cdm_promise.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698