OLD | NEW |
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 15 matching lines...) Expand all Loading... |
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 "public/platform/WebCrypto.h" | 32 #include "public/platform/WebCrypto.h" |
33 | 33 |
34 #include "platform/CryptoResult.h" | 34 #include "platform/CryptoResult.h" |
35 #include "platform/heap/Heap.h" | 35 #include "platform/heap/Heap.h" |
36 #include <string.h> | 36 #include "wtf/Atomics.h" |
37 | 37 |
38 namespace blink { | 38 namespace blink { |
39 | 39 |
40 void WebCryptoResult::completeWithError(WebCryptoErrorType errorType, const WebS
tring& errorDetails) | 40 void WebCryptoResult::completeWithError(WebCryptoErrorType errorType, const WebS
tring& errorDetails) |
41 { | 41 { |
| 42 if (cancelled()) |
| 43 return; |
42 m_impl->completeWithError(errorType, errorDetails); | 44 m_impl->completeWithError(errorType, errorDetails); |
43 reset(); | 45 clear(); |
44 } | 46 } |
45 | 47 |
46 void WebCryptoResult::completeWithBuffer(const void* bytes, unsigned bytesSize) | 48 void WebCryptoResult::completeWithBuffer(const void* bytes, unsigned bytesSize) |
47 { | 49 { |
| 50 if (cancelled()) |
| 51 return; |
48 m_impl->completeWithBuffer(bytes, bytesSize); | 52 m_impl->completeWithBuffer(bytes, bytesSize); |
49 reset(); | 53 clear(); |
50 } | 54 } |
51 | 55 |
52 void WebCryptoResult::completeWithJson(const char* utf8Data, unsigned length) | 56 void WebCryptoResult::completeWithJson(const char* utf8Data, unsigned length) |
53 { | 57 { |
| 58 if (cancelled()) |
| 59 return; |
54 m_impl->completeWithJson(utf8Data, length); | 60 m_impl->completeWithJson(utf8Data, length); |
55 reset(); | 61 clear(); |
56 } | 62 } |
57 | 63 |
58 void WebCryptoResult::completeWithBoolean(bool b) | 64 void WebCryptoResult::completeWithBoolean(bool b) |
59 { | 65 { |
| 66 if (cancelled()) |
| 67 return; |
60 m_impl->completeWithBoolean(b); | 68 m_impl->completeWithBoolean(b); |
61 reset(); | 69 clear(); |
62 } | 70 } |
63 | 71 |
64 void WebCryptoResult::completeWithKey(const WebCryptoKey& key) | 72 void WebCryptoResult::completeWithKey(const WebCryptoKey& key) |
65 { | 73 { |
| 74 if (cancelled()) |
| 75 return; |
66 ASSERT(!key.isNull()); | 76 ASSERT(!key.isNull()); |
67 m_impl->completeWithKey(key); | 77 m_impl->completeWithKey(key); |
68 reset(); | 78 clear(); |
69 } | 79 } |
70 | 80 |
71 void WebCryptoResult::completeWithKeyPair(const WebCryptoKey& publicKey, const W
ebCryptoKey& privateKey) | 81 void WebCryptoResult::completeWithKeyPair(const WebCryptoKey& publicKey, const W
ebCryptoKey& privateKey) |
72 { | 82 { |
| 83 if (cancelled()) |
| 84 return; |
73 ASSERT(!publicKey.isNull()); | 85 ASSERT(!publicKey.isNull()); |
74 ASSERT(!privateKey.isNull()); | 86 ASSERT(!privateKey.isNull()); |
75 m_impl->completeWithKeyPair(publicKey, privateKey); | 87 m_impl->completeWithKeyPair(publicKey, privateKey); |
76 reset(); | 88 clear(); |
77 } | 89 } |
78 | 90 |
79 bool WebCryptoResult::cancelled() const | 91 bool WebCryptoResult::cancelled() const |
80 { | 92 { |
81 return m_impl->cancelled(); | 93 return acquireLoad(&m_cancelled); |
82 } | 94 } |
83 | 95 |
84 WebCryptoResult::WebCryptoResult(const PassRefPtrWillBeRawPtr<CryptoResult>& imp
l) | 96 WebCryptoResult::WebCryptoResult(const PassRefPtrWillBeRawPtr<CryptoResult>& imp
l) |
85 : m_impl(impl) | 97 : m_cancelled(0) |
| 98 , m_impl(impl) |
86 { | 99 { |
87 ASSERT(m_impl.get()); | 100 ASSERT(m_impl.get()); |
| 101 m_impl->assignedTo(this); |
88 } | 102 } |
89 | 103 |
90 void WebCryptoResult::reset() | 104 void WebCryptoResult::reset() |
91 { | 105 { |
92 m_impl.reset(); | 106 m_impl.reset(); |
93 } | 107 } |
94 | 108 |
| 109 void WebCryptoResult::clear() |
| 110 { |
| 111 if (!m_impl.isNull()) { |
| 112 releaseStore(&m_cancelled, 1); |
| 113 m_impl->assignedTo(nullptr); |
| 114 } |
| 115 reset(); |
| 116 } |
| 117 |
95 void WebCryptoResult::assign(const WebCryptoResult& o) | 118 void WebCryptoResult::assign(const WebCryptoResult& o) |
96 { | 119 { |
| 120 ASSERT(!o.m_cancelled); |
| 121 ASSERT(!o.m_impl.isNull()); |
| 122 m_cancelled = o.m_cancelled; |
97 m_impl = o.m_impl; | 123 m_impl = o.m_impl; |
| 124 m_impl->assignedTo(this); |
98 } | 125 } |
99 | 126 |
100 } // namespace blink | 127 } // namespace blink |
OLD | NEW |