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

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

Issue 2407013002: EME: Improve promise lifetime (Closed)
Patch Set: more checks 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..51ace41b38bfe1adef8e16cee88706af2d78f475 100644
--- a/third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.h
+++ b/third_party/WebKit/Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.h
@@ -19,6 +19,15 @@ ExceptionCode WebCdmExceptionToExceptionCode(
// complete(), completeWithSession(), etc. methods will reject the promise
// with an error. It needs to be subclassed and the appropriate complete()
// method overridden to resolve the promise as needed.
+//
+// Subclasses need to keep a Member<> to the object that created them so
+// that the creator remains around as long as this promise is pending. This
+// promise is not referenced by the object that created it (e.g MediaKeys,
+// MediaKeySession, Navigator.requestMediaKeySystemAccess), so this promise
+// may be cleaned up before or after it's creator once both become unreachable.
+// If it is after, the destruction of the creator may trigger this promise,
+// so use isValidToFulfillPromise() to verify that it is safe to fulfill
+// the promise.
class ContentDecryptionModuleResultPromise
: public ContentDecryptionModuleResult {
public:
@@ -46,20 +55,21 @@ class ContentDecryptionModuleResultPromise
// promise.
template <typename... T>
void resolve(T... value) {
+ DCHECK(isValidToFulfillPromise());
+
m_resolver->resolve(value...);
m_resolver.clear();
}
- // Rejects the promise with a DOMException. This will post a task to
- // actually reject the promise later on.
+ // Rejects the promise with a DOMException.
void reject(ExceptionCode, const String& errorMessage);
ExecutionContext* getExecutionContext() const;
- private:
- // Rejects the promise with a DOMException.
- void rejectInternal(ExceptionCode, const String& errorMessage);
+ // Determine if it's OK to resolve/reject this promise.
+ bool isValidToFulfillPromise();
+ private:
Member<ScriptPromiseResolver> m_resolver;
};

Powered by Google App Engine
This is Rietveld 408576698