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

Side by Side Diff: Source/modules/crypto/CrossThreadCryptoResult.h

Issue 311733004: Introduce KeepAliveWhilePending to ScriptPromiseResolverWithContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@refactor-webmidi-initialization
Patch Set: Created 6 years, 6 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
(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 CrossThreadCryptoResult_h
6 #define CrossThreadCryptoResult_h
7
8 #include "core/dom/ExceptionCode.h"
9 #include "platform/CryptoResult.h"
10 #include "public/platform/WebCrypto.h"
11 #include "wtf/WeakPtr.h"
12
13 namespace WebCore {
14
15 // Wrapper around a Promise to notify completion of the crypto operation.
16 //
17 // CrossThreadCryptoResult<T> inherits CryptoResult, where T must inherit
18 // CryptoResult as well.
19 // The thread on which CrossThreadCryptoResult was created on is referred to as the
20 // "origin thread".
21 //
22 // * At creation time there must be an active ExecutionContext.
23 // * The CryptoResult interface must only be called from the origin thread.
24 // * addref() and deref() can be called from any thread.
25 template<typename T>
26 class CrossThreadCryptoResult FINAL : public CryptoResult {
27 public:
28 ~CrossThreadCryptoResult() { }
29
30 static PassRefPtr<CrossThreadCryptoResult> create(WeakPtr<T> result)
31 {
32 return adoptRef(new CrossThreadCryptoResult(result));
33 }
34
35 // CryptoResult implementation
36 virtual void completeWithError(blink::WebCryptoErrorType type, const blink:: WebString& message) OVERRIDE
37 {
38 if (m_result)
39 m_result->completeWithError(type, message);
40 }
41 virtual void completeWithBuffer(const blink::WebArrayBuffer& buffer) OVERRID E
42 {
43 if (m_result)
44 m_result->completeWithBuffer(buffer);
45 }
46 virtual void completeWithBoolean(bool b) OVERRIDE
47 {
48 if (m_result)
49 m_result->completeWithBoolean(b);
50 }
51 virtual void completeWithKey(const blink::WebCryptoKey& key) OVERRIDE
52 {
53 if (m_result)
54 m_result->completeWithKey(key);
55 }
56 virtual void completeWithKeyPair(const blink::WebCryptoKey& publicKey, const blink::WebCryptoKey& privateKey) OVERRIDE
57 {
58 if (m_result)
59 m_result->completeWithKeyPair(publicKey, privateKey);
60 }
61
62 private:
63 explicit CrossThreadCryptoResult(WeakPtr<T> result)
64 : m_result(result) { }
65
66 WeakPtr<T> m_result;
67 };
68
69 } // namespace WebCore
70
71 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698