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

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

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 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 #ifndef ContentDecryptionModuleResultPromise_h 5 #ifndef ContentDecryptionModuleResultPromise_h
6 #define ContentDecryptionModuleResultPromise_h 6 #define ContentDecryptionModuleResultPromise_h
7 7
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "core/dom/ContextLifecycleObserver.h"
9 #include "core/dom/ExceptionCode.h" 10 #include "core/dom/ExceptionCode.h"
10 #include "platform/ContentDecryptionModuleResult.h" 11 #include "platform/ContentDecryptionModuleResult.h"
11 12
12 namespace blink { 13 namespace blink {
13 14
14 ExceptionCode WebCdmExceptionToExceptionCode( 15 ExceptionCode WebCdmExceptionToExceptionCode(
15 WebContentDecryptionModuleException); 16 WebContentDecryptionModuleException);
16 17
17 // This class wraps the promise resolver to simplify creation of 18 // This class wraps the promise resolver to simplify creation of
18 // ContentDecryptionModuleResult objects. The default implementations of the 19 // ContentDecryptionModuleResult objects. The default implementations of the
19 // complete(), completeWithSession(), etc. methods will reject the promise 20 // complete(), completeWithSession(), etc. methods will reject the promise
20 // with an error. It needs to be subclassed and the appropriate complete() 21 // with an error. It needs to be subclassed and the appropriate complete()
21 // method overridden to resolve the promise as needed. 22 // method overridden to resolve the promise as needed.
23 //
24 // Subclasses need to keep a Member<> to the object that created them so
25 // that the creator remains around as long as this promise is pending. This
26 // promise is not referenced by the object that created it (e.g MediaKeys,
27 // MediaKeySession, Navigator.requestMediaKeySystemAccess), so this promise
28 // may be cleaned up before or after it's creator once both become unreachable.
29 // If it is after, the destruction of the creator may trigger this promise,
30 // so use isValidToFulfillPromise() to verify that it is safe to fulfill
31 // the promise.
22 class ContentDecryptionModuleResultPromise 32 class ContentDecryptionModuleResultPromise
23 : public ContentDecryptionModuleResult { 33 : public ContentDecryptionModuleResult,
34 public ContextLifecycleObserver {
35 USING_GARBAGE_COLLECTED_MIXIN(ContentDecryptionModuleResultPromise);
36
24 public: 37 public:
25 ~ContentDecryptionModuleResultPromise() override; 38 ~ContentDecryptionModuleResultPromise() override;
26 39
27 // ContentDecryptionModuleResult implementation. 40 // ContentDecryptionModuleResult implementation.
28 void complete() override; 41 void complete() override;
29 void completeWithContentDecryptionModule( 42 void completeWithContentDecryptionModule(
30 WebContentDecryptionModule*) override; 43 WebContentDecryptionModule*) override;
31 void completeWithSession( 44 void completeWithSession(
32 WebContentDecryptionModuleResult::SessionStatus) override; 45 WebContentDecryptionModuleResult::SessionStatus) override;
33 void completeWithError(WebContentDecryptionModuleException, 46 void completeWithError(WebContentDecryptionModuleException,
34 unsigned long systemCode, 47 unsigned long systemCode,
35 const WebString&) override; 48 const WebString&) override;
36 49
37 // It is only valid to call this before completion. 50 // It is only valid to call this before completion.
38 ScriptPromise promise(); 51 ScriptPromise promise();
39 52
40 DECLARE_VIRTUAL_TRACE(); 53 DECLARE_VIRTUAL_TRACE();
41 54
42 protected: 55 protected:
43 explicit ContentDecryptionModuleResultPromise(ScriptState*); 56 explicit ContentDecryptionModuleResultPromise(ScriptState*);
44 57
45 // Resolves the promise with |value|. Used by subclasses to resolve the 58 // Resolves the promise with |value|. Used by subclasses to resolve the
46 // promise. 59 // promise.
47 template <typename... T> 60 template <typename... T>
48 void resolve(T... value) { 61 void resolve(T... value) {
62 DCHECK(isValidToFulfillPromise());
63
49 m_resolver->resolve(value...); 64 m_resolver->resolve(value...);
50 m_resolver.clear(); 65 m_resolver.clear();
51 } 66 }
52 67
53 // Rejects the promise with a DOMException. This will post a task to 68 // Rejects the promise with a DOMException.
54 // actually reject the promise later on.
55 void reject(ExceptionCode, const String& errorMessage); 69 void reject(ExceptionCode, const String& errorMessage);
56 70
57 ExecutionContext* getExecutionContext() const; 71 // Determine if it's OK to resolve/reject this promise.
72 bool isValidToFulfillPromise();
58 73
59 private: 74 private:
60 // Rejects the promise with a DOMException.
61 void rejectInternal(ExceptionCode, const String& errorMessage);
62
63 Member<ScriptPromiseResolver> m_resolver; 75 Member<ScriptPromiseResolver> m_resolver;
64 }; 76 };
65 77
66 } // namespace blink 78 } // namespace blink
67 79
68 #endif // ContentDecryptionModuleResultPromise_h 80 #endif // ContentDecryptionModuleResultPromise_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698