OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 12 matching lines...) Expand all Loading... |
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "modules/indexeddb/IDBOpenDBRequest.h" | 26 #include "modules/indexeddb/IDBOpenDBRequest.h" |
27 | 27 |
28 #include "bindings/core/v8/Nullable.h" | 28 #include "bindings/core/v8/Nullable.h" |
29 #include "core/dom/DOMException.h" | 29 #include "core/dom/DOMException.h" |
30 #include "core/dom/ExceptionCode.h" | 30 #include "core/dom/ExceptionCode.h" |
31 #include "core/dom/ExecutionContext.h" | 31 #include "core/dom/ExecutionContext.h" |
32 #include "modules/indexeddb/IDBDatabase.h" | 32 #include "modules/indexeddb/IDBDatabase.h" |
33 #include "modules/indexeddb/IDBDatabaseCallbacks.h" | |
34 #include "modules/indexeddb/IDBTracing.h" | 33 #include "modules/indexeddb/IDBTracing.h" |
35 #include "modules/indexeddb/IDBVersionChangeEvent.h" | 34 #include "modules/indexeddb/IDBVersionChangeEvent.h" |
36 #include <memory> | 35 #include <memory> |
37 | 36 |
38 using blink::WebIDBDatabase; | 37 using blink::WebIDBDatabase; |
39 | 38 |
40 namespace blink { | 39 namespace blink { |
41 | 40 |
42 IDBOpenDBRequest* IDBOpenDBRequest::create(ScriptState* scriptState, IDBDatabase
Callbacks* callbacks, int64_t transactionId, int64_t version) | 41 IDBOpenDBRequest* IDBOpenDBRequest::create(ScriptState* scriptState, int64_t tra
nsactionId, int64_t version) |
43 { | 42 { |
44 IDBOpenDBRequest* request = new IDBOpenDBRequest(scriptState, callbacks, tra
nsactionId, version); | 43 IDBOpenDBRequest* request = new IDBOpenDBRequest(scriptState, transactionId,
version); |
45 request->suspendIfNeeded(); | 44 request->suspendIfNeeded(); |
46 return request; | 45 return request; |
47 } | 46 } |
48 | 47 |
49 IDBOpenDBRequest::IDBOpenDBRequest(ScriptState* scriptState, IDBDatabaseCallback
s* callbacks, int64_t transactionId, int64_t version) | 48 IDBOpenDBRequest::IDBOpenDBRequest(ScriptState* scriptState, int64_t transaction
Id, int64_t version) |
50 : IDBRequest(scriptState, IDBAny::createNull(), nullptr) | 49 : IDBRequest(scriptState, IDBAny::createNull(), nullptr) |
51 , m_databaseCallbacks(callbacks) | |
52 , m_transactionId(transactionId) | 50 , m_transactionId(transactionId) |
53 , m_version(version) | 51 , m_version(version) |
54 { | 52 { |
55 ASSERT(!resultAsAny()); | 53 DCHECK(!resultAsAny()); |
56 } | 54 } |
57 | 55 |
58 IDBOpenDBRequest::~IDBOpenDBRequest() | 56 IDBOpenDBRequest::~IDBOpenDBRequest() |
59 { | 57 { |
60 } | 58 } |
61 | 59 |
62 DEFINE_TRACE(IDBOpenDBRequest) | 60 DEFINE_TRACE(IDBOpenDBRequest) |
63 { | 61 { |
64 visitor->trace(m_databaseCallbacks); | |
65 IDBRequest::trace(visitor); | 62 IDBRequest::trace(visitor); |
66 } | 63 } |
67 | 64 |
| 65 void IDBOpenDBRequest::setClientRequest(indexed_db::mojom::blink::DatabaseClient
AssociatedRequest clientRequest) |
| 66 { |
| 67 DCHECK(!m_clientRequest.is_pending()); |
| 68 m_clientRequest = std::move(clientRequest); |
| 69 } |
| 70 |
68 const AtomicString& IDBOpenDBRequest::interfaceName() const | 71 const AtomicString& IDBOpenDBRequest::interfaceName() const |
69 { | 72 { |
70 return EventTargetNames::IDBOpenDBRequest; | 73 return EventTargetNames::IDBOpenDBRequest; |
71 } | 74 } |
72 | 75 |
73 void IDBOpenDBRequest::onBlocked(int64_t oldVersion) | 76 void IDBOpenDBRequest::onBlocked(int64_t oldVersion) |
74 { | 77 { |
75 IDB_TRACE("IDBOpenDBRequest::onBlocked()"); | 78 IDB_TRACE("IDBOpenDBRequest::onBlocked()"); |
76 if (!shouldEnqueueEvent()) | 79 if (!shouldEnqueueEvent()) |
77 return; | 80 return; |
78 Nullable<unsigned long long> newVersionNullable = (m_version == IDBDatabaseM
etadata::DefaultVersion) ? Nullable<unsigned long long>() : Nullable<unsigned lo
ng long>(m_version); | 81 Nullable<unsigned long long> newVersionNullable = (m_version == IDBDatabaseM
etadata::DefaultVersion) ? Nullable<unsigned long long>() : Nullable<unsigned lo
ng long>(m_version); |
79 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::blocked, oldVersi
on, newVersionNullable)); | 82 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::blocked, oldVersi
on, newVersionNullable)); |
80 } | 83 } |
81 | 84 |
82 void IDBOpenDBRequest::onUpgradeNeeded(int64_t oldVersion, std::unique_ptr<WebID
BDatabase> backend, const IDBDatabaseMetadata& metadata, WebIDBDataLoss dataLoss
, String dataLossMessage) | 85 void IDBOpenDBRequest::onUpgradeNeeded(int64_t oldVersion, std::unique_ptr<WebID
BDatabase> backend, const IDBDatabaseMetadata& metadata, WebIDBDataLoss dataLoss
, String dataLossMessage) |
83 { | 86 { |
84 IDB_TRACE("IDBOpenDBRequest::onUpgradeNeeded()"); | 87 IDB_TRACE("IDBOpenDBRequest::onUpgradeNeeded()"); |
85 if (m_contextStopped || !getExecutionContext()) { | 88 if (m_contextStopped || !getExecutionContext()) { |
86 std::unique_ptr<WebIDBDatabase> db = std::move(backend); | 89 std::unique_ptr<WebIDBDatabase> db = std::move(backend); |
87 db->abort(m_transactionId); | 90 db->abort(m_transactionId); |
88 db->close(); | 91 db->close(); |
89 return; | 92 return; |
90 } | 93 } |
91 if (!shouldEnqueueEvent()) | 94 if (!shouldEnqueueEvent()) |
92 return; | 95 return; |
93 | 96 |
94 ASSERT(m_databaseCallbacks); | 97 DCHECK(m_clientRequest.is_pending()); |
95 | 98 |
96 IDBDatabase* idbDatabase = IDBDatabase::create(getExecutionContext(), std::m
ove(backend), m_databaseCallbacks.release()); | 99 IDBDatabase* idbDatabase = IDBDatabase::create(getExecutionContext(), std::m
ove(backend), std::move(m_clientRequest)); |
97 idbDatabase->setMetadata(metadata); | 100 idbDatabase->setMetadata(metadata); |
98 | 101 |
99 if (oldVersion == IDBDatabaseMetadata::NoVersion) { | 102 if (oldVersion == IDBDatabaseMetadata::NoVersion) { |
100 // This database hasn't had a version before. | 103 // This database hasn't had a version before. |
101 oldVersion = IDBDatabaseMetadata::DefaultVersion; | 104 oldVersion = IDBDatabaseMetadata::DefaultVersion; |
102 } | 105 } |
103 IDBDatabaseMetadata oldMetadata(metadata); | 106 IDBDatabaseMetadata oldMetadata(metadata); |
104 oldMetadata.version = oldVersion; | 107 oldMetadata.version = oldVersion; |
105 | 108 |
106 m_transaction = IDBTransaction::create(getScriptState(), m_transactionId, id
bDatabase, this, oldMetadata); | 109 m_transaction = IDBTransaction::create(getScriptState(), m_transactionId, id
bDatabase, this, oldMetadata); |
(...skipping 12 matching lines...) Expand all Loading... |
119 if (db) | 122 if (db) |
120 db->close(); | 123 db->close(); |
121 return; | 124 return; |
122 } | 125 } |
123 if (!shouldEnqueueEvent()) | 126 if (!shouldEnqueueEvent()) |
124 return; | 127 return; |
125 | 128 |
126 IDBDatabase* idbDatabase = nullptr; | 129 IDBDatabase* idbDatabase = nullptr; |
127 if (resultAsAny()) { | 130 if (resultAsAny()) { |
128 // Previous onUpgradeNeeded call delivered the backend. | 131 // Previous onUpgradeNeeded call delivered the backend. |
129 ASSERT(!backend.get()); | 132 DCHECK(!backend.get()); |
130 idbDatabase = resultAsAny()->idbDatabase(); | 133 idbDatabase = resultAsAny()->idbDatabase(); |
131 ASSERT(idbDatabase); | 134 DCHECK(idbDatabase); |
132 ASSERT(!m_databaseCallbacks); | 135 DCHECK(!m_clientRequest.is_pending()); |
133 } else { | 136 } else { |
134 ASSERT(backend.get()); | 137 DCHECK(backend.get()); |
135 ASSERT(m_databaseCallbacks); | 138 DCHECK(m_clientRequest.is_pending()); |
136 idbDatabase = IDBDatabase::create(getExecutionContext(), std::move(backe
nd), m_databaseCallbacks.release()); | 139 idbDatabase = IDBDatabase::create(getExecutionContext(), std::move(backe
nd), std::move(m_clientRequest)); |
137 setResult(IDBAny::create(idbDatabase)); | 140 setResult(IDBAny::create(idbDatabase)); |
138 } | 141 } |
139 idbDatabase->setMetadata(metadata); | 142 idbDatabase->setMetadata(metadata); |
140 enqueueEvent(Event::create(EventTypeNames::success)); | 143 enqueueEvent(Event::create(EventTypeNames::success)); |
141 } | 144 } |
142 | 145 |
143 void IDBOpenDBRequest::onSuccess(int64_t oldVersion) | 146 void IDBOpenDBRequest::onSuccess(int64_t oldVersion) |
144 { | 147 { |
145 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); | 148 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); |
146 if (!shouldEnqueueEvent()) | 149 if (!shouldEnqueueEvent()) |
147 return; | 150 return; |
148 if (oldVersion == IDBDatabaseMetadata::NoVersion) { | 151 if (oldVersion == IDBDatabaseMetadata::NoVersion) { |
149 // This database hasn't had an integer version before. | 152 // This database hasn't had an integer version before. |
150 oldVersion = IDBDatabaseMetadata::DefaultVersion; | 153 oldVersion = IDBDatabaseMetadata::DefaultVersion; |
151 } | 154 } |
152 setResult(IDBAny::createUndefined()); | 155 setResult(IDBAny::createUndefined()); |
153 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::success, oldVersi
on, Nullable<unsigned long long>())); | 156 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::success, oldVersi
on, Nullable<unsigned long long>())); |
154 } | 157 } |
155 | 158 |
156 bool IDBOpenDBRequest::shouldEnqueueEvent() const | 159 bool IDBOpenDBRequest::shouldEnqueueEvent() const |
157 { | 160 { |
158 if (m_contextStopped || !getExecutionContext()) | 161 if (m_contextStopped || !getExecutionContext()) |
159 return false; | 162 return false; |
160 ASSERT(m_readyState == PENDING || m_readyState == DONE); | 163 DCHECK(m_readyState == PENDING || m_readyState == DONE); |
161 if (m_requestAborted) | 164 if (m_requestAborted) |
162 return false; | 165 return false; |
163 return true; | 166 return true; |
164 } | 167 } |
165 | 168 |
166 DispatchEventResult IDBOpenDBRequest::dispatchEventInternal(Event* event) | 169 DispatchEventResult IDBOpenDBRequest::dispatchEventInternal(Event* event) |
167 { | 170 { |
168 // If the connection closed between onUpgradeNeeded and the delivery of the
"success" event, | 171 // If the connection closed between onUpgradeNeeded and the delivery of the
"success" event, |
169 // an "error" event should be fired instead. | 172 // an "error" event should be fired instead. |
170 if (event->type() == EventTypeNames::success && resultAsAny()->getType() ==
IDBAny::IDBDatabaseType && resultAsAny()->idbDatabase()->isClosePending()) { | 173 if (event->type() == EventTypeNames::success && resultAsAny()->getType() ==
IDBAny::IDBDatabaseType && resultAsAny()->idbDatabase()->isClosePending()) { |
171 dequeueEvent(event); | 174 dequeueEvent(event); |
172 setResult(nullptr); | 175 setResult(nullptr); |
173 onError(DOMException::create(AbortError, "The connection was closed.")); | 176 onError(DOMException::create(AbortError, "The connection was closed.")); |
174 return DispatchEventResult::CanceledBeforeDispatch; | 177 return DispatchEventResult::CanceledBeforeDispatch; |
175 } | 178 } |
176 | 179 |
177 return IDBRequest::dispatchEventInternal(event); | 180 return IDBRequest::dispatchEventInternal(event); |
178 } | 181 } |
179 | 182 |
180 } // namespace blink | 183 } // namespace blink |
OLD | NEW |