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

Unified Diff: third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.cpp

Issue 2407013002: EME: Improve promise lifetime (Closed)
Patch Set: changes Created 4 years, 2 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: third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.cpp
diff --git a/third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.cpp b/third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.cpp
index 58b35116e66ac7d09d376be848413d8994f3eb3a..84179e3dbd09ef9fdd7ea3f1813598ce8ba16022 100644
--- a/third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.cpp
+++ b/third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.cpp
@@ -41,7 +41,8 @@ ExceptionCode WebCdmExceptionToExceptionCode(
ContentDecryptionModuleResultPromise::ContentDecryptionModuleResultPromise(
ScriptState* scriptState)
- : m_resolver(ScriptPromiseResolver::create(scriptState)) {}
+ : ContextLifecycleObserver(scriptState->getExecutionContext()),
+ m_resolver(ScriptPromiseResolver::create(scriptState)) {}
ContentDecryptionModuleResultPromise::~ContentDecryptionModuleResultPromise() {}
@@ -66,6 +67,9 @@ void ContentDecryptionModuleResultPromise::completeWithError(
WebContentDecryptionModuleException exceptionCode,
unsigned long systemCode,
const WebString& errorMessage) {
+ if (!isValidToFulfillPromise())
+ return;
+
// Non-zero |systemCode| is appended to the |errorMessage|. If the
// |errorMessage| is empty, we'll report "Rejected with system code
// (systemCode)".
@@ -87,36 +91,22 @@ ScriptPromise ContentDecryptionModuleResultPromise::promise() {
void ContentDecryptionModuleResultPromise::reject(ExceptionCode code,
const String& errorMessage) {
- // Reject the promise asynchronously. This avoids problems when gc is
- // destroying objects that result in unfulfilled promises being rejected.
- // (Resolving promises is still done synchronously as there may be events
- // already posted that need to happen only after the promise is resolved.)
- // TODO(jrummell): Make resolving a promise asynchronous as well (including
- // making sure events still happen after the promise is resolved).
- if (getExecutionContext()) {
- getExecutionContext()->postTask(
- BLINK_FROM_HERE,
- createSameThreadTask(
- &ContentDecryptionModuleResultPromise::rejectInternal,
- wrapPersistent(this), code, errorMessage));
- }
-}
+ DCHECK(isValidToFulfillPromise());
yhirano 2016/10/14 01:05:25 Is this change (from PS3) correct? You once said
jrummell 2016/10/14 02:13:30 All the complete...() methods have the check for i
-void ContentDecryptionModuleResultPromise::rejectInternal(
- ExceptionCode code,
- const String& errorMessage) {
m_resolver->reject(DOMException::create(code, errorMessage));
m_resolver.clear();
}
-ExecutionContext* ContentDecryptionModuleResultPromise::getExecutionContext()
- const {
- return m_resolver->getExecutionContext();
+bool ContentDecryptionModuleResultPromise::isValidToFulfillPromise() {
+ // getExecutionContext() is no longer valid once the context is destroyed.
+ return getExecutionContext() &&
+ !getExecutionContext()->activeDOMObjectsAreStopped();
}
DEFINE_TRACE(ContentDecryptionModuleResultPromise) {
visitor->trace(m_resolver);
ContentDecryptionModuleResult::trace(visitor);
+ ContextLifecycleObserver::trace(visitor);
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698