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

Side by Side Diff: Source/modules/indexeddb/IDBObjectStore.cpp

Issue 67463006: IndexedDB: Simplify WebIDBCallbacks exports, strip IDBFactoryBackend (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Re-up Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/indexeddb/IDBIndex.cpp ('k') | Source/modules/indexeddb/IDBRequestTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 21 matching lines...) Expand all
32 #include "bindings/v8/ScriptState.h" 32 #include "bindings/v8/ScriptState.h"
33 #include "core/dom/DOMStringList.h" 33 #include "core/dom/DOMStringList.h"
34 #include "core/dom/ExceptionCode.h" 34 #include "core/dom/ExceptionCode.h"
35 #include "core/dom/ExecutionContext.h" 35 #include "core/dom/ExecutionContext.h"
36 #include "modules/indexeddb/IDBAny.h" 36 #include "modules/indexeddb/IDBAny.h"
37 #include "modules/indexeddb/IDBCursorWithValue.h" 37 #include "modules/indexeddb/IDBCursorWithValue.h"
38 #include "modules/indexeddb/IDBDatabase.h" 38 #include "modules/indexeddb/IDBDatabase.h"
39 #include "modules/indexeddb/IDBKeyPath.h" 39 #include "modules/indexeddb/IDBKeyPath.h"
40 #include "modules/indexeddb/IDBTracing.h" 40 #include "modules/indexeddb/IDBTracing.h"
41 #include "modules/indexeddb/IDBTransaction.h" 41 #include "modules/indexeddb/IDBTransaction.h"
42 #include "modules/indexeddb/WebIDBCallbacksImpl.h"
42 #include "platform/SharedBuffer.h" 43 #include "platform/SharedBuffer.h"
43 #include "public/platform/WebData.h" 44 #include "public/platform/WebData.h"
44 #include "public/platform/WebIDBKey.h" 45 #include "public/platform/WebIDBKey.h"
45 #include "public/platform/WebIDBKeyRange.h" 46 #include "public/platform/WebIDBKeyRange.h"
46 47
47 using blink::WebIDBDatabase; 48 using blink::WebIDBDatabase;
48 using blink::WebIDBCallbacks; 49 using blink::WebIDBCallbacks;
49 50
50 namespace WebCore { 51 namespace WebCore {
51 52
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 88 }
88 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex ceptionState); 89 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex ceptionState);
89 if (exceptionState.hadException()) 90 if (exceptionState.hadException())
90 return 0; 91 return 0;
91 if (!keyRange) { 92 if (!keyRange) {
92 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage); 93 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage);
93 return 0; 94 return 0;
94 } 95 }
95 96
96 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 97 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
97 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, key Range.release(), false, new WebIDBCallbacks(request)); 98 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, key Range.release(), false, WebIDBCallbacksImpl::create(request).leakPtr());
98 return request.release(); 99 return request.release();
99 } 100 }
100 101
101 static void generateIndexKeysForValue(DOMRequestState* requestState, const IDBIn dexMetadata& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::Inde xKeys* indexKeys) 102 static void generateIndexKeysForValue(DOMRequestState* requestState, const IDBIn dexMetadata& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::Inde xKeys* indexKeys)
102 { 103 {
103 ASSERT(indexKeys); 104 ASSERT(indexKeys);
104 RefPtr<IDBKey> indexKey = createIDBKeyFromScriptValueAndKeyPath(requestState , objectValue, indexMetadata.keyPath); 105 RefPtr<IDBKey> indexKey = createIDBKeyFromScriptValueAndKeyPath(requestState , objectValue, indexMetadata.keyPath);
105 106
106 if (!indexKey) 107 if (!indexKey)
107 return; 108 return;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 IndexKeys keys; 219 IndexKeys keys;
219 generateIndexKeysForValue(&requestState, it->value, value, &keys); 220 generateIndexKeysForValue(&requestState, it->value, value, &keys);
220 indexIds.append(it->key); 221 indexIds.append(it->key);
221 indexKeys.append(keys); 222 indexKeys.append(keys);
222 } 223 }
223 224
224 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti on.get()); 225 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti on.get());
225 Vector<char> wireBytes; 226 Vector<char> wireBytes;
226 serializedValue->toWireBytes(wireBytes); 227 serializedValue->toWireBytes(wireBytes);
227 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); 228 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes);
228 backendDB()->put(m_transaction->id(), id(), blink::WebData(valueBuffer), key .release(), static_cast<WebIDBDatabase::PutMode>(putMode), new WebIDBCallbacks(r equest), indexIds, indexKeys); 229 backendDB()->put(m_transaction->id(), id(), blink::WebData(valueBuffer), key .release(), static_cast<WebIDBDatabase::PutMode>(putMode), WebIDBCallbacksImpl:: create(request).leakPtr(), indexIds, indexKeys);
229 return request.release(); 230 return request.release();
230 } 231 }
231 232
232 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ExecutionContext* context, const ScriptValue& key, ExceptionState& exceptionState) 233 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ExecutionContext* context, const ScriptValue& key, ExceptionState& exceptionState)
233 { 234 {
234 IDB_TRACE("IDBObjectStore::delete"); 235 IDB_TRACE("IDBObjectStore::delete");
235 if (isDeleted()) { 236 if (isDeleted()) {
236 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 237 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
237 return 0; 238 return 0;
238 } 239 }
(...skipping 12 matching lines...) Expand all
251 252
252 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex ceptionState); 253 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex ceptionState);
253 if (exceptionState.hadException()) 254 if (exceptionState.hadException())
254 return 0; 255 return 0;
255 if (!keyRange) { 256 if (!keyRange) {
256 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage); 257 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage);
257 return 0; 258 return 0;
258 } 259 }
259 260
260 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 261 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
261 backendDB()->deleteRange(m_transaction->id(), id(), keyRange.release(), new WebIDBCallbacks(request)); 262 backendDB()->deleteRange(m_transaction->id(), id(), keyRange.release(), WebI DBCallbacksImpl::create(request).leakPtr());
262 return request.release(); 263 return request.release();
263 } 264 }
264 265
265 PassRefPtr<IDBRequest> IDBObjectStore::clear(ExecutionContext* context, Exceptio nState& exceptionState) 266 PassRefPtr<IDBRequest> IDBObjectStore::clear(ExecutionContext* context, Exceptio nState& exceptionState)
266 { 267 {
267 IDB_TRACE("IDBObjectStore::clear"); 268 IDB_TRACE("IDBObjectStore::clear");
268 if (isDeleted()) { 269 if (isDeleted()) {
269 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 270 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
270 return 0; 271 return 0;
271 } 272 }
272 if (m_transaction->isFinished()) { 273 if (m_transaction->isFinished()) {
273 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 274 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
274 return 0; 275 return 0;
275 } 276 }
276 if (!m_transaction->isActive()) { 277 if (!m_transaction->isActive()) {
277 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 278 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
278 return 0; 279 return 0;
279 } 280 }
280 if (m_transaction->isReadOnly()) { 281 if (m_transaction->isReadOnly()) {
281 exceptionState.throwUninformativeAndGenericDOMException(ReadOnlyError); 282 exceptionState.throwUninformativeAndGenericDOMException(ReadOnlyError);
282 return 0; 283 return 0;
283 } 284 }
284 285
285 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 286 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
286 backendDB()->clear(m_transaction->id(), id(), new WebIDBCallbacks(request)); 287 backendDB()->clear(m_transaction->id(), id(), WebIDBCallbacksImpl::create(re quest).leakPtr());
287 return request.release(); 288 return request.release();
288 } 289 }
289 290
290 namespace { 291 namespace {
291 // This class creates the index keys for a given index by extracting 292 // This class creates the index keys for a given index by extracting
292 // them from the SerializedScriptValue, for all the existing values in 293 // them from the SerializedScriptValue, for all the existing values in
293 // the objectStore. It only needs to be kept alive by virtue of being 294 // the objectStore. It only needs to be kept alive by virtue of being
294 // a listener on an IDBRequest object, in the same way that JavaScript 295 // a listener on an IDBRequest object, in the same way that JavaScript
295 // cursor success handlers are kept alive. 296 // cursor success handlers are kept alive.
296 class IndexPopulator : public EventListener { 297 class IndexPopulator : public EventListener {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 return 0; 529 return 0;
529 530
530 return openCursor(context, keyRange, direction, WebIDBDatabase::NormalTask); 531 return openCursor(context, keyRange, direction, WebIDBDatabase::NormalTask);
531 } 532 }
532 533
533 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ExecutionContext* context, Pas sRefPtr<IDBKeyRange> range, IndexedDB::CursorDirection direction, WebIDBDatabase ::TaskType taskType) 534 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ExecutionContext* context, Pas sRefPtr<IDBKeyRange> range, IndexedDB::CursorDirection direction, WebIDBDatabase ::TaskType taskType)
534 { 535 {
535 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 536 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
536 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); 537 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction);
537 538
538 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, taskType, new WebIDBCallbacks(request)); 539 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, taskType, WebIDBCallbacksImpl::create(request).leak Ptr());
539 return request.release(); 540 return request.release();
540 } 541 }
541 542
542 PassRefPtr<IDBRequest> IDBObjectStore::openKeyCursor(ExecutionContext* context, const ScriptValue& range, const String& directionString, ExceptionState& excepti onState) 543 PassRefPtr<IDBRequest> IDBObjectStore::openKeyCursor(ExecutionContext* context, const ScriptValue& range, const String& directionString, ExceptionState& excepti onState)
543 { 544 {
544 IDB_TRACE("IDBObjectStore::openKeyCursor"); 545 IDB_TRACE("IDBObjectStore::openKeyCursor");
545 if (isDeleted()) { 546 if (isDeleted()) {
546 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 547 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
547 return 0; 548 return 0;
548 } 549 }
(...skipping 10 matching lines...) Expand all
559 if (exceptionState.hadException()) 560 if (exceptionState.hadException())
560 return 0; 561 return 0;
561 562
562 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState); 563 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState);
563 if (exceptionState.hadException()) 564 if (exceptionState.hadException())
564 return 0; 565 return 0;
565 566
566 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 567 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
567 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); 568 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction);
568 569
569 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, keyRange.release(), direction, true, WebIDBDatabase::NormalTask, new WebIDBC allbacks(request)); 570 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, keyRange.release(), direction, true, WebIDBDatabase::NormalTask, WebIDBCallb acksImpl::create(request).leakPtr());
570 return request.release(); 571 return request.release();
571 } 572 }
572 573
573 PassRefPtr<IDBRequest> IDBObjectStore::count(ExecutionContext* context, const Sc riptValue& range, ExceptionState& exceptionState) 574 PassRefPtr<IDBRequest> IDBObjectStore::count(ExecutionContext* context, const Sc riptValue& range, ExceptionState& exceptionState)
574 { 575 {
575 IDB_TRACE("IDBObjectStore::count"); 576 IDB_TRACE("IDBObjectStore::count");
576 if (isDeleted()) { 577 if (isDeleted()) {
577 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 578 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
578 return 0; 579 return 0;
579 } 580 }
580 if (m_transaction->isFinished()) { 581 if (m_transaction->isFinished()) {
581 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 582 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
582 return 0; 583 return 0;
583 } 584 }
584 if (!m_transaction->isActive()) { 585 if (!m_transaction->isActive()) {
585 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 586 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
586 return 0; 587 return 0;
587 } 588 }
588 589
589 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState); 590 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState);
590 if (exceptionState.hadException()) 591 if (exceptionState.hadException())
591 return 0; 592 return 0;
592 593
593 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 594 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
594 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, k eyRange.release(), new WebIDBCallbacks(request)); 595 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, k eyRange.release(), WebIDBCallbacksImpl::create(request).leakPtr());
595 return request.release(); 596 return request.release();
596 } 597 }
597 598
598 void IDBObjectStore::transactionFinished() 599 void IDBObjectStore::transactionFinished()
599 { 600 {
600 ASSERT(m_transaction->isFinished()); 601 ASSERT(m_transaction->isFinished());
601 602
602 // Break reference cycles. 603 // Break reference cycles.
603 m_indexMap.clear(); 604 m_indexMap.clear();
604 } 605 }
605 606
606 int64_t IDBObjectStore::findIndexId(const String& name) const 607 int64_t IDBObjectStore::findIndexId(const String& name) const
607 { 608 {
608 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) { 609 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) {
609 if (it->value.name == name) { 610 if (it->value.name == name) {
610 ASSERT(it->key != IDBIndexMetadata::InvalidId); 611 ASSERT(it->key != IDBIndexMetadata::InvalidId);
611 return it->key; 612 return it->key;
612 } 613 }
613 } 614 }
614 return IDBIndexMetadata::InvalidId; 615 return IDBIndexMetadata::InvalidId;
615 } 616 }
616 617
617 WebIDBDatabase* IDBObjectStore::backendDB() const 618 WebIDBDatabase* IDBObjectStore::backendDB() const
618 { 619 {
619 return m_transaction->backendDB(); 620 return m_transaction->backendDB();
620 } 621 }
621 622
622 } // namespace WebCore 623 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/indexeddb/IDBIndex.cpp ('k') | Source/modules/indexeddb/IDBRequestTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698