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

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

Issue 2407013002: EME: Improve promise lifetime (Closed)
Patch Set: 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.
22 class ContentDecryptionModuleResultPromise 23 class ContentDecryptionModuleResultPromise
23 : public ContentDecryptionModuleResult { 24 : public ContentDecryptionModuleResult,
25 public ContextLifecycleObserver {
26 USING_GARBAGE_COLLECTED_MIXIN(ContentDecryptionModuleResultPromise);
27
24 public: 28 public:
25 ~ContentDecryptionModuleResultPromise() override; 29 ~ContentDecryptionModuleResultPromise() override;
26 30
27 // ContentDecryptionModuleResult implementation. 31 // ContentDecryptionModuleResult implementation.
28 void complete() override; 32 void complete() override;
29 void completeWithContentDecryptionModule( 33 void completeWithContentDecryptionModule(
30 WebContentDecryptionModule*) override; 34 WebContentDecryptionModule*) override;
31 void completeWithSession( 35 void completeWithSession(
32 WebContentDecryptionModuleResult::SessionStatus) override; 36 WebContentDecryptionModuleResult::SessionStatus) override;
33 void completeWithError(WebContentDecryptionModuleException, 37 void completeWithError(WebContentDecryptionModuleException,
34 unsigned long systemCode, 38 unsigned long systemCode,
35 const WebString&) override; 39 const WebString&) override;
36 40
41 // ContextLifecycleObserver implementation.
42 void contextDestroyed() override;
43
37 // It is only valid to call this before completion. 44 // It is only valid to call this before completion.
38 ScriptPromise promise(); 45 ScriptPromise promise();
39 46
40 DECLARE_VIRTUAL_TRACE(); 47 DECLARE_VIRTUAL_TRACE();
41 48
42 protected: 49 protected:
43 explicit ContentDecryptionModuleResultPromise(ScriptState*); 50 explicit ContentDecryptionModuleResultPromise(ScriptState*);
44 51
45 // Resolves the promise with |value|. Used by subclasses to resolve the 52 // Resolves the promise with |value|. Used by subclasses to resolve the
46 // promise. 53 // promise.
47 template <typename... T> 54 template <typename... T>
48 void resolve(T... value) { 55 void resolve(T... value) {
56 if (m_contextDestroyed ||
57 getExecutionContext()->activeDOMObjectsAreStopped()) {
jrummell 2016/10/10 21:06:15 I included activeDOMObjectsAreStopped() since cont
58 m_resolver.clear();
59 return;
60 }
61
49 m_resolver->resolve(value...); 62 m_resolver->resolve(value...);
50 m_resolver.clear(); 63 m_resolver.clear();
51 } 64 }
52 65
53 // Rejects the promise with a DOMException. This will post a task to 66 // Rejects the promise with a DOMException. This will post a task to
54 // actually reject the promise later on. 67 // actually reject the promise later on.
55 void reject(ExceptionCode, const String& errorMessage); 68 void reject(ExceptionCode, const String& errorMessage);
56 69
57 ExecutionContext* getExecutionContext() const; 70 private:
71 Member<ScriptPromiseResolver> m_resolver;
58 72
59 private: 73 // Set once the Context is destroyed.
60 // Rejects the promise with a DOMException. 74 bool m_contextDestroyed;
61 void rejectInternal(ExceptionCode, const String& errorMessage);
62
63 Member<ScriptPromiseResolver> m_resolver;
64 }; 75 };
65 76
66 } // namespace blink 77 } // namespace blink
67 78
68 #endif // ContentDecryptionModuleResultPromise_h 79 #endif // ContentDecryptionModuleResultPromise_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698