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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 using blink::WebIDBCallbacks; | 53 using blink::WebIDBCallbacks; |
54 using blink::WebIDBCursor; | 54 using blink::WebIDBCursor; |
55 using blink::WebIDBDatabase; | 55 using blink::WebIDBDatabase; |
56 using blink::WebVector; | 56 using blink::WebVector; |
57 | 57 |
58 namespace blink { | 58 namespace blink { |
59 | 59 |
60 IDBObjectStore::IDBObjectStore(const IDBObjectStoreMetadata& metadata, IDBTransa
ction* transaction) | 60 IDBObjectStore::IDBObjectStore(const IDBObjectStoreMetadata& metadata, IDBTransa
ction* transaction) |
61 : m_metadata(metadata) | 61 : m_metadata(metadata) |
62 , m_transaction(transaction) | 62 , m_transaction(transaction) |
63 , m_deleted(false) | |
64 { | 63 { |
65 ASSERT(m_transaction); | 64 ASSERT(m_transaction); |
66 } | 65 } |
67 | 66 |
68 DEFINE_TRACE(IDBObjectStore) | 67 DEFINE_TRACE(IDBObjectStore) |
69 { | 68 { |
70 visitor->trace(m_transaction); | 69 visitor->trace(m_transaction); |
71 visitor->trace(m_indexMap); | 70 visitor->trace(m_indexMap); |
72 } | 71 } |
73 | 72 |
74 ScriptValue IDBObjectStore::keyPath(ScriptState* scriptState) const | 73 ScriptValue IDBObjectStore::keyPath(ScriptState* scriptState) const |
75 { | 74 { |
76 return ScriptValue::from(scriptState, m_metadata.keyPath); | 75 return ScriptValue::from(scriptState, m_metadata.keyPath); |
77 } | 76 } |
78 | 77 |
79 PassRefPtrWillBeRawPtr<DOMStringList> IDBObjectStore::indexNames() const | 78 PassRefPtrWillBeRawPtr<DOMStringList> IDBObjectStore::indexNames() const |
80 { | 79 { |
81 IDB_TRACE("IDBObjectStore::indexNames"); | 80 IDB_TRACE("IDBObjectStore::indexNames"); |
82 RefPtrWillBeRawPtr<DOMStringList> indexNames = DOMStringList::create(DOMStri
ngList::IndexedDB); | 81 RefPtrWillBeRawPtr<DOMStringList> indexNames = DOMStringList::create(DOMStri
ngList::IndexedDB); |
83 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) | 82 for (const auto& it : m_metadata.indexes) |
84 indexNames->append(it->value.name); | 83 indexNames->append(it.value.name); |
85 indexNames->sort(); | 84 indexNames->sort(); |
86 return indexNames.release(); | 85 return indexNames.release(); |
87 } | 86 } |
88 | 87 |
89 IDBRequest* IDBObjectStore::get(ScriptState* scriptState, const ScriptValue& key
, ExceptionState& exceptionState) | 88 IDBRequest* IDBObjectStore::get(ScriptState* scriptState, const ScriptValue& key
, ExceptionState& exceptionState) |
90 { | 89 { |
91 IDB_TRACE("IDBObjectStore::get"); | 90 IDB_TRACE("IDBObjectStore::get"); |
92 if (isDeleted()) { | 91 if (isDeleted()) { |
93 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); | 92 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); |
94 return nullptr; | 93 return nullptr; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 159 } |
161 | 160 |
162 IDBRequest* IDBObjectStore::getAllKeys(ScriptState* scriptState, const ScriptVal
ue& keyRange, unsigned long maxCount, ExceptionState& exceptionState) | 161 IDBRequest* IDBObjectStore::getAllKeys(ScriptState* scriptState, const ScriptVal
ue& keyRange, unsigned long maxCount, ExceptionState& exceptionState) |
163 { | 162 { |
164 IDB_TRACE("IDBObjectStore::getAll"); | 163 IDB_TRACE("IDBObjectStore::getAll"); |
165 if (!maxCount) | 164 if (!maxCount) |
166 maxCount = std::numeric_limits<uint32_t>::max(); | 165 maxCount = std::numeric_limits<uint32_t>::max(); |
167 | 166 |
168 if (isDeleted()) { | 167 if (isDeleted()) { |
169 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); | 168 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); |
170 return 0; | 169 return nullptr; |
171 } | 170 } |
172 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 171 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
173 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 172 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
174 return 0; | 173 return nullptr; |
175 } | 174 } |
176 if (!m_transaction->isActive()) { | 175 if (!m_transaction->isActive()) { |
177 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 176 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
178 return 0; | 177 return nullptr; |
179 } | 178 } |
180 IDBKeyRange* range = IDBKeyRange::fromScriptValue(scriptState->executionCont
ext(), keyRange, exceptionState); | 179 IDBKeyRange* range = IDBKeyRange::fromScriptValue(scriptState->executionCont
ext(), keyRange, exceptionState); |
181 if (exceptionState.hadException()) | 180 if (exceptionState.hadException()) |
182 return 0; | 181 return nullptr; |
183 if (!backendDB()) { | 182 if (!backendDB()) { |
184 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 183 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
185 return 0; | 184 return nullptr; |
186 } | 185 } |
187 | 186 |
188 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 187 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
189 backendDB()->getAll(m_transaction->id(), id(), IDBIndexMetadata::InvalidId,
range, maxCount, true, WebIDBCallbacksImpl::create(request).leakPtr()); | 188 backendDB()->getAll(m_transaction->id(), id(), IDBIndexMetadata::InvalidId,
range, maxCount, true, WebIDBCallbacksImpl::create(request).leakPtr()); |
190 return request; | 189 return request; |
191 } | 190 } |
192 | 191 |
193 static void generateIndexKeysForValue(v8::Isolate* isolate, const IDBIndexMetada
ta& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::IndexKeys* in
dexKeys) | 192 static void generateIndexKeysForValue(v8::Isolate* isolate, const IDBIndexMetada
ta& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::IndexKeys* in
dexKeys) |
194 { | 193 { |
195 ASSERT(indexKeys); | 194 ASSERT(indexKeys); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 return nullptr; | 317 return nullptr; |
319 } | 318 } |
320 | 319 |
321 if (!backendDB()) { | 320 if (!backendDB()) { |
322 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 321 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
323 return nullptr; | 322 return nullptr; |
324 } | 323 } |
325 | 324 |
326 Vector<int64_t> indexIds; | 325 Vector<int64_t> indexIds; |
327 HeapVector<IndexKeys> indexKeys; | 326 HeapVector<IndexKeys> indexKeys; |
328 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) { | 327 for (const auto& it : m_metadata.indexes) { |
329 if (clone.isEmpty()) | 328 if (clone.isEmpty()) |
330 clone = deserializeScriptValue(scriptState, serializedValue.get(), &
blobInfo); | 329 clone = deserializeScriptValue(scriptState, serializedValue.get(), &
blobInfo); |
331 IndexKeys keys; | 330 IndexKeys keys; |
332 generateIndexKeysForValue(scriptState->isolate(), it->value, clone, &key
s); | 331 generateIndexKeysForValue(scriptState->isolate(), it.value, clone, &keys
); |
333 indexIds.append(it->key); | 332 indexIds.append(it.key); |
334 indexKeys.append(keys); | 333 indexKeys.append(keys); |
335 } | 334 } |
336 | 335 |
337 IDBRequest* request = IDBRequest::create(scriptState, source, m_transaction.
get()); | 336 IDBRequest* request = IDBRequest::create(scriptState, source, m_transaction.
get()); |
338 Vector<char> wireBytes; | 337 Vector<char> wireBytes; |
339 serializedValue->toWireBytes(wireBytes); | 338 serializedValue->toWireBytes(wireBytes); |
340 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); | 339 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); |
341 | 340 |
342 backendDB()->put(m_transaction->id(), id(), WebData(valueBuffer), blobInfo,
key, static_cast<WebIDBPutMode>(putMode), WebIDBCallbacksImpl::create(request).l
eakPtr(), indexIds, indexKeys); | 341 backendDB()->put(m_transaction->id(), id(), WebData(valueBuffer), blobInfo,
key, static_cast<WebIDBPutMode>(putMode), WebIDBCallbacksImpl::create(request).l
eakPtr(), indexIds, indexKeys); |
343 return request; | 342 return request; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 if (it != m_indexMap.end()) | 567 if (it != m_indexMap.end()) |
569 return it->value; | 568 return it->value; |
570 | 569 |
571 int64_t indexId = findIndexId(name); | 570 int64_t indexId = findIndexId(name); |
572 if (indexId == IDBIndexMetadata::InvalidId) { | 571 if (indexId == IDBIndexMetadata::InvalidId) { |
573 exceptionState.throwDOMException(NotFoundError, IDBDatabase::noSuchIndex
ErrorMessage); | 572 exceptionState.throwDOMException(NotFoundError, IDBDatabase::noSuchIndex
ErrorMessage); |
574 return nullptr; | 573 return nullptr; |
575 } | 574 } |
576 | 575 |
577 const IDBIndexMetadata* indexMetadata(nullptr); | 576 const IDBIndexMetadata* indexMetadata(nullptr); |
578 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) { | 577 for (const auto& it : m_metadata.indexes) { |
579 if (it->value.name == name) { | 578 if (it.value.name == name) { |
580 indexMetadata = &it->value; | 579 indexMetadata = &it.value; |
581 break; | 580 break; |
582 } | 581 } |
583 } | 582 } |
584 ASSERT(indexMetadata); | 583 ASSERT(indexMetadata); |
585 ASSERT(indexMetadata->id != IDBIndexMetadata::InvalidId); | 584 ASSERT(indexMetadata->id != IDBIndexMetadata::InvalidId); |
586 | 585 |
587 IDBIndex* index = IDBIndex::create(*indexMetadata, this, m_transaction.get()
); | 586 IDBIndex* index = IDBIndex::create(*indexMetadata, this, m_transaction.get()
); |
588 m_indexMap.set(name, index); | 587 m_indexMap.set(name, index); |
589 return index; | 588 return index; |
590 } | 589 } |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 void IDBObjectStore::transactionFinished() | 732 void IDBObjectStore::transactionFinished() |
734 { | 733 { |
735 ASSERT(m_transaction->isFinished()); | 734 ASSERT(m_transaction->isFinished()); |
736 | 735 |
737 // Break reference cycles. | 736 // Break reference cycles. |
738 m_indexMap.clear(); | 737 m_indexMap.clear(); |
739 } | 738 } |
740 | 739 |
741 int64_t IDBObjectStore::findIndexId(const String& name) const | 740 int64_t IDBObjectStore::findIndexId(const String& name) const |
742 { | 741 { |
743 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) { | 742 for (const auto& it : m_metadata.indexes) { |
744 if (it->value.name == name) { | 743 if (it.value.name == name) { |
745 ASSERT(it->key != IDBIndexMetadata::InvalidId); | 744 ASSERT(it.key != IDBIndexMetadata::InvalidId); |
746 return it->key; | 745 return it.key; |
747 } | 746 } |
748 } | 747 } |
749 return IDBIndexMetadata::InvalidId; | 748 return IDBIndexMetadata::InvalidId; |
750 } | 749 } |
751 | 750 |
752 WebIDBDatabase* IDBObjectStore::backendDB() const | 751 WebIDBDatabase* IDBObjectStore::backendDB() const |
753 { | 752 { |
754 return m_transaction->backendDB(); | 753 return m_transaction->backendDB(); |
755 } | 754 } |
756 | 755 |
757 } // namespace blink | 756 } // namespace blink |
OLD | NEW |