| 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 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 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/IDBObserverCallback.h" |
| 32 #include "bindings/modules/v8/V8BindingForModules.h" | 33 #include "bindings/modules/v8/V8BindingForModules.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" |
| 41 #include "modules/indexeddb/IDBObserver.h" |
| 42 #include "modules/indexeddb/IDBObserverChanges.h" |
| 40 #include "modules/indexeddb/IDBTracing.h" | 43 #include "modules/indexeddb/IDBTracing.h" |
| 41 #include "modules/indexeddb/IDBVersionChangeEvent.h" | 44 #include "modules/indexeddb/IDBVersionChangeEvent.h" |
| 42 #include "modules/indexeddb/WebIDBDatabaseCallbacksImpl.h" | 45 #include "modules/indexeddb/WebIDBDatabaseCallbacksImpl.h" |
| 43 #include "platform/Histogram.h" | 46 #include "platform/Histogram.h" |
| 44 #include "public/platform/modules/indexeddb/WebIDBKeyPath.h" | 47 #include "public/platform/modules/indexeddb/WebIDBKeyPath.h" |
| 45 #include "public/platform/modules/indexeddb/WebIDBTypes.h" | 48 #include "public/platform/modules/indexeddb/WebIDBTypes.h" |
| 46 #include "wtf/Atomics.h" | 49 #include "wtf/Atomics.h" |
| 47 #include <limits> | 50 #include <limits> |
| 48 #include <memory> | 51 #include <memory> |
| 49 | 52 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } | 109 } |
| 107 | 110 |
| 108 IDBDatabase::~IDBDatabase() { | 111 IDBDatabase::~IDBDatabase() { |
| 109 if (!m_closePending && m_backend) | 112 if (!m_closePending && m_backend) |
| 110 m_backend->close(); | 113 m_backend->close(); |
| 111 } | 114 } |
| 112 | 115 |
| 113 DEFINE_TRACE(IDBDatabase) { | 116 DEFINE_TRACE(IDBDatabase) { |
| 114 visitor->trace(m_versionChangeTransaction); | 117 visitor->trace(m_versionChangeTransaction); |
| 115 visitor->trace(m_transactions); | 118 visitor->trace(m_transactions); |
| 119 visitor->trace(m_observers); |
| 116 visitor->trace(m_enqueuedEvents); | 120 visitor->trace(m_enqueuedEvents); |
| 117 visitor->trace(m_databaseCallbacks); | 121 visitor->trace(m_databaseCallbacks); |
| 118 EventTargetWithInlineData::trace(visitor); | 122 EventTargetWithInlineData::trace(visitor); |
| 119 ActiveDOMObject::trace(visitor); | 123 ActiveDOMObject::trace(visitor); |
| 120 } | 124 } |
| 121 | 125 |
| 122 int64_t IDBDatabase::nextTransactionId() { | 126 int64_t IDBDatabase::nextTransactionId() { |
| 123 // Only keep a 32-bit counter to allow ports to use the other 32 | 127 // Only keep a 32-bit counter to allow ports to use the other 32 |
| 124 // bits of the id. | 128 // bits of the id. |
| 125 static int currentTransactionId = 0; | 129 static int currentTransactionId = 0; |
| 126 return atomicIncrement(¤tTransactionId); | 130 return atomicIncrement(¤tTransactionId); |
| 127 } | 131 } |
| 128 | 132 |
| 133 int32_t IDBDatabase::nextObserverId() { |
| 134 static int currentObserverId = 0; |
| 135 return atomicIncrement(¤tObserverId); |
| 136 } |
| 137 |
| 129 void IDBDatabase::setMetadata(const IDBDatabaseMetadata& metadata) { | 138 void IDBDatabase::setMetadata(const IDBDatabaseMetadata& metadata) { |
| 130 m_metadata = metadata; | 139 m_metadata = metadata; |
| 131 } | 140 } |
| 132 | 141 |
| 133 void IDBDatabase::setDatabaseMetadata(const IDBDatabaseMetadata& metadata) { | 142 void IDBDatabase::setDatabaseMetadata(const IDBDatabaseMetadata& metadata) { |
| 134 m_metadata.copyFrom(metadata); | 143 m_metadata.copyFrom(metadata); |
| 135 } | 144 } |
| 136 | 145 |
| 137 void IDBDatabase::transactionCreated(IDBTransaction* transaction) { | 146 void IDBDatabase::transactionCreated(IDBTransaction* transaction) { |
| 138 DCHECK(transaction); | 147 DCHECK(transaction); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 163 void IDBDatabase::onAbort(int64_t transactionId, DOMException* error) { | 172 void IDBDatabase::onAbort(int64_t transactionId, DOMException* error) { |
| 164 DCHECK(m_transactions.contains(transactionId)); | 173 DCHECK(m_transactions.contains(transactionId)); |
| 165 m_transactions.get(transactionId)->onAbort(error); | 174 m_transactions.get(transactionId)->onAbort(error); |
| 166 } | 175 } |
| 167 | 176 |
| 168 void IDBDatabase::onComplete(int64_t transactionId) { | 177 void IDBDatabase::onComplete(int64_t transactionId) { |
| 169 DCHECK(m_transactions.contains(transactionId)); | 178 DCHECK(m_transactions.contains(transactionId)); |
| 170 m_transactions.get(transactionId)->onComplete(); | 179 m_transactions.get(transactionId)->onComplete(); |
| 171 } | 180 } |
| 172 | 181 |
| 182 void IDBDatabase::onChanges( |
| 183 const std::unordered_map<int32_t, std::vector<int32_t>>& |
| 184 observation_index_map, |
| 185 const WebVector<WebIDBObservation>& observations) { |
| 186 for (const auto& map_entry : observation_index_map) { |
| 187 auto it = m_observers.find(map_entry.first); |
| 188 if (it != m_observers.end()) { |
| 189 IDBObserver* observer = it->value; |
| 190 observer->callback()->call( |
| 191 observer, |
| 192 IDBObserverChanges::create(this, observations, map_entry.second)); |
| 193 } |
| 194 } |
| 195 } |
| 196 |
| 173 DOMStringList* IDBDatabase::objectStoreNames() const { | 197 DOMStringList* IDBDatabase::objectStoreNames() const { |
| 174 DOMStringList* objectStoreNames = | 198 DOMStringList* objectStoreNames = |
| 175 DOMStringList::create(DOMStringList::IndexedDB); | 199 DOMStringList::create(DOMStringList::IndexedDB); |
| 176 for (const auto& it : m_metadata.objectStores) | 200 for (const auto& it : m_metadata.objectStores) |
| 177 objectStoreNames->append(it.value->name); | 201 objectStoreNames->append(it.value->name); |
| 178 objectStoreNames->sort(); | 202 objectStoreNames->sort(); |
| 179 return objectStoreNames; | 203 return objectStoreNames; |
| 180 } | 204 } |
| 181 | 205 |
| 182 const String& IDBDatabase::getObjectStoreName(int64_t objectStoreId) const { | 206 const String& IDBDatabase::getObjectStoreName(int64_t objectStoreId) const { |
| 183 const auto& it = m_metadata.objectStores.find(objectStoreId); | 207 const auto& it = m_metadata.objectStores.find(objectStoreId); |
| 184 DCHECK(it != m_metadata.objectStores.end()); | 208 DCHECK(it != m_metadata.objectStores.end()); |
| 185 return it->value->name; | 209 return it->value->name; |
| 186 } | 210 } |
| 187 | 211 |
| 212 int32_t IDBDatabase::addObserver( |
| 213 IDBObserver* observer, |
| 214 int64_t transactionId, |
| 215 bool includeTransaction, |
| 216 bool noRecords, |
| 217 bool values, |
| 218 const std::bitset<WebIDBOperationTypeCount>& operationTypes) { |
| 219 int32_t observerId = nextObserverId(); |
| 220 m_observers.set(observerId, observer); |
| 221 backend()->addObserver(transactionId, observerId, includeTransaction, |
| 222 noRecords, values, operationTypes); |
| 223 return observerId; |
| 224 } |
| 225 |
| 226 void IDBDatabase::removeObservers(const Vector<int32_t>& observerIds) { |
| 227 m_observers.removeAll(observerIds); |
| 228 backend()->removeObservers(observerIds); |
| 229 } |
| 230 |
| 188 IDBObjectStore* IDBDatabase::createObjectStore(const String& name, | 231 IDBObjectStore* IDBDatabase::createObjectStore(const String& name, |
| 189 const IDBKeyPath& keyPath, | 232 const IDBKeyPath& keyPath, |
| 190 bool autoIncrement, | 233 bool autoIncrement, |
| 191 ExceptionState& exceptionState) { | 234 ExceptionState& exceptionState) { |
| 192 IDB_TRACE("IDBDatabase::createObjectStore"); | 235 IDB_TRACE("IDBDatabase::createObjectStore"); |
| 193 recordApiCallsHistogram(IDBCreateObjectStoreCall); | 236 recordApiCallsHistogram(IDBCreateObjectStoreCall); |
| 194 | 237 |
| 195 if (!m_versionChangeTransaction) { | 238 if (!m_versionChangeTransaction) { |
| 196 exceptionState.throwDOMException( | 239 exceptionState.throwDOMException( |
| 197 InvalidStateError, | 240 InvalidStateError, |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 | 584 |
| 542 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method) { | 585 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method) { |
| 543 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 586 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 544 EnumerationHistogram, apiCallsHistogram, | 587 EnumerationHistogram, apiCallsHistogram, |
| 545 new EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls", | 588 new EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls", |
| 546 IDBMethodsMax)); | 589 IDBMethodsMax)); |
| 547 apiCallsHistogram.count(method); | 590 apiCallsHistogram.count(method); |
| 548 } | 591 } |
| 549 | 592 |
| 550 } // namespace blink | 593 } // namespace blink |
| OLD | NEW |