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

Side by Side Diff: Source/modules/crypto/CryptoResultImpl.cpp

Issue 133253002: [webcrypto] Fix TODO regarding asynchronous completion of crypto operations. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "modules/crypto/CryptoResultImpl.h" 32 #include "modules/crypto/CryptoResultImpl.h"
33 33
34 #include "bindings/v8/ScriptPromiseResolver.h" 34 #include "bindings/v8/ScriptPromiseResolver.h"
35 #include "bindings/v8/ScriptScope.h"
36 #include "bindings/v8/ScriptState.h"
35 #include "modules/crypto/Key.h" 37 #include "modules/crypto/Key.h"
36 #include "modules/crypto/KeyPair.h" 38 #include "modules/crypto/KeyPair.h"
37 #include "modules/crypto/NormalizeAlgorithm.h" 39 #include "modules/crypto/NormalizeAlgorithm.h"
38 #include "public/platform/Platform.h" 40 #include "public/platform/Platform.h"
39 #include "public/platform/WebArrayBuffer.h" 41 #include "public/platform/WebArrayBuffer.h"
40 #include "public/platform/WebCryptoAlgorithm.h" 42 #include "public/platform/WebCryptoAlgorithm.h"
41 #include "wtf/ArrayBufferView.h" 43 #include "wtf/ArrayBufferView.h"
42 44
43 namespace WebCore { 45 namespace WebCore {
44 46
45 CryptoResultImpl::~CryptoResultImpl() 47 CryptoResultImpl::~CryptoResultImpl()
46 { 48 {
47 ASSERT(m_finished); 49 ASSERT(m_finished);
48 } 50 }
49 51
50 PassRefPtr<CryptoResultImpl> CryptoResultImpl::create(ScriptPromise promise) 52 PassRefPtr<CryptoResultImpl> CryptoResultImpl::create(ScriptPromise promise)
51 { 53 {
52 return adoptRef(new CryptoResultImpl(promise)); 54 return adoptRef(new CryptoResultImpl(promise));
53 } 55 }
54 56
55 void CryptoResultImpl::completeWithError() 57 void CryptoResultImpl::completeWithError()
56 { 58 {
59 CheckValidThread();
60 ScriptScope scope(m_scriptState);
57 m_promiseResolver->reject(ScriptValue::createNull()); 61 m_promiseResolver->reject(ScriptValue::createNull());
58 finish(); 62 finish();
59 } 63 }
60 64
61 void CryptoResultImpl::completeWithBuffer(const blink::WebArrayBuffer& buffer) 65 void CryptoResultImpl::completeWithBuffer(const blink::WebArrayBuffer& buffer)
62 { 66 {
67 CheckValidThread();
68 ScriptScope scope(m_scriptState);
63 m_promiseResolver->resolve(PassRefPtr<ArrayBuffer>(buffer)); 69 m_promiseResolver->resolve(PassRefPtr<ArrayBuffer>(buffer));
64 finish(); 70 finish();
65 } 71 }
66 72
67 void CryptoResultImpl::completeWithBoolean(bool b) 73 void CryptoResultImpl::completeWithBoolean(bool b)
68 { 74 {
75 CheckValidThread();
76 ScriptScope scope(m_scriptState);
69 m_promiseResolver->resolve(ScriptValue::createBoolean(b)); 77 m_promiseResolver->resolve(ScriptValue::createBoolean(b));
70 finish(); 78 finish();
71 } 79 }
72 80
73 void CryptoResultImpl::completeWithKey(const blink::WebCryptoKey& key) 81 void CryptoResultImpl::completeWithKey(const blink::WebCryptoKey& key)
74 { 82 {
83 CheckValidThread();
84 ScriptScope scope(m_scriptState);
75 m_promiseResolver->resolve(Key::create(key)); 85 m_promiseResolver->resolve(Key::create(key));
76 finish(); 86 finish();
77 } 87 }
78 88
79 void CryptoResultImpl::completeWithKeyPair(const blink::WebCryptoKey& publicKey, const blink::WebCryptoKey& privateKey) 89 void CryptoResultImpl::completeWithKeyPair(const blink::WebCryptoKey& publicKey, const blink::WebCryptoKey& privateKey)
80 { 90 {
91 CheckValidThread();
92 ScriptScope scope(m_scriptState);
81 m_promiseResolver->resolve(KeyPair::create(publicKey, privateKey)); 93 m_promiseResolver->resolve(KeyPair::create(publicKey, privateKey));
82 finish(); 94 finish();
83 } 95 }
84 96
85 CryptoResultImpl::CryptoResultImpl(ScriptPromise promise) 97 CryptoResultImpl::CryptoResultImpl(ScriptPromise promise)
86 : m_promiseResolver(ScriptPromiseResolver::create(promise)) 98 : m_promiseResolver(ScriptPromiseResolver::create(promise))
87 , m_finished(false) { } 99 , m_scriptState(ScriptState::current())
100 #if !ASSERT_DISABLED
101 , m_owningThread(currentThread())
102 , m_finished(false)
103 #endif
104 {
105 }
88 106
89 void CryptoResultImpl::finish() 107 void CryptoResultImpl::finish()
90 { 108 {
91 ASSERT(!m_finished); 109 ASSERT(!m_finished);
110 #if !ASSERT_DISABLED
92 m_finished = true; 111 m_finished = true;
112 #endif
113 m_scriptState = 0;
114 m_promiseResolver.clear();
115 }
116
117 void CryptoResultImpl::CheckValidThread() const
118 {
119 ASSERT(m_owningThread == currentThread());
93 } 120 }
94 121
95 } // namespace WebCore 122 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698