Chromium Code Reviews| 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..e81670f767676f710f134cfe9ecc0bbcccab61f1 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() {} |
| @@ -81,42 +82,33 @@ void ContentDecryptionModuleResultPromise::completeWithError( |
| reject(WebCdmExceptionToExceptionCode(exceptionCode), result.toString()); |
| } |
| +void ContentDecryptionModuleResultPromise::contextDestroyed() { |
| + m_resolver.clear(); |
|
yhirano
2016/10/13 13:35:47
Is this needed? ScriptPromiseResolver is a Context
jrummell
2016/10/14 00:03:31
If you think it's not needed I'm happy to remove i
haraken
2016/10/14 00:05:07
This doesn't change anything. Rather, it regresses
jrummell
2016/10/14 00:41:55
Removed ContextLifecycleObserver.
|
| +} |
| + |
| ScriptPromise ContentDecryptionModuleResultPromise::promise() { |
| return m_resolver->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)); |
| - } |
| -} |
| + if (!isValidToFulfillPromise()) |
| + return; |
| -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 contextDestroyed() is called. |
| + return getExecutionContext() && |
| + !getExecutionContext()->activeDOMObjectsAreStopped(); |
|
haraken
2016/10/12 00:58:22
Alternately, can we just check m_resolver?
jrummell
2016/10/12 17:59:14
My concern is the order that objects are gc'd. Whe
haraken
2016/10/13 02:06:47
What are the "other objects"? The other objects ar
jrummell
2016/10/13 07:02:23
Currently the objects (MediaKeys and MediaKeySessi
haraken
2016/10/13 07:58:29
Fair enough.
Then let's add a comment about the d
jrummell
2016/10/14 00:03:31
Added comment to class header.
|
| } |
| DEFINE_TRACE(ContentDecryptionModuleResultPromise) { |
| visitor->trace(m_resolver); |
| ContentDecryptionModuleResult::trace(visitor); |
| + ContextLifecycleObserver::trace(visitor); |
| } |
| } // namespace blink |