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

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBTransaction.cpp

Issue 1963293002: Replacing Indexed DB Chromium IPC with Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Some (incomplete) work on struct traits. Created 4 years, 5 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
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
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
204 } 205 }
205 206
206 void IDBTransaction::abort(ExceptionState& exceptionState) 207 void IDBTransaction::abort(ExceptionState& exceptionState)
207 { 208 {
208 if (m_state == Finishing || m_state == Finished) { 209 if (m_state == Finishing || m_state == Finished) {
209 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::transac tionFinishedErrorMessage); 210 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::transac tionFinishedErrorMessage);
210 return; 211 return;
211 } 212 }
212 213
213 m_state = Finishing; 214 m_state = Finishing;
214 215
215 if (m_contextStopped) 216 if (m_contextStopped)
216 return; 217 return;
217 218
218 for (IDBRequest* request : m_requestList) 219 for (IDBRequest* request : m_requestList)
219 request->abort(); 220 request->abort();
220 m_requestList.clear(); 221 m_requestList.clear();
221 222
222 for (IDBObjectStore* store : m_createdObjectStores) { 223 for (IDBObjectStore* store : m_createdObjectStores) {
223 store->abort(); 224 store->abort();
224 store->markDeleted(); 225 store->markDeleted();
225 } 226 }
226 227
227 if (backendDB()) 228 if (backendDB())
228 backendDB()->abort(m_id); 229 backendDB()->Abort(m_id);
229 } 230 }
230 231
231 void IDBTransaction::registerRequest(IDBRequest* request) 232 void IDBTransaction::registerRequest(IDBRequest* request)
232 { 233 {
233 ASSERT(request); 234 ASSERT(request);
234 ASSERT(m_state == Active); 235 ASSERT(m_state == Active);
235 m_requestList.add(request); 236 m_requestList.add(request);
236 } 237 }
237 238
238 void IDBTransaction::unregisterRequest(IDBRequest* request) 239 void IDBTransaction::unregisterRequest(IDBRequest* request)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 306 }
306 307
307 bool IDBTransaction::hasPendingActivity() const 308 bool IDBTransaction::hasPendingActivity() const
308 { 309 {
309 // FIXME: In an ideal world, we should return true as long as anyone has a o r can 310 // 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 311 // 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. 312 // event listeners. This is in order to handle user generated events properly.
312 return m_hasPendingActivity && !m_contextStopped; 313 return m_hasPendingActivity && !m_contextStopped;
313 } 314 }
314 315
315 WebIDBTransactionMode IDBTransaction::stringToMode(const String& modeString) 316 TransactionMode IDBTransaction::stringToMode(const String& modeString)
316 { 317 {
317 if (modeString == IndexedDBNames::readonly) 318 if (modeString == IndexedDBNames::readonly)
318 return WebIDBTransactionModeReadOnly; 319 return TransactionMode::ReadOnly;
319 if (modeString == IndexedDBNames::readwrite) 320 if (modeString == IndexedDBNames::readwrite)
320 return WebIDBTransactionModeReadWrite; 321 return TransactionMode::ReadWrite;
321 if (modeString == IndexedDBNames::versionchange) 322 if (modeString == IndexedDBNames::versionchange)
322 return WebIDBTransactionModeVersionChange; 323 return TransactionMode::VersionChange;
323 ASSERT_NOT_REACHED(); 324 ASSERT_NOT_REACHED();
324 return WebIDBTransactionModeReadOnly; 325 return TransactionMode::ReadOnly;
325 } 326 }
326 327
327 const String& IDBTransaction::mode() const 328 const String& IDBTransaction::mode() const
328 { 329 {
329 switch (m_mode) { 330 switch (m_mode) {
330 case WebIDBTransactionModeReadOnly: 331 case TransactionMode::ReadOnly:
331 return IndexedDBNames::readonly; 332 return IndexedDBNames::readonly;
332 333
333 case WebIDBTransactionModeReadWrite: 334 case TransactionMode::ReadWrite:
334 return IndexedDBNames::readwrite; 335 return IndexedDBNames::readwrite;
335 336
336 case WebIDBTransactionModeVersionChange: 337 case TransactionMode::VersionChange:
337 return IndexedDBNames::versionchange; 338 return IndexedDBNames::versionchange;
338 } 339 }
339 340
340 ASSERT_NOT_REACHED(); 341 ASSERT_NOT_REACHED();
341 return IndexedDBNames::readonly; 342 return IndexedDBNames::readonly;
342 } 343 }
343 344
344 DOMStringList* IDBTransaction::objectStoreNames() const 345 DOMStringList* IDBTransaction::objectStoreNames() const
345 { 346 {
346 if (m_mode == WebIDBTransactionModeVersionChange) 347 if (m_mode == TransactionMode::VersionChange)
347 return m_database->objectStoreNames(); 348 return m_database->objectStoreNames();
348 349
349 DOMStringList* objectStoreNames = DOMStringList::create(DOMStringList::Index edDB); 350 DOMStringList* objectStoreNames = DOMStringList::create(DOMStringList::Index edDB);
350 for (const String& name : m_objectStoreNames) 351 for (const String& name : m_objectStoreNames)
351 objectStoreNames->append(name); 352 objectStoreNames->append(name);
352 objectStoreNames->sort(); 353 objectStoreNames->sort();
353 return objectStoreNames; 354 return objectStoreNames;
354 } 355 }
355 356
356 const AtomicString& IDBTransaction::interfaceName() const 357 const AtomicString& IDBTransaction::interfaceName() const
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 { 418 {
418 DCHECK_NE(m_state, Finished) << "A finished transaction tried to enqueue an event of type " << event->type() << "."; 419 DCHECK_NE(m_state, Finished) << "A finished transaction tried to enqueue an event of type " << event->type() << ".";
419 if (m_contextStopped || !getExecutionContext()) 420 if (m_contextStopped || !getExecutionContext())
420 return; 421 return;
421 422
422 EventQueue* eventQueue = getExecutionContext()->getEventQueue(); 423 EventQueue* eventQueue = getExecutionContext()->getEventQueue();
423 event->setTarget(this); 424 event->setTarget(this);
424 eventQueue->enqueueEvent(event); 425 eventQueue->enqueueEvent(event);
425 } 426 }
426 427
427 WebIDBDatabase* IDBTransaction::backendDB() const 428 IDBDatabaseProxy* IDBTransaction::backendDB() const
428 { 429 {
429 return m_database->backend(); 430 return m_database->backend();
430 } 431 }
431 432
432 } // namespace blink 433 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698