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/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/ExceptionCode.h" | 33 #include "core/dom/ExceptionCode.h" |
34 #include "core/dom/ExecutionContext.h" | 34 #include "core/dom/ExecutionContext.h" |
35 #include "core/events/EventQueue.h" | 35 #include "core/events/EventQueue.h" |
36 #include "modules/indexeddb/IDBAny.h" | 36 #include "modules/indexeddb/IDBAny.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/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::IDBDatabaseProxy; |
| 51 using indexed_db::mojom::blink::TransactionMode; |
51 | 52 |
52 namespace blink { | 53 namespace blink { |
53 | 54 |
54 const char IDBDatabase::indexDeletedErrorMessage[] = "The index or its object st
ore has been deleted."; | 55 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.
"; | 56 const char IDBDatabase::isKeyCursorErrorMessage[] = "The cursor is a key cursor.
"; |
56 const char IDBDatabase::noKeyOrKeyRangeErrorMessage[] = "No key or key range spe
cified."; | 57 const char IDBDatabase::noKeyOrKeyRangeErrorMessage[] = "No key or key range spe
cified."; |
57 const char IDBDatabase::noSuchIndexErrorMessage[] = "The specified index was not
found."; | 58 const char IDBDatabase::noSuchIndexErrorMessage[] = "The specified index was not
found."; |
58 const char IDBDatabase::noSuchObjectStoreErrorMessage[] = "The specified object
store was not found."; | 59 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."; | 60 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."; | 61 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."; | 62 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."; | 63 const char IDBDatabase::objectStoreDeletedErrorMessage[] = "The object store has
been deleted."; |
63 const char IDBDatabase::requestNotFinishedErrorMessage[] = "The request has not
finished."; | 64 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."; | 65 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."; | 66 const char IDBDatabase::transactionInactiveErrorMessage[] = "The transaction is
not active."; |
66 const char IDBDatabase::transactionFinishedErrorMessage[] = "The transaction has
finished."; | 67 const char IDBDatabase::transactionFinishedErrorMessage[] = "The transaction has
finished."; |
67 const char IDBDatabase::transactionReadOnlyErrorMessage[] = "The transaction is
read-only."; | 68 const char IDBDatabase::transactionReadOnlyErrorMessage[] = "The transaction is
read-only."; |
68 const char IDBDatabase::databaseClosedErrorMessage[] = "The database connection
is closed."; | 69 const char IDBDatabase::databaseClosedErrorMessage[] = "The database connection
is closed."; |
69 | 70 |
70 IDBDatabase* IDBDatabase::create(ExecutionContext* context, std::unique_ptr<WebI
DBDatabase> database, IDBDatabaseCallbacks* callbacks) | 71 IDBDatabase* IDBDatabase::create(ExecutionContext* context, std::unique_ptr<IDBD
atabaseProxy> database) |
71 { | 72 { |
72 IDBDatabase* idbDatabase = new IDBDatabase(context, std::move(database), cal
lbacks); | 73 IDBDatabase* idbDatabase = new IDBDatabase(context, std::move(database)); |
73 idbDatabase->suspendIfNeeded(); | 74 idbDatabase->suspendIfNeeded(); |
74 return idbDatabase; | 75 return idbDatabase; |
75 } | 76 } |
76 | 77 |
77 IDBDatabase::IDBDatabase(ExecutionContext* context, std::unique_ptr<WebIDBDataba
se> backend, IDBDatabaseCallbacks* callbacks) | 78 IDBDatabase::IDBDatabase(ExecutionContext* context, std::unique_ptr<IDBDatabaseP
roxy> backend) |
78 : ActiveScriptWrappable(this) | 79 : ActiveScriptWrappable(this) |
79 , ActiveDOMObject(context) | 80 , ActiveDOMObject(context) |
80 , m_backend(std::move(backend)) | 81 , m_backend(std::move(backend)) |
81 , m_databaseCallbacks(callbacks) | |
82 { | 82 { |
83 m_databaseCallbacks->connect(this); | |
84 } | 83 } |
85 | 84 |
86 IDBDatabase::~IDBDatabase() | 85 IDBDatabase::~IDBDatabase() |
87 { | 86 { |
88 if (!m_closePending && m_backend) | 87 if (!m_closePending && m_backend) |
89 m_backend->close(); | 88 m_backend->Close(); |
90 } | 89 } |
91 | 90 |
92 DEFINE_TRACE(IDBDatabase) | 91 DEFINE_TRACE(IDBDatabase) |
93 { | 92 { |
94 visitor->trace(m_versionChangeTransaction); | 93 visitor->trace(m_versionChangeTransaction); |
95 visitor->trace(m_transactions); | 94 visitor->trace(m_transactions); |
96 visitor->trace(m_enqueuedEvents); | 95 visitor->trace(m_enqueuedEvents); |
97 visitor->trace(m_databaseCallbacks); | |
98 EventTargetWithInlineData::trace(visitor); | 96 EventTargetWithInlineData::trace(visitor); |
99 ActiveDOMObject::trace(visitor); | 97 ActiveDOMObject::trace(visitor); |
100 } | 98 } |
101 | 99 |
102 int64_t IDBDatabase::nextTransactionId() | 100 int64_t IDBDatabase::nextTransactionId() |
103 { | 101 { |
104 // Only keep a 32-bit counter to allow ports to use the other 32 | 102 // Only keep a 32-bit counter to allow ports to use the other 32 |
105 // bits of the id. | 103 // bits of the id. |
106 static int currentTransactionId = 0; | 104 static int currentTransactionId = 0; |
107 return atomicIncrement(¤tTransactionId); | 105 return atomicIncrement(¤tTransactionId); |
108 } | 106 } |
109 | 107 |
110 void IDBDatabase::indexCreated(int64_t objectStoreId, const IDBIndexMetadata& me
tadata) | 108 void IDBDatabase::indexCreated(int64_t objectStoreId, const IDBIndexMetadata& me
tadata) |
111 { | 109 { |
112 IDBDatabaseMetadata::ObjectStoreMap::iterator it = m_metadata.objectStores.f
ind(objectStoreId); | 110 auto it = m_metadata.objectStores.find(objectStoreId); |
113 ASSERT_WITH_SECURITY_IMPLICATION(it != m_metadata.objectStores.end()); | 111 ASSERT_WITH_SECURITY_IMPLICATION(it != m_metadata.objectStores.end()); |
114 it->value.indexes.set(metadata.id, metadata); | 112 it->value.indexes.set(metadata.id, metadata); |
115 } | 113 } |
116 | 114 |
117 void IDBDatabase::indexDeleted(int64_t objectStoreId, int64_t indexId) | 115 void IDBDatabase::indexDeleted(int64_t objectStoreId, int64_t indexId) |
118 { | 116 { |
119 IDBDatabaseMetadata::ObjectStoreMap::iterator it = m_metadata.objectStores.f
ind(objectStoreId); | 117 auto it = m_metadata.objectStores.find(objectStoreId); |
120 ASSERT_WITH_SECURITY_IMPLICATION(it != m_metadata.objectStores.end()); | 118 ASSERT_WITH_SECURITY_IMPLICATION(it != m_metadata.objectStores.end()); |
121 it->value.indexes.remove(indexId); | 119 it->value.indexes.remove(indexId); |
122 } | 120 } |
123 | 121 |
124 void IDBDatabase::transactionCreated(IDBTransaction* transaction) | 122 void IDBDatabase::transactionCreated(IDBTransaction* transaction) |
125 { | 123 { |
126 ASSERT(transaction); | 124 ASSERT(transaction); |
127 ASSERT(!m_transactions.contains(transaction->id())); | 125 ASSERT(!m_transactions.contains(transaction->id())); |
128 m_transactions.add(transaction->id(), transaction); | 126 m_transactions.add(transaction->id(), transaction); |
129 | 127 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 exceptionState.throwDOMException(InvalidAccessError, "The autoIncrement
option was set but the keyPath option was empty or an array."); | 207 exceptionState.throwDOMException(InvalidAccessError, "The autoIncrement
option was set but the keyPath option was empty or an array."); |
210 return nullptr; | 208 return nullptr; |
211 } | 209 } |
212 | 210 |
213 if (!m_backend) { | 211 if (!m_backend) { |
214 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 212 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
215 return nullptr; | 213 return nullptr; |
216 } | 214 } |
217 | 215 |
218 int64_t objectStoreId = m_metadata.maxObjectStoreId + 1; | 216 int64_t objectStoreId = m_metadata.maxObjectStoreId + 1; |
219 m_backend->createObjectStore(m_versionChangeTransaction->id(), objectStoreId
, name, keyPath, autoIncrement); | 217 m_backend->CreateObjectStore(m_versionChangeTransaction->id(), objectStoreId
, name, keyPath, autoIncrement); |
220 | 218 |
221 IDBObjectStoreMetadata metadata(name, objectStoreId, keyPath, autoIncrement,
WebIDBDatabase::minimumIndexId); | 219 IDBObjectStoreMetadata metadata(name, objectStoreId, keyPath, autoIncrement,
indexed_db::mojom::blink::Database::minimumIndexId); |
222 IDBObjectStore* objectStore = IDBObjectStore::create(metadata, m_versionChan
geTransaction.get()); | 220 IDBObjectStore* objectStore = IDBObjectStore::create(metadata, m_versionChan
geTransaction.get()); |
223 m_metadata.objectStores.set(metadata.id, metadata); | 221 m_metadata.objectStores.set(metadata.id, metadata); |
224 ++m_metadata.maxObjectStoreId; | 222 ++m_metadata.maxObjectStoreId; |
225 | 223 |
226 m_versionChangeTransaction->objectStoreCreated(name, objectStore); | 224 m_versionChangeTransaction->objectStoreCreated(name, objectStore); |
227 return objectStore; | 225 return objectStore; |
228 } | 226 } |
229 | 227 |
230 void IDBDatabase::deleteObjectStore(const String& name, ExceptionState& exceptio
nState) | 228 void IDBDatabase::deleteObjectStore(const String& name, ExceptionState& exceptio
nState) |
231 { | 229 { |
(...skipping 16 matching lines...) Expand all Loading... |
248 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { | 246 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { |
249 exceptionState.throwDOMException(NotFoundError, "The specified object st
ore was not found."); | 247 exceptionState.throwDOMException(NotFoundError, "The specified object st
ore was not found."); |
250 return; | 248 return; |
251 } | 249 } |
252 | 250 |
253 if (!m_backend) { | 251 if (!m_backend) { |
254 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 252 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
255 return; | 253 return; |
256 } | 254 } |
257 | 255 |
258 m_backend->deleteObjectStore(m_versionChangeTransaction->id(), objectStoreId
); | 256 m_backend->DeleteObjectStore(m_versionChangeTransaction->id(), objectStoreId
); |
259 m_versionChangeTransaction->objectStoreDeleted(name); | 257 m_versionChangeTransaction->objectStoreDeleted(name); |
260 m_metadata.objectStores.remove(objectStoreId); | 258 m_metadata.objectStores.remove(objectStoreId); |
261 } | 259 } |
262 | 260 |
263 IDBTransaction* IDBDatabase::transaction(ScriptState* scriptState, const StringO
rStringSequenceOrDOMStringList& storeNames, const String& modeString, ExceptionS
tate& exceptionState) | 261 IDBTransaction* IDBDatabase::transaction(ScriptState* scriptState, const StringO
rStringSequenceOrDOMStringList& storeNames, const String& modeString, ExceptionS
tate& exceptionState) |
264 { | 262 { |
265 IDB_TRACE("IDBDatabase::transaction"); | 263 IDB_TRACE("IDBDatabase::transaction"); |
266 recordApiCallsHistogram(IDBTransactionCall); | 264 recordApiCallsHistogram(IDBTransactionCall); |
267 | 265 |
268 HashSet<String> scope; | 266 HashSet<String> scope; |
269 if (storeNames.isString()) { | 267 if (storeNames.isString()) { |
270 scope.add(storeNames.getAsString()); | 268 scope.add(storeNames.getAsString()); |
271 } else if (storeNames.isStringSequence()) { | 269 } else if (storeNames.isStringSequence()) { |
272 for (const String& name : storeNames.getAsStringSequence()) | 270 for (const String& name : storeNames.getAsStringSequence()) |
273 scope.add(name); | 271 scope.add(name); |
274 } else if (storeNames.isDOMStringList()) { | 272 } else if (storeNames.isDOMStringList()) { |
275 const Vector<String>& list = *storeNames.getAsDOMStringList(); | 273 const Vector<String>& list = *storeNames.getAsDOMStringList(); |
276 for (const String& name : list) | 274 for (const String& name : list) |
277 scope.add(name); | 275 scope.add(name); |
278 } else { | 276 } else { |
279 ASSERT_NOT_REACHED(); | 277 ASSERT_NOT_REACHED(); |
280 } | 278 } |
281 | 279 |
282 if (scope.isEmpty()) { | 280 if (scope.isEmpty()) { |
283 exceptionState.throwDOMException(InvalidAccessError, "The storeNames par
ameter was empty."); | 281 exceptionState.throwDOMException(InvalidAccessError, "The storeNames par
ameter was empty."); |
284 return nullptr; | 282 return nullptr; |
285 } | 283 } |
286 | 284 |
287 WebIDBTransactionMode mode = IDBTransaction::stringToMode(modeString); | 285 TransactionMode mode = IDBTransaction::stringToMode(modeString); |
288 if (mode != WebIDBTransactionModeReadOnly && mode != WebIDBTransactionModeRe
adWrite) { | 286 if (mode != TransactionMode::ReadOnly && mode != TransactionMode::ReadWrite)
{ |
289 exceptionState.throwTypeError("The mode provided ('" + modeString + "')
is not one of 'readonly' or 'readwrite'."); | 287 exceptionState.throwTypeError("The mode provided ('" + modeString + "')
is not one of 'readonly' or 'readwrite'."); |
290 return nullptr; | 288 return nullptr; |
291 } | 289 } |
292 | 290 |
293 if (exceptionState.hadException()) | 291 if (exceptionState.hadException()) |
294 return nullptr; | 292 return nullptr; |
295 | 293 |
296 if (m_versionChangeTransaction) { | 294 if (m_versionChangeTransaction) { |
297 exceptionState.throwDOMException(InvalidStateError, "A version change tr
ansaction is running."); | 295 exceptionState.throwDOMException(InvalidStateError, "A version change tr
ansaction is running."); |
298 return nullptr; | 296 return nullptr; |
(...skipping 13 matching lines...) Expand all Loading... |
312 } | 310 } |
313 objectStoreIds.append(objectStoreId); | 311 objectStoreIds.append(objectStoreId); |
314 } | 312 } |
315 | 313 |
316 if (!m_backend) { | 314 if (!m_backend) { |
317 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 315 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
318 return nullptr; | 316 return nullptr; |
319 } | 317 } |
320 | 318 |
321 int64_t transactionId = nextTransactionId(); | 319 int64_t transactionId = nextTransactionId(); |
322 m_backend->createTransaction(transactionId, WebIDBDatabaseCallbacksImpl::cre
ate(m_databaseCallbacks).release(), objectStoreIds, mode); | 320 m_backend->CreateTransaction(transactionId, std::move(objectStoreIds), mode)
; |
323 | 321 |
324 return IDBTransaction::create(scriptState, transactionId, scope, mode, this)
; | 322 return IDBTransaction::create(scriptState, transactionId, scope, mode, this)
; |
325 } | 323 } |
326 | 324 |
327 void IDBDatabase::forceClose() | 325 void IDBDatabase::forceClose() |
328 { | 326 { |
329 for (const auto& it : m_transactions) | 327 for (const auto& it : m_transactions) |
330 it.value->abort(IGNORE_EXCEPTION); | 328 it.value->abort(IGNORE_EXCEPTION); |
331 this->close(); | 329 this->close(); |
332 enqueueEvent(Event::create(EventTypeNames::close)); | 330 enqueueEvent(Event::create(EventTypeNames::close)); |
(...skipping 10 matching lines...) Expand all Loading... |
343 if (m_transactions.isEmpty()) | 341 if (m_transactions.isEmpty()) |
344 closeConnection(); | 342 closeConnection(); |
345 } | 343 } |
346 | 344 |
347 void IDBDatabase::closeConnection() | 345 void IDBDatabase::closeConnection() |
348 { | 346 { |
349 ASSERT(m_closePending); | 347 ASSERT(m_closePending); |
350 ASSERT(m_transactions.isEmpty()); | 348 ASSERT(m_transactions.isEmpty()); |
351 | 349 |
352 if (m_backend) { | 350 if (m_backend) { |
353 m_backend->close(); | 351 m_backend->Close(); |
354 m_backend.reset(); | 352 m_backend.reset(); |
355 } | 353 } |
356 | 354 |
357 if (m_contextStopped || !getExecutionContext()) | 355 if (m_contextStopped || !getExecutionContext()) |
358 return; | 356 return; |
359 | 357 |
360 EventQueue* eventQueue = getExecutionContext()->getEventQueue(); | 358 EventQueue* eventQueue = getExecutionContext()->getEventQueue(); |
361 // Remove any pending versionchange events scheduled to fire on this | 359 // Remove any pending versionchange events scheduled to fire on this |
362 // connection. They would have been scheduled by the backend when another | 360 // connection. They would have been scheduled by the backend when another |
363 // connection attempted an upgrade, but the frontend connection is being | 361 // connection attempted an upgrade, but the frontend connection is being |
364 // closed before they could fire. | 362 // closed before they could fire. |
365 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { | 363 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { |
366 bool removed = eventQueue->cancelEvent(m_enqueuedEvents[i].get()); | 364 bool removed = eventQueue->cancelEvent(m_enqueuedEvents[i].get()); |
367 ASSERT_UNUSED(removed, removed); | 365 ASSERT_UNUSED(removed, removed); |
368 } | 366 } |
369 } | 367 } |
370 | 368 |
371 void IDBDatabase::onVersionChange(int64_t oldVersion, int64_t newVersion) | 369 void IDBDatabase::onVersionChange(int64_t oldVersion, int64_t newVersion) |
372 { | 370 { |
373 IDB_TRACE("IDBDatabase::onVersionChange"); | 371 IDB_TRACE("IDBDatabase::onVersionChange"); |
| 372 // TODO(cmumford): Not currently called - fix this. |
| 373 NOTREACHED(); |
374 if (m_contextStopped || !getExecutionContext()) | 374 if (m_contextStopped || !getExecutionContext()) |
375 return; | 375 return; |
376 | 376 |
377 if (m_closePending) { | 377 if (m_closePending) { |
378 // If we're pending, that means there's a busy transaction. We won't | 378 // If we're pending, that means there's a busy transaction. We won't |
379 // fire 'versionchange' but since we're not closing immediately the | 379 // fire 'versionchange' but since we're not closing immediately the |
380 // back-end should still send out 'blocked'. | 380 // back-end should still send out 'blocked'. |
381 m_backend->versionChangeIgnored(); | 381 m_backend->VersionChangeIgnored(); |
382 return; | 382 return; |
383 } | 383 } |
384 | 384 |
385 Nullable<unsigned long long> newVersionNullable = (newVersion == IDBDatabase
Metadata::NoVersion) ? Nullable<unsigned long long>() : Nullable<unsigned long l
ong>(newVersion); | 385 Nullable<unsigned long long> newVersionNullable = (newVersion == IDBDatabase
Metadata::NoVersion) ? Nullable<unsigned long long>() : Nullable<unsigned long l
ong>(newVersion); |
386 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::versionchange, ol
dVersion, newVersionNullable)); | 386 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::versionchange, ol
dVersion, newVersionNullable)); |
387 } | 387 } |
388 | 388 |
389 void IDBDatabase::enqueueEvent(Event* event) | 389 void IDBDatabase::enqueueEvent(Event* event) |
390 { | 390 { |
391 ASSERT(!m_contextStopped); | 391 ASSERT(!m_contextStopped); |
(...skipping 10 matching lines...) Expand all Loading... |
402 if (m_contextStopped || !getExecutionContext()) | 402 if (m_contextStopped || !getExecutionContext()) |
403 return DispatchEventResult::CanceledBeforeDispatch; | 403 return DispatchEventResult::CanceledBeforeDispatch; |
404 ASSERT(event->type() == EventTypeNames::versionchange || event->type() == Ev
entTypeNames::close); | 404 ASSERT(event->type() == EventTypeNames::versionchange || event->type() == Ev
entTypeNames::close); |
405 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { | 405 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { |
406 if (m_enqueuedEvents[i].get() == event) | 406 if (m_enqueuedEvents[i].get() == event) |
407 m_enqueuedEvents.remove(i); | 407 m_enqueuedEvents.remove(i); |
408 } | 408 } |
409 | 409 |
410 DispatchEventResult dispatchResult = EventTarget::dispatchEventInternal(even
t); | 410 DispatchEventResult dispatchResult = EventTarget::dispatchEventInternal(even
t); |
411 if (event->type() == EventTypeNames::versionchange && !m_closePending && m_b
ackend) | 411 if (event->type() == EventTypeNames::versionchange && !m_closePending && m_b
ackend) |
412 m_backend->versionChangeIgnored(); | 412 m_backend->VersionChangeIgnored(); |
413 return dispatchResult; | 413 return dispatchResult; |
414 } | 414 } |
415 | 415 |
416 int64_t IDBDatabase::findObjectStoreId(const String& name) const | 416 int64_t IDBDatabase::findObjectStoreId(const String& name) const |
417 { | 417 { |
418 for (const auto& it : m_metadata.objectStores) { | 418 for (const auto& it : m_metadata.objectStores) { |
419 if (it.value.name == name) { | 419 if (it.value.name == name) { |
420 ASSERT(it.key != IDBObjectStoreMetadata::InvalidId); | 420 ASSERT(it.key != IDBObjectStoreMetadata::InvalidId); |
421 return it.key; | 421 return it.key; |
422 } | 422 } |
423 } | 423 } |
424 return IDBObjectStoreMetadata::InvalidId; | 424 return IDBObjectStoreMetadata::InvalidId; |
425 } | 425 } |
426 | 426 |
427 bool IDBDatabase::hasPendingActivity() const | 427 bool IDBDatabase::hasPendingActivity() const |
428 { | 428 { |
429 // The script wrapper must not be collected before the object is closed or | 429 // The script wrapper must not be collected before the object is closed or |
430 // we can't fire a "versionchange" event to let script manually close the co
nnection. | 430 // we can't fire a "versionchange" event to let script manually close the co
nnection. |
431 return !m_closePending && hasEventListeners() && !m_contextStopped; | 431 return !m_closePending && hasEventListeners() && !m_contextStopped; |
432 } | 432 } |
433 | 433 |
434 void IDBDatabase::stop() | 434 void IDBDatabase::stop() |
435 { | 435 { |
436 m_contextStopped = true; | 436 m_contextStopped = true; |
437 | 437 |
438 // Immediately close the connection to the back end. Don't attempt a | 438 // Immediately close the connection to the back end. Don't attempt a |
439 // normal close() since that may wait on transactions which require a | 439 // normal close() since that may wait on transactions which require a |
440 // round trip to the back-end to abort. | 440 // round trip to the back-end to abort. |
441 if (m_backend) { | 441 if (m_backend) { |
442 m_backend->close(); | 442 m_backend->Close(); |
443 m_backend.reset(); | 443 m_backend.reset(); |
444 } | 444 } |
445 } | 445 } |
446 | 446 |
447 const AtomicString& IDBDatabase::interfaceName() const | 447 const AtomicString& IDBDatabase::interfaceName() const |
448 { | 448 { |
449 return EventTargetNames::IDBDatabase; | 449 return EventTargetNames::IDBDatabase; |
450 } | 450 } |
451 | 451 |
452 ExecutionContext* IDBDatabase::getExecutionContext() const | 452 ExecutionContext* IDBDatabase::getExecutionContext() const |
453 { | 453 { |
454 return ActiveDOMObject::getExecutionContext(); | 454 return ActiveDOMObject::getExecutionContext(); |
455 } | 455 } |
456 | 456 |
457 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method) | 457 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method) |
458 { | 458 { |
459 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, apiCallsHistogram, new
EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls", IDBMethodsMax)); | 459 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, apiCallsHistogram, new
EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls", IDBMethodsMax)); |
460 apiCallsHistogram.count(method); | 460 apiCallsHistogram.count(method); |
461 } | 461 } |
462 | 462 |
463 } // namespace blink | 463 } // namespace blink |
OLD | NEW |