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

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

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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.h
diff --git a/third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.h b/third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.h
index 104d15b4004d1686527843e6945961a750445c07..f2671a33d223478b7f66f4db20be00d02ea9fcbc 100644
--- a/third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.h
+++ b/third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.h
@@ -6,6 +6,7 @@
#define ContentDecryptionModuleResultPromise_h
#include "bindings/core/v8/ScriptPromiseResolver.h"
+#include "core/dom/ContextLifecycleObserver.h"
#include "core/dom/ExceptionCode.h"
#include "platform/ContentDecryptionModuleResult.h"
@@ -20,7 +21,10 @@ ExceptionCode WebCdmExceptionToExceptionCode(
// with an error. It needs to be subclassed and the appropriate complete()
// method overridden to resolve the promise as needed.
class ContentDecryptionModuleResultPromise
- : public ContentDecryptionModuleResult {
+ : public ContentDecryptionModuleResult,
+ public ContextLifecycleObserver {
+ USING_GARBAGE_COLLECTED_MIXIN(ContentDecryptionModuleResultPromise);
+
public:
~ContentDecryptionModuleResultPromise() override;
@@ -34,6 +38,9 @@ class ContentDecryptionModuleResultPromise
unsigned long systemCode,
const WebString&) override;
+ // ContextLifecycleObserver implementation.
+ void contextDestroyed() override;
+
// It is only valid to call this before completion.
ScriptPromise promise();
@@ -46,6 +53,9 @@ class ContentDecryptionModuleResultPromise
// promise.
template <typename... T>
void resolve(T... value) {
+ if (!isValidToFulfillPromise())
+ return;
+
m_resolver->resolve(value...);
m_resolver.clear();
}
@@ -54,12 +64,10 @@ class ContentDecryptionModuleResultPromise
// actually reject the promise later on.
xhwang 2016/10/13 19:29:58 Update this comment.
jrummell 2016/10/14 00:03:31 Done.
void reject(ExceptionCode, const String& errorMessage);
- ExecutionContext* getExecutionContext() const;
+ // Determine if it's OK to resolve/reject this promise.
+ bool isValidToFulfillPromise();
private:
- // Rejects the promise with a DOMException.
- void rejectInternal(ExceptionCode, const String& errorMessage);
-
Member<ScriptPromiseResolver> m_resolver;
};

Powered by Google App Engine
This is Rietveld 408576698