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

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

Issue 2320213004: Port IndexedDB open() and database callbacks to Mojo. (Closed)
Patch Set: Make DatabaseClient an associated interface. Created 4 years, 3 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 12 matching lines...) Expand all
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/IDBDatabase.h" 26 #include "modules/indexeddb/IDBDatabase.h"
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/Nullable.h" 30 #include "bindings/core/v8/Nullable.h"
31 #include "bindings/core/v8/SerializedScriptValue.h" 31 #include "bindings/core/v8/SerializedScriptValue.h"
32 #include "bindings/modules/v8/V8BindingForModules.h" 32 #include "bindings/modules/v8/V8BindingForModules.h"
33 #include "core/dom/DOMException.h"
33 #include "core/dom/ExceptionCode.h" 34 #include "core/dom/ExceptionCode.h"
34 #include "core/dom/ExecutionContext.h" 35 #include "core/dom/ExecutionContext.h"
35 #include "core/events/EventQueue.h" 36 #include "core/events/EventQueue.h"
36 #include "modules/indexeddb/IDBAny.h" 37 #include "modules/indexeddb/IDBAny.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/IDBKeyPath.h" 40 #include "modules/indexeddb/IDBKeyPath.h"
40 #include "modules/indexeddb/IDBTracing.h" 41 #include "modules/indexeddb/IDBTracing.h"
41 #include "modules/indexeddb/IDBVersionChangeEvent.h" 42 #include "modules/indexeddb/IDBVersionChangeEvent.h"
42 #include "modules/indexeddb/WebIDBDatabaseCallbacksImpl.h"
43 #include "platform/Histogram.h" 43 #include "platform/Histogram.h"
44 #include "public/platform/modules/indexeddb/WebIDBKeyPath.h" 44 #include "public/platform/modules/indexeddb/WebIDBKeyPath.h"
45 #include "public/platform/modules/indexeddb/WebIDBTypes.h" 45 #include "public/platform/modules/indexeddb/WebIDBTypes.h"
46 #include "wtf/Atomics.h" 46 #include "wtf/Atomics.h"
47 #include <limits> 47 #include <limits>
48 #include <memory> 48 #include <memory>
49 49
50 using blink::WebIDBDatabase; 50 using blink::WebIDBDatabase;
51 51
52 namespace blink { 52 namespace blink {
53 53
54 const char IDBDatabase::indexDeletedErrorMessage[] = "The index or its object st ore has been deleted."; 54 const char IDBDatabase::indexDeletedErrorMessage[] = "The index or its object st ore has been deleted.";
55 const char IDBDatabase::isKeyCursorErrorMessage[] = "The cursor is a key cursor. "; 55 const char IDBDatabase::isKeyCursorErrorMessage[] = "The cursor is a key cursor. ";
56 const char IDBDatabase::noKeyOrKeyRangeErrorMessage[] = "No key or key range spe cified."; 56 const char IDBDatabase::noKeyOrKeyRangeErrorMessage[] = "No key or key range spe cified.";
57 const char IDBDatabase::noSuchIndexErrorMessage[] = "The specified index was not found."; 57 const char IDBDatabase::noSuchIndexErrorMessage[] = "The specified index was not found.";
58 const char IDBDatabase::noSuchObjectStoreErrorMessage[] = "The specified object store was not found."; 58 const char IDBDatabase::noSuchObjectStoreErrorMessage[] = "The specified object store was not found.";
59 const char IDBDatabase::noValueErrorMessage[] = "The cursor is being iterated or has iterated past its end."; 59 const char IDBDatabase::noValueErrorMessage[] = "The cursor is being iterated or has iterated past its end.";
60 const char IDBDatabase::notValidKeyErrorMessage[] = "The parameter is not a vali d key."; 60 const char IDBDatabase::notValidKeyErrorMessage[] = "The parameter is not a vali d key.";
61 const char IDBDatabase::notVersionChangeTransactionErrorMessage[] = "The databas e is not running a version change transaction."; 61 const char IDBDatabase::notVersionChangeTransactionErrorMessage[] = "The databas e is not running a version change transaction.";
62 const char IDBDatabase::objectStoreDeletedErrorMessage[] = "The object store has been deleted."; 62 const char IDBDatabase::objectStoreDeletedErrorMessage[] = "The object store has been deleted.";
63 const char IDBDatabase::requestNotFinishedErrorMessage[] = "The request has not finished."; 63 const char IDBDatabase::requestNotFinishedErrorMessage[] = "The request has not finished.";
64 const char IDBDatabase::sourceDeletedErrorMessage[] = "The cursor's source or ef fective object store has been deleted."; 64 const char IDBDatabase::sourceDeletedErrorMessage[] = "The cursor's source or ef fective object store has been deleted.";
65 const char IDBDatabase::transactionInactiveErrorMessage[] = "The transaction is not active."; 65 const char IDBDatabase::transactionInactiveErrorMessage[] = "The transaction is not active.";
66 const char IDBDatabase::transactionFinishedErrorMessage[] = "The transaction has finished."; 66 const char IDBDatabase::transactionFinishedErrorMessage[] = "The transaction has finished.";
67 const char IDBDatabase::transactionReadOnlyErrorMessage[] = "The transaction is read-only."; 67 const char IDBDatabase::transactionReadOnlyErrorMessage[] = "The transaction is read-only.";
68 const char IDBDatabase::databaseClosedErrorMessage[] = "The database connection is closed."; 68 const char IDBDatabase::databaseClosedErrorMessage[] = "The database connection is closed.";
69 69
70 IDBDatabase* IDBDatabase::create(ExecutionContext* context, std::unique_ptr<WebI DBDatabase> database, IDBDatabaseCallbacks* callbacks) 70 IDBDatabase* IDBDatabase::create(ExecutionContext* context, std::unique_ptr<WebI DBDatabase> database, indexed_db::mojom::blink::DatabaseClientAssociatedRequest clientRequest)
71 { 71 {
72 IDBDatabase* idbDatabase = new IDBDatabase(context, std::move(database), cal lbacks); 72 IDBDatabase* idbDatabase = new IDBDatabase(context, std::move(database), std ::move(clientRequest));
73 idbDatabase->suspendIfNeeded(); 73 idbDatabase->suspendIfNeeded();
74 return idbDatabase; 74 return idbDatabase;
75 } 75 }
76 76
77 IDBDatabase::IDBDatabase(ExecutionContext* context, std::unique_ptr<WebIDBDataba se> backend, IDBDatabaseCallbacks* callbacks) 77 IDBDatabase::IDBDatabase(ExecutionContext* context, std::unique_ptr<WebIDBDataba se> backend, indexed_db::mojom::blink::DatabaseClientAssociatedRequest clientReq uest)
78 : ActiveScriptWrappable(this) 78 : ActiveScriptWrappable(this)
79 , ActiveDOMObject(context) 79 , ActiveDOMObject(context)
80 , m_backend(std::move(backend)) 80 , m_backend(std::move(backend))
81 , m_databaseCallbacks(callbacks) 81 , m_clientBinding(this, std::move(clientRequest))
82 { 82 {
83 m_databaseCallbacks->connect(this); 83 ThreadState::current()->registerPreFinalizer(this);
84 } 84 }
85 85
86 IDBDatabase::~IDBDatabase() 86 IDBDatabase::~IDBDatabase()
87 { 87 {
88 if (!m_closePending && m_backend) 88 if (!m_closePending && m_backend)
89 m_backend->close(); 89 m_backend->close();
90 } 90 }
91 91
92 DEFINE_TRACE(IDBDatabase) 92 DEFINE_TRACE(IDBDatabase)
93 { 93 {
94 visitor->trace(m_versionChangeTransaction); 94 visitor->trace(m_versionChangeTransaction);
95 visitor->trace(m_transactions); 95 visitor->trace(m_transactions);
96 visitor->trace(m_enqueuedEvents); 96 visitor->trace(m_enqueuedEvents);
97 visitor->trace(m_databaseCallbacks);
98 EventTargetWithInlineData::trace(visitor); 97 EventTargetWithInlineData::trace(visitor);
99 ActiveDOMObject::trace(visitor); 98 ActiveDOMObject::trace(visitor);
100 } 99 }
101 100
101 void IDBDatabase::dispose()
102 {
103 m_clientBinding.Close();
104 }
105
102 int64_t IDBDatabase::nextTransactionId() 106 int64_t IDBDatabase::nextTransactionId()
103 { 107 {
104 // Only keep a 32-bit counter to allow ports to use the other 32 108 // Only keep a 32-bit counter to allow ports to use the other 32
105 // bits of the id. 109 // bits of the id.
106 static int currentTransactionId = 0; 110 static int currentTransactionId = 0;
107 return atomicIncrement(&currentTransactionId); 111 return atomicIncrement(&currentTransactionId);
108 } 112 }
109 113
110 void IDBDatabase::indexCreated(int64_t objectStoreId, const IDBIndexMetadata& me tadata) 114 void IDBDatabase::indexCreated(int64_t objectStoreId, const IDBIndexMetadata& me tadata)
111 { 115 {
(...skipping 30 matching lines...) Expand all
142 146
143 if (transaction->isVersionChange()) { 147 if (transaction->isVersionChange()) {
144 ASSERT(m_versionChangeTransaction == transaction); 148 ASSERT(m_versionChangeTransaction == transaction);
145 m_versionChangeTransaction = nullptr; 149 m_versionChangeTransaction = nullptr;
146 } 150 }
147 151
148 if (m_closePending && m_transactions.isEmpty()) 152 if (m_closePending && m_transactions.isEmpty())
149 closeConnection(); 153 closeConnection();
150 } 154 }
151 155
152 void IDBDatabase::onAbort(int64_t transactionId, DOMException* error) 156 void IDBDatabase::OnTransactionAborted(int64_t transactionId, indexed_db::mojom: :blink::ErrorInfoPtr error)
153 { 157 {
154 ASSERT(m_transactions.contains(transactionId)); 158 ASSERT(m_transactions.contains(transactionId));
155 m_transactions.get(transactionId)->onAbort(error); 159 m_transactions.get(transactionId)->onAbort(DOMException::create(error->code, error->message));
156 } 160 }
157 161
158 void IDBDatabase::onComplete(int64_t transactionId) 162 void IDBDatabase::OnTransactionCompleted(int64_t transactionId)
159 { 163 {
160 ASSERT(m_transactions.contains(transactionId)); 164 ASSERT(m_transactions.contains(transactionId));
161 m_transactions.get(transactionId)->onComplete(); 165 m_transactions.get(transactionId)->onComplete();
162 } 166 }
163 167
164 DOMStringList* IDBDatabase::objectStoreNames() const 168 DOMStringList* IDBDatabase::objectStoreNames() const
165 { 169 {
166 DOMStringList* objectStoreNames = DOMStringList::create(DOMStringList::Index edDB); 170 DOMStringList* objectStoreNames = DOMStringList::create(DOMStringList::Index edDB);
167 for (const auto& it : m_metadata.objectStores) 171 for (const auto& it : m_metadata.objectStores)
168 objectStoreNames->append(it.value.name); 172 objectStoreNames->append(it.value.name);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 objectStoreIds.append(objectStoreId); 314 objectStoreIds.append(objectStoreId);
311 } 315 }
312 316
313 WebIDBTransactionMode mode = IDBTransaction::stringToMode(modeString); 317 WebIDBTransactionMode mode = IDBTransaction::stringToMode(modeString);
314 if (mode != WebIDBTransactionModeReadOnly && mode != WebIDBTransactionModeRe adWrite) { 318 if (mode != WebIDBTransactionModeReadOnly && mode != WebIDBTransactionModeRe adWrite) {
315 exceptionState.throwTypeError("The mode provided ('" + modeString + "') is not one of 'readonly' or 'readwrite'."); 319 exceptionState.throwTypeError("The mode provided ('" + modeString + "') is not one of 'readonly' or 'readwrite'.");
316 return nullptr; 320 return nullptr;
317 } 321 }
318 322
319 int64_t transactionId = nextTransactionId(); 323 int64_t transactionId = nextTransactionId();
320 m_backend->createTransaction(transactionId, WebIDBDatabaseCallbacksImpl::cre ate(m_databaseCallbacks).release(), objectStoreIds, mode); 324 m_backend->createTransaction(transactionId, objectStoreIds, mode);
321 325
322 return IDBTransaction::create(scriptState, transactionId, scope, mode, this) ; 326 return IDBTransaction::create(scriptState, transactionId, scope, mode, this) ;
323 } 327 }
324 328
325 void IDBDatabase::forceClose() 329 void IDBDatabase::OnForcedClosed()
326 { 330 {
327 for (const auto& it : m_transactions) 331 for (const auto& it : m_transactions)
328 it.value->abort(IGNORE_EXCEPTION); 332 it.value->abort(IGNORE_EXCEPTION);
329 this->close(); 333 this->close();
330 enqueueEvent(Event::create(EventTypeNames::close)); 334 enqueueEvent(Event::create(EventTypeNames::close));
331 } 335 }
332 336
333 void IDBDatabase::close() 337 void IDBDatabase::close()
334 { 338 {
335 IDB_TRACE("IDBDatabase::close"); 339 IDB_TRACE("IDBDatabase::close");
(...skipping 23 matching lines...) Expand all
359 // Remove any pending versionchange events scheduled to fire on this 363 // Remove any pending versionchange events scheduled to fire on this
360 // connection. They would have been scheduled by the backend when another 364 // connection. They would have been scheduled by the backend when another
361 // connection attempted an upgrade, but the frontend connection is being 365 // connection attempted an upgrade, but the frontend connection is being
362 // closed before they could fire. 366 // closed before they could fire.
363 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { 367 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) {
364 bool removed = eventQueue->cancelEvent(m_enqueuedEvents[i].get()); 368 bool removed = eventQueue->cancelEvent(m_enqueuedEvents[i].get());
365 ASSERT_UNUSED(removed, removed); 369 ASSERT_UNUSED(removed, removed);
366 } 370 }
367 } 371 }
368 372
369 void IDBDatabase::onVersionChange(int64_t oldVersion, int64_t newVersion) 373 void IDBDatabase::OnVersionChange(int64_t oldVersion, int64_t newVersion)
370 { 374 {
371 IDB_TRACE("IDBDatabase::onVersionChange"); 375 IDB_TRACE("IDBDatabase::onVersionChange");
372 if (m_contextStopped || !getExecutionContext()) 376 if (m_contextStopped || !getExecutionContext())
373 return; 377 return;
374 378
375 if (m_closePending) { 379 if (m_closePending) {
376 // If we're pending, that means there's a busy transaction. We won't 380 // If we're pending, that means there's a busy transaction. We won't
377 // fire 'versionchange' but since we're not closing immediately the 381 // fire 'versionchange' but since we're not closing immediately the
378 // back-end should still send out 'blocked'. 382 // back-end should still send out 'blocked'.
379 m_backend->versionChangeIgnored(); 383 m_backend->versionChangeIgnored();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 return ActiveDOMObject::getExecutionContext(); 456 return ActiveDOMObject::getExecutionContext();
453 } 457 }
454 458
455 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method) 459 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method)
456 { 460 {
457 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, apiCallsHistogram, new EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls", IDBMethodsMax)); 461 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, apiCallsHistogram, new EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls", IDBMethodsMax));
458 apiCallsHistogram.count(method); 462 apiCallsHistogram.count(method);
459 } 463 }
460 464
461 } // namespace blink 465 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698