OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 #include "bindings/core/v8/ExceptionState.h" | 28 #include "bindings/core/v8/ExceptionState.h" |
29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
30 #include "bindings/core/v8/V8PerIsolateData.h" | 30 #include "bindings/core/v8/V8PerIsolateData.h" |
31 #include "core/dom/DOMException.h" | 31 #include "core/dom/DOMException.h" |
32 #include "core/dom/ExceptionCode.h" | 32 #include "core/dom/ExceptionCode.h" |
33 #include "core/dom/ExecutionContext.h" | 33 #include "core/dom/ExecutionContext.h" |
34 #include "core/events/EventQueue.h" | 34 #include "core/events/EventQueue.h" |
35 #include "modules/IndexedDBNames.h" | 35 #include "modules/IndexedDBNames.h" |
36 #include "modules/indexeddb/IDBDatabase.h" | 36 #include "modules/indexeddb/IDBDatabase.h" |
| 37 #include "modules/indexeddb/IDBDatabaseProxy.h" |
37 #include "modules/indexeddb/IDBEventDispatcher.h" | 38 #include "modules/indexeddb/IDBEventDispatcher.h" |
38 #include "modules/indexeddb/IDBIndex.h" | 39 #include "modules/indexeddb/IDBIndex.h" |
39 #include "modules/indexeddb/IDBObjectStore.h" | 40 #include "modules/indexeddb/IDBObjectStore.h" |
40 #include "modules/indexeddb/IDBOpenDBRequest.h" | 41 #include "modules/indexeddb/IDBOpenDBRequest.h" |
41 #include "modules/indexeddb/IDBTracing.h" | 42 #include "modules/indexeddb/IDBTracing.h" |
42 #include "wtf/PtrUtil.h" | 43 #include "wtf/PtrUtil.h" |
43 #include <memory> | 44 #include <memory> |
44 | 45 |
45 using blink::WebIDBDatabase; | 46 using indexed_db::mojom::blink::TransactionMode; |
46 | 47 |
47 namespace blink { | 48 namespace blink { |
48 | 49 |
49 IDBTransaction* IDBTransaction::create(ScriptState* scriptState, int64_t id, con
st HashSet<String>& objectStoreNames, WebIDBTransactionMode mode, IDBDatabase* d
b) | 50 IDBTransaction* IDBTransaction::create(ScriptState* scriptState, int64_t id, con
st HashSet<String>& objectStoreNames, TransactionMode mode, IDBDatabase* db) |
50 { | 51 { |
51 IDBOpenDBRequest* openDBRequest = nullptr; | 52 IDBOpenDBRequest* openDBRequest = nullptr; |
52 IDBTransaction* transaction = new IDBTransaction(scriptState, id, objectStor
eNames, mode, db, openDBRequest, IDBDatabaseMetadata()); | 53 IDBTransaction* transaction = new IDBTransaction(scriptState, id, objectStor
eNames, mode, db, openDBRequest, IDBDatabaseMetadata()); |
53 transaction->suspendIfNeeded(); | 54 transaction->suspendIfNeeded(); |
54 return transaction; | 55 return transaction; |
55 } | 56 } |
56 | 57 |
57 IDBTransaction* IDBTransaction::create(ScriptState* scriptState, int64_t id, IDB
Database* db, IDBOpenDBRequest* openDBRequest, const IDBDatabaseMetadata& previo
usMetadata) | 58 IDBTransaction* IDBTransaction::create(ScriptState* scriptState, int64_t id, IDB
Database* db, IDBOpenDBRequest* openDBRequest, const IDBDatabaseMetadata& previo
usMetadata) |
58 { | 59 { |
59 IDBTransaction* transaction = new IDBTransaction(scriptState, id, HashSet<St
ring>(), WebIDBTransactionModeVersionChange, db, openDBRequest, previousMetadata
); | 60 IDBTransaction* transaction = new IDBTransaction(scriptState, id, HashSet<St
ring>(), TransactionMode::VersionChange, db, openDBRequest, previousMetadata); |
60 transaction->suspendIfNeeded(); | 61 transaction->suspendIfNeeded(); |
61 return transaction; | 62 return transaction; |
62 } | 63 } |
63 | 64 |
64 namespace { | 65 namespace { |
65 | 66 |
66 class DeactivateTransactionTask : public V8PerIsolateData::EndOfScopeTask { | 67 class DeactivateTransactionTask : public V8PerIsolateData::EndOfScopeTask { |
67 public: | 68 public: |
68 static std::unique_ptr<DeactivateTransactionTask> create(IDBTransaction* tra
nsaction) | 69 static std::unique_ptr<DeactivateTransactionTask> create(IDBTransaction* tra
nsaction) |
69 { | 70 { |
70 return wrapUnique(new DeactivateTransactionTask(transaction)); | 71 return wrapUnique(new DeactivateTransactionTask(transaction)); |
71 } | 72 } |
72 | 73 |
73 void run() override | 74 void run() override |
74 { | 75 { |
75 m_transaction->setActive(false); | 76 m_transaction->setActive(false); |
76 m_transaction.clear(); | 77 m_transaction.clear(); |
77 } | 78 } |
78 | 79 |
79 private: | 80 private: |
80 explicit DeactivateTransactionTask(IDBTransaction* transaction) | 81 explicit DeactivateTransactionTask(IDBTransaction* transaction) |
81 : m_transaction(transaction) { } | 82 : m_transaction(transaction) { } |
82 | 83 |
83 Persistent<IDBTransaction> m_transaction; | 84 Persistent<IDBTransaction> m_transaction; |
84 }; | 85 }; |
85 | 86 |
86 } // namespace | 87 } // namespace |
87 | 88 |
88 IDBTransaction::IDBTransaction(ScriptState* scriptState, int64_t id, const HashS
et<String>& objectStoreNames, WebIDBTransactionMode mode, IDBDatabase* db, IDBOp
enDBRequest* openDBRequest, const IDBDatabaseMetadata& previousMetadata) | 89 IDBTransaction::IDBTransaction(ScriptState* scriptState, int64_t id, const HashS
et<String>& objectStoreNames, TransactionMode mode, IDBDatabase* db, IDBOpenDBRe
quest* openDBRequest, const IDBDatabaseMetadata& previousMetadata) |
89 : ActiveScriptWrappable(this) | 90 : ActiveScriptWrappable(this) |
90 , ActiveDOMObject(scriptState->getExecutionContext()) | 91 , ActiveDOMObject(scriptState->getExecutionContext()) |
91 , m_id(id) | 92 , m_id(id) |
92 , m_database(db) | 93 , m_database(db) |
93 , m_objectStoreNames(objectStoreNames) | 94 , m_objectStoreNames(objectStoreNames) |
94 , m_openDBRequest(openDBRequest) | 95 , m_openDBRequest(openDBRequest) |
95 , m_mode(mode) | 96 , m_mode(mode) |
96 , m_previousMetadata(previousMetadata) | 97 , m_previousMetadata(previousMetadata) |
97 { | 98 { |
98 if (mode == WebIDBTransactionModeVersionChange) { | 99 if (mode == TransactionMode::VersionChange) { |
99 // Not active until the callback. | 100 // Not active until the callback. |
100 m_state = Inactive; | 101 m_state = Inactive; |
101 } | 102 } |
102 | 103 |
103 if (m_state == Active) | 104 if (m_state == Active) |
104 V8PerIsolateData::from(scriptState->isolate())->addEndOfScopeTask(Deacti
vateTransactionTask::create(this)); | 105 V8PerIsolateData::from(scriptState->isolate())->addEndOfScopeTask(Deacti
vateTransactionTask::create(this)); |
105 m_database->transactionCreated(this); | 106 m_database->transactionCreated(this); |
106 } | 107 } |
107 | 108 |
108 IDBTransaction::~IDBTransaction() | 109 IDBTransaction::~IDBTransaction() |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 193 } |
193 | 194 |
194 void IDBTransaction::setActive(bool active) | 195 void IDBTransaction::setActive(bool active) |
195 { | 196 { |
196 DCHECK_NE(m_state, Finished) << "A finished transaction tried to setActive("
<< (active ? "true" : "false") << ")"; | 197 DCHECK_NE(m_state, Finished) << "A finished transaction tried to setActive("
<< (active ? "true" : "false") << ")"; |
197 if (m_state == Finishing) | 198 if (m_state == Finishing) |
198 return; | 199 return; |
199 ASSERT(active != (m_state == Active)); | 200 ASSERT(active != (m_state == Active)); |
200 m_state = active ? Active : Inactive; | 201 m_state = active ? Active : Inactive; |
201 | 202 |
202 if (!active && m_requestList.isEmpty() && backendDB()) | 203 if (!active && m_requestList.isEmpty() && backendDB()) { |
203 backendDB()->commit(m_id); | 204 backendDB()->Commit(m_id); |
| 205 } |
204 } | 206 } |
205 | 207 |
206 void IDBTransaction::abort(ExceptionState& exceptionState) | 208 void IDBTransaction::abort(ExceptionState& exceptionState) |
207 { | 209 { |
208 if (m_state == Finishing || m_state == Finished) { | 210 if (m_state == Finishing || m_state == Finished) { |
209 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::transac
tionFinishedErrorMessage); | 211 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::transac
tionFinishedErrorMessage); |
210 return; | 212 return; |
211 } | 213 } |
212 | 214 |
213 m_state = Finishing; | 215 m_state = Finishing; |
214 | 216 |
215 if (m_contextStopped) | 217 if (m_contextStopped) |
216 return; | 218 return; |
217 | 219 |
218 for (IDBRequest* request : m_requestList) | 220 for (IDBRequest* request : m_requestList) |
219 request->abort(); | 221 request->abort(); |
220 m_requestList.clear(); | 222 m_requestList.clear(); |
221 | 223 |
222 for (IDBObjectStore* store : m_createdObjectStores) { | 224 for (IDBObjectStore* store : m_createdObjectStores) { |
223 store->abort(); | 225 store->abort(); |
224 store->markDeleted(); | 226 store->markDeleted(); |
225 } | 227 } |
226 | 228 |
227 if (backendDB()) | 229 if (backendDB()) |
228 backendDB()->abort(m_id); | 230 backendDB()->Abort(m_id); |
229 } | 231 } |
230 | 232 |
231 void IDBTransaction::registerRequest(IDBRequest* request) | 233 void IDBTransaction::registerRequest(IDBRequest* request) |
232 { | 234 { |
233 ASSERT(request); | 235 ASSERT(request); |
234 ASSERT(m_state == Active); | 236 ASSERT(m_state == Active); |
235 m_requestList.add(request); | 237 m_requestList.add(request); |
236 } | 238 } |
237 | 239 |
238 void IDBTransaction::unregisterRequest(IDBRequest* request) | 240 void IDBTransaction::unregisterRequest(IDBRequest* request) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 } | 307 } |
306 | 308 |
307 bool IDBTransaction::hasPendingActivity() const | 309 bool IDBTransaction::hasPendingActivity() const |
308 { | 310 { |
309 // FIXME: In an ideal world, we should return true as long as anyone has a o
r can | 311 // FIXME: In an ideal world, we should return true as long as anyone has a o
r can |
310 // get a handle to us or any child request object and any of those ha
ve | 312 // get a handle to us or any child request object and any of those ha
ve |
311 // event listeners. This is in order to handle user generated events
properly. | 313 // event listeners. This is in order to handle user generated events
properly. |
312 return m_hasPendingActivity && !m_contextStopped; | 314 return m_hasPendingActivity && !m_contextStopped; |
313 } | 315 } |
314 | 316 |
315 WebIDBTransactionMode IDBTransaction::stringToMode(const String& modeString) | 317 TransactionMode IDBTransaction::stringToMode(const String& modeString) |
316 { | 318 { |
317 if (modeString == IndexedDBNames::readonly) | 319 if (modeString == IndexedDBNames::readonly) |
318 return WebIDBTransactionModeReadOnly; | 320 return TransactionMode::ReadOnly; |
319 if (modeString == IndexedDBNames::readwrite) | 321 if (modeString == IndexedDBNames::readwrite) |
320 return WebIDBTransactionModeReadWrite; | 322 return TransactionMode::ReadWrite; |
321 if (modeString == IndexedDBNames::versionchange) | 323 if (modeString == IndexedDBNames::versionchange) |
322 return WebIDBTransactionModeVersionChange; | 324 return TransactionMode::VersionChange; |
323 ASSERT_NOT_REACHED(); | 325 ASSERT_NOT_REACHED(); |
324 return WebIDBTransactionModeReadOnly; | 326 return TransactionMode::ReadOnly; |
325 } | 327 } |
326 | 328 |
327 const String& IDBTransaction::mode() const | 329 const String& IDBTransaction::mode() const |
328 { | 330 { |
329 switch (m_mode) { | 331 switch (m_mode) { |
330 case WebIDBTransactionModeReadOnly: | 332 case TransactionMode::ReadOnly: |
331 return IndexedDBNames::readonly; | 333 return IndexedDBNames::readonly; |
332 | 334 |
333 case WebIDBTransactionModeReadWrite: | 335 case TransactionMode::ReadWrite: |
334 return IndexedDBNames::readwrite; | 336 return IndexedDBNames::readwrite; |
335 | 337 |
336 case WebIDBTransactionModeVersionChange: | 338 case TransactionMode::VersionChange: |
337 return IndexedDBNames::versionchange; | 339 return IndexedDBNames::versionchange; |
338 } | 340 } |
339 | 341 |
340 ASSERT_NOT_REACHED(); | 342 ASSERT_NOT_REACHED(); |
341 return IndexedDBNames::readonly; | 343 return IndexedDBNames::readonly; |
342 } | 344 } |
343 | 345 |
344 DOMStringList* IDBTransaction::objectStoreNames() const | 346 DOMStringList* IDBTransaction::objectStoreNames() const |
345 { | 347 { |
346 if (m_mode == WebIDBTransactionModeVersionChange) | 348 if (m_mode == TransactionMode::VersionChange) |
347 return m_database->objectStoreNames(); | 349 return m_database->objectStoreNames(); |
348 | 350 |
349 DOMStringList* objectStoreNames = DOMStringList::create(DOMStringList::Index
edDB); | 351 DOMStringList* objectStoreNames = DOMStringList::create(DOMStringList::Index
edDB); |
350 for (const String& name : m_objectStoreNames) | 352 for (const String& name : m_objectStoreNames) |
351 objectStoreNames->append(name); | 353 objectStoreNames->append(name); |
352 objectStoreNames->sort(); | 354 objectStoreNames->sort(); |
353 return objectStoreNames; | 355 return objectStoreNames; |
354 } | 356 } |
355 | 357 |
356 const AtomicString& IDBTransaction::interfaceName() const | 358 const AtomicString& IDBTransaction::interfaceName() const |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 { | 419 { |
418 DCHECK_NE(m_state, Finished) << "A finished transaction tried to enqueue an
event of type " << event->type() << "."; | 420 DCHECK_NE(m_state, Finished) << "A finished transaction tried to enqueue an
event of type " << event->type() << "."; |
419 if (m_contextStopped || !getExecutionContext()) | 421 if (m_contextStopped || !getExecutionContext()) |
420 return; | 422 return; |
421 | 423 |
422 EventQueue* eventQueue = getExecutionContext()->getEventQueue(); | 424 EventQueue* eventQueue = getExecutionContext()->getEventQueue(); |
423 event->setTarget(this); | 425 event->setTarget(this); |
424 eventQueue->enqueueEvent(event); | 426 eventQueue->enqueueEvent(event); |
425 } | 427 } |
426 | 428 |
427 WebIDBDatabase* IDBTransaction::backendDB() const | 429 IDBDatabaseProxy* IDBTransaction::backendDB() const |
428 { | 430 { |
429 return m_database->backend(); | 431 return m_database->backend(); |
430 } | 432 } |
431 | 433 |
432 } // namespace blink | 434 } // namespace blink |
OLD | NEW |