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

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

Issue 687533004: Simplify use of ContentDecryptionModuleResult with promises (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Changes Created 6 years, 1 month 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
« no previous file with comments | « no previous file | Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef ContentDecryptionModuleResultPromise_h
6 #define ContentDecryptionModuleResultPromise_h
7
8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "core/dom/ExceptionCode.h"
10 #include "platform/ContentDecryptionModuleResult.h"
11
12 namespace blink {
13
14 ExceptionCode WebCdmExceptionToExceptionCode(WebContentDecryptionModuleException );
15
16 // This class wraps the promise resolver to simplify creation of
17 // ContentDecryptionModuleResult objects. The default implementations of the
18 // complete(), completeWithSession(), etc. methods will reject the promise
19 // with an error. It needs to be subclassed and the appropriate complete()
20 // method overridden to resolve the promise as needed.
21 class ContentDecryptionModuleResultPromise : public ContentDecryptionModuleResul t {
22 public:
23 virtual ~ContentDecryptionModuleResultPromise();
24
25 // ContentDecryptionModuleResult implementation.
26 virtual void complete() override;
27 virtual void completeWithSession(WebContentDecryptionModuleResult::SessionSt atus) override;
28 virtual void completeWithError(WebContentDecryptionModuleException, unsigned long systemCode, const WebString&) final;
29
30 // It is only valid to call this before completion.
31 ScriptPromise promise();
32
33 virtual void trace(Visitor*);
34
35 protected:
36 explicit ContentDecryptionModuleResultPromise(ScriptState*);
37
38 // Resolves the promise with |value|. Used by subclasses to resolve the
39 // promise.
40 template <typename... T>
41 void resolve(T... value)
42 {
43 m_resolver->resolve(value...);
44 m_resolver.clear();
45 }
46
47 // Rejects the promise with a DOMException.
48 void reject(ExceptionCode, const String& errorMessage);
49
50 ExecutionContext* executionContext() const;
51
52 private:
53 RefPtr<ScriptPromiseResolver> m_resolver;
54 };
55
56 } // namespace blink
57
58 #endif // ContentDecryptionModuleResultPromise_h
OLDNEW
« no previous file with comments | « no previous file | Source/modules/encryptedmedia/ContentDecryptionModuleResultPromise.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698