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

Side by Side Diff: third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.cpp

Issue 2407013002: EME: Improve promise lifetime (Closed)
Patch Set: remove m_contextDestroyed 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/encryptedmedia/ContentDecryptionModuleResultPromise.h" 5 #include "modules/encryptedmedia/ContentDecryptionModuleResultPromise.h"
6 6
7 #include "bindings/core/v8/ScriptPromise.h" 7 #include "bindings/core/v8/ScriptPromise.h"
8 #include "bindings/core/v8/ScriptState.h" 8 #include "bindings/core/v8/ScriptState.h"
9 #include "core/dom/DOMException.h" 9 #include "core/dom/DOMException.h"
10 #include "core/dom/ExecutionContext.h" 10 #include "core/dom/ExecutionContext.h"
(...skipping 23 matching lines...) Expand all
34 // the EME spec. 34 // the EME spec.
35 return UnknownError; 35 return UnknownError;
36 } 36 }
37 37
38 NOTREACHED(); 38 NOTREACHED();
39 return UnknownError; 39 return UnknownError;
40 } 40 }
41 41
42 ContentDecryptionModuleResultPromise::ContentDecryptionModuleResultPromise( 42 ContentDecryptionModuleResultPromise::ContentDecryptionModuleResultPromise(
43 ScriptState* scriptState) 43 ScriptState* scriptState)
44 : m_resolver(ScriptPromiseResolver::create(scriptState)) {} 44 : ContextLifecycleObserver(scriptState->getExecutionContext()),
45 m_resolver(ScriptPromiseResolver::create(scriptState)) {}
45 46
46 ContentDecryptionModuleResultPromise::~ContentDecryptionModuleResultPromise() {} 47 ContentDecryptionModuleResultPromise::~ContentDecryptionModuleResultPromise() {}
47 48
48 void ContentDecryptionModuleResultPromise::complete() { 49 void ContentDecryptionModuleResultPromise::complete() {
49 NOTREACHED(); 50 NOTREACHED();
50 reject(InvalidStateError, "Unexpected completion."); 51 reject(InvalidStateError, "Unexpected completion.");
51 } 52 }
52 53
53 void ContentDecryptionModuleResultPromise::completeWithContentDecryptionModule( 54 void ContentDecryptionModuleResultPromise::completeWithContentDecryptionModule(
54 WebContentDecryptionModule* cdm) { 55 WebContentDecryptionModule* cdm) {
(...skipping 19 matching lines...) Expand all
74 if (systemCode != 0) { 75 if (systemCode != 0) {
75 if (result.isEmpty()) 76 if (result.isEmpty())
76 result.append("Rejected with system code"); 77 result.append("Rejected with system code");
77 result.append(" ("); 78 result.append(" (");
78 result.appendNumber(systemCode); 79 result.appendNumber(systemCode);
79 result.append(')'); 80 result.append(')');
80 } 81 }
81 reject(WebCdmExceptionToExceptionCode(exceptionCode), result.toString()); 82 reject(WebCdmExceptionToExceptionCode(exceptionCode), result.toString());
82 } 83 }
83 84
85 void ContentDecryptionModuleResultPromise::contextDestroyed() {
86 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.
87 }
88
84 ScriptPromise ContentDecryptionModuleResultPromise::promise() { 89 ScriptPromise ContentDecryptionModuleResultPromise::promise() {
85 return m_resolver->promise(); 90 return m_resolver->promise();
86 } 91 }
87 92
88 void ContentDecryptionModuleResultPromise::reject(ExceptionCode code, 93 void ContentDecryptionModuleResultPromise::reject(ExceptionCode code,
89 const String& errorMessage) { 94 const String& errorMessage) {
90 // Reject the promise asynchronously. This avoids problems when gc is 95 if (!isValidToFulfillPromise())
91 // destroying objects that result in unfulfilled promises being rejected. 96 return;
92 // (Resolving promises is still done synchronously as there may be events
93 // already posted that need to happen only after the promise is resolved.)
94 // TODO(jrummell): Make resolving a promise asynchronous as well (including
95 // making sure events still happen after the promise is resolved).
96 if (getExecutionContext()) {
97 getExecutionContext()->postTask(
98 BLINK_FROM_HERE,
99 createSameThreadTask(
100 &ContentDecryptionModuleResultPromise::rejectInternal,
101 wrapPersistent(this), code, errorMessage));
102 }
103 }
104 97
105 void ContentDecryptionModuleResultPromise::rejectInternal(
106 ExceptionCode code,
107 const String& errorMessage) {
108 m_resolver->reject(DOMException::create(code, errorMessage)); 98 m_resolver->reject(DOMException::create(code, errorMessage));
109 m_resolver.clear(); 99 m_resolver.clear();
110 } 100 }
111 101
112 ExecutionContext* ContentDecryptionModuleResultPromise::getExecutionContext() 102 bool ContentDecryptionModuleResultPromise::isValidToFulfillPromise() {
113 const { 103 // getExecutionContext() is no longer valid once contextDestroyed() is called.
114 return m_resolver->getExecutionContext(); 104 return getExecutionContext() &&
105 !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.
115 } 106 }
116 107
117 DEFINE_TRACE(ContentDecryptionModuleResultPromise) { 108 DEFINE_TRACE(ContentDecryptionModuleResultPromise) {
118 visitor->trace(m_resolver); 109 visitor->trace(m_resolver);
119 ContentDecryptionModuleResult::trace(visitor); 110 ContentDecryptionModuleResult::trace(visitor);
111 ContextLifecycleObserver::trace(visitor);
120 } 112 }
121 113
122 } // namespace blink 114 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698