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

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

Issue 22893058: IndexedDB: Replace IDL operation overloading with ScriptValue handling (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove assert, per review feedback Created 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/indexeddb/IDBObjectStore.h ('k') | Source/modules/indexeddb/IDBObjectStore.idl » ('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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 PassRefPtr<DOMStringList> IDBObjectStore::indexNames() const 63 PassRefPtr<DOMStringList> IDBObjectStore::indexNames() const
64 { 64 {
65 IDB_TRACE("IDBObjectStore::indexNames"); 65 IDB_TRACE("IDBObjectStore::indexNames");
66 RefPtr<DOMStringList> indexNames = DOMStringList::create(); 66 RefPtr<DOMStringList> indexNames = DOMStringList::create();
67 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) 67 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it)
68 indexNames->append(it->value.name); 68 indexNames->append(it->value.name);
69 indexNames->sort(); 69 indexNames->sort();
70 return indexNames.release(); 70 return indexNames.release();
71 } 71 }
72 72
73 PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, Pass RefPtr<IDBKeyRange> keyRange, ExceptionState& es) 73 PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, cons t ScriptValue& key, ExceptionState& es)
74 { 74 {
75 IDB_TRACE("IDBObjectStore::get"); 75 IDB_TRACE("IDBObjectStore::get");
76 if (isDeleted()) { 76 if (isDeleted()) {
77 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage); 77 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage);
78 return 0; 78 return 0;
79 } 79 }
80 if (!keyRange) {
81 es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage );
82 return 0;
83 }
84 if (m_transaction->isFinished()) { 80 if (m_transaction->isFinished()) {
85 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); 81 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage);
86 return 0; 82 return 0;
87 } 83 }
88 if (!m_transaction->isActive()) { 84 if (!m_transaction->isActive()) {
89 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); 85 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage);
90 return 0; 86 return 0;
91 } 87 }
88 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, es );
89 if (es.hadException())
90 return 0;
91 if (!keyRange) {
92 es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage );
93 return 0;
94 }
95
92 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 96 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
93 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, key Range, false, request); 97 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, key Range, false, request);
94 return request.release(); 98 return request.release();
95 } 99 }
96 100
97 PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, cons t ScriptValue& key, ExceptionState& es)
98 {
99 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es);
100 if (es.hadException())
101 return 0;
102 return get(context, keyRange.release(), es);
103 }
104
105 static void generateIndexKeysForValue(DOMRequestState* requestState, const IDBIn dexMetadata& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::Inde xKeys* indexKeys) 101 static void generateIndexKeysForValue(DOMRequestState* requestState, const IDBIn dexMetadata& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::Inde xKeys* indexKeys)
106 { 102 {
107 ASSERT(indexKeys); 103 ASSERT(indexKeys);
108 RefPtr<IDBKey> indexKey = createIDBKeyFromScriptValueAndKeyPath(requestState , objectValue, indexMetadata.keyPath); 104 RefPtr<IDBKey> indexKey = createIDBKeyFromScriptValueAndKeyPath(requestState , objectValue, indexMetadata.keyPath);
109 105
110 if (!indexKey) 106 if (!indexKey)
111 return; 107 return;
112 108
113 if (!indexMetadata.multiEntry || indexKey->type() != IDBKey::ArrayType) { 109 if (!indexMetadata.multiEntry || indexKey->type() != IDBKey::ArrayType) {
114 if (!indexKey->isValid()) 110 if (!indexKey->isValid())
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 222 }
227 223
228 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti on.get()); 224 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti on.get());
229 Vector<char> wireBytes; 225 Vector<char> wireBytes;
230 serializedValue->toWireBytes(wireBytes); 226 serializedValue->toWireBytes(wireBytes);
231 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); 227 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes);
232 backendDB()->put(m_transaction->id(), id(), valueBuffer, key.release(), stat ic_cast<IDBDatabaseBackendInterface::PutMode>(putMode), request, indexIds, index Keys); 228 backendDB()->put(m_transaction->id(), id(), valueBuffer, key.release(), stat ic_cast<IDBDatabaseBackendInterface::PutMode>(putMode), request, indexIds, index Keys);
233 return request.release(); 229 return request.release();
234 } 230 }
235 231
236 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co ntext, PassRefPtr<IDBKeyRange> keyRange, ExceptionState& es) 232 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co ntext, const ScriptValue& key, ExceptionState& es)
237 { 233 {
238 IDB_TRACE("IDBObjectStore::delete"); 234 IDB_TRACE("IDBObjectStore::delete");
239 if (isDeleted()) { 235 if (isDeleted()) {
240 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage); 236 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage);
241 return 0; 237 return 0;
242 } 238 }
243 if (m_transaction->isFinished()) { 239 if (m_transaction->isFinished()) {
244 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); 240 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage);
245 return 0; 241 return 0;
246 } 242 }
247 if (!m_transaction->isActive()) { 243 if (!m_transaction->isActive()) {
248 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); 244 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage);
249 return 0; 245 return 0;
250 } 246 }
251 if (m_transaction->isReadOnly()) { 247 if (m_transaction->isReadOnly()) {
252 es.throwDOMException(ReadOnlyError); 248 es.throwDOMException(ReadOnlyError);
253 return 0; 249 return 0;
254 } 250 }
251
252 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, es );
253 if (es.hadException())
254 return 0;
255 if (!keyRange) { 255 if (!keyRange) {
256 es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage ); 256 es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage );
257 return 0; 257 return 0;
258 } 258 }
259 259
260 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 260 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
261 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, request); 261 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, request);
262 return request.release(); 262 return request.release();
263 } 263 }
264 264
265 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co ntext, const ScriptValue& key, ExceptionState& es)
266 {
267 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es);
268 if (es.hadException())
269 return 0;
270 return deleteFunction(context, keyRange.release(), es);
271 }
272
273 PassRefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext* context, Ex ceptionState& es) 265 PassRefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext* context, Ex ceptionState& es)
274 { 266 {
275 IDB_TRACE("IDBObjectStore::clear"); 267 IDB_TRACE("IDBObjectStore::clear");
276 if (isDeleted()) { 268 if (isDeleted()) {
277 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage); 269 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage);
278 return 0; 270 return 0;
279 } 271 }
280 if (m_transaction->isFinished()) { 272 if (m_transaction->isFinished()) {
281 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); 273 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage);
282 return 0; 274 return 0;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); 413 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry);
422 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get( )); 414 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get( ));
423 m_indexMap.set(name, index); 415 m_indexMap.set(name, index);
424 m_metadata.indexes.set(indexId, metadata); 416 m_metadata.indexes.set(indexId, metadata);
425 m_transaction->db()->indexCreated(id(), metadata); 417 m_transaction->db()->indexCreated(id(), metadata);
426 418
427 ASSERT(!es.hadException()); 419 ASSERT(!es.hadException());
428 if (es.hadException()) 420 if (es.hadException())
429 return 0; 421 return 0;
430 422
431 RefPtr<IDBRequest> indexRequest = openCursor(context, static_cast<IDBKeyRang e*>(0), IDBCursor::directionNext(), IDBDatabaseBackendInterface::PreemptiveTask, es); 423 RefPtr<IDBRequest> indexRequest = openCursor(context, static_cast<IDBKeyRang e*>(0), IndexedDB::CursorNext, IDBDatabaseBackendInterface::PreemptiveTask);
432 ASSERT(!es.hadException());
433 if (es.hadException())
434 return 0;
435 indexRequest->preventPropagation(); 424 indexRequest->preventPropagation();
436 425
437 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction. 426 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction.
438 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(backendDB(), m_transaction->id(), id(), metadata); 427 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(backendDB(), m_transaction->id(), id(), metadata);
439 indexRequest->setOnsuccess(indexPopulator); 428 indexRequest->setOnsuccess(indexPopulator);
440 429
441 return index.release(); 430 return index.release();
442 } 431 }
443 432
444 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& e s) 433 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& e s)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 496
508 m_metadata.indexes.remove(indexId); 497 m_metadata.indexes.remove(indexId);
509 m_transaction->db()->indexDeleted(id(), indexId); 498 m_transaction->db()->indexDeleted(id(), indexId);
510 IDBIndexMap::iterator it = m_indexMap.find(name); 499 IDBIndexMap::iterator it = m_indexMap.find(name);
511 if (it != m_indexMap.end()) { 500 if (it != m_indexMap.end()) {
512 it->value->markDeleted(); 501 it->value->markDeleted();
513 m_indexMap.remove(name); 502 m_indexMap.remove(name);
514 } 503 }
515 } 504 }
516 505
517 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex t, PassRefPtr<IDBKeyRange> range, const String& directionString, IDBDatabaseBack endInterface::TaskType taskType, ExceptionState& es) 506 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex t, const ScriptValue& range, const String& directionString, ExceptionState& es)
518 { 507 {
519 IDB_TRACE("IDBObjectStore::openCursor"); 508 IDB_TRACE("IDBObjectStore::openCursor");
520 if (isDeleted()) { 509 if (isDeleted()) {
521 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage); 510 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage);
522 return 0; 511 return 0;
523 } 512 }
524 if (m_transaction->isFinished()) { 513 if (m_transaction->isFinished()) {
525 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); 514 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage);
526 return 0; 515 return 0;
527 } 516 }
528 if (!m_transaction->isActive()) { 517 if (!m_transaction->isActive()) {
529 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); 518 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage);
530 return 0; 519 return 0;
531 } 520 }
521
532 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio nString, es); 522 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio nString, es);
533 if (es.hadException()) 523 if (es.hadException())
534 return 0; 524 return 0;
535 525
526 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, es);
527 if (es.hadException())
528 return 0;
529
530 return openCursor(context, keyRange, direction, IDBDatabaseBackendInterface: :NormalTask);
531 }
532
533 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex t, PassRefPtr<IDBKeyRange> range, IndexedDB::CursorDirection direction, IDBDatab aseBackendInterface::TaskType taskType)
534 {
536 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 535 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
537 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); 536 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction);
538 537
539 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, static_cast<IDBDatabaseBackendInterface::TaskType>( taskType), request); 538 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, taskType, request);
540 return request.release(); 539 return request.release();
541 } 540 }
542 541
543 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex t, const ScriptValue& key, const String& direction, ExceptionState& es) 542 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, co nst ScriptValue& range, ExceptionState& es)
544 {
545 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es);
546 if (es.hadException())
547 return 0;
548 return openCursor(context, keyRange.release(), direction, es);
549 }
550
551 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, Pa ssRefPtr<IDBKeyRange> range, ExceptionState& es)
552 { 543 {
553 IDB_TRACE("IDBObjectStore::count"); 544 IDB_TRACE("IDBObjectStore::count");
554 if (isDeleted()) { 545 if (isDeleted()) {
555 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage); 546 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage);
556 return 0; 547 return 0;
557 } 548 }
558 if (m_transaction->isFinished()) { 549 if (m_transaction->isFinished()) {
559 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); 550 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage);
560 return 0; 551 return 0;
561 } 552 }
562 if (!m_transaction->isActive()) { 553 if (!m_transaction->isActive()) {
563 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); 554 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage);
564 return 0; 555 return 0;
565 } 556 }
557
558 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, es);
559 if (es.hadException())
560 return 0;
561
566 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 562 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
567 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, r ange, request); 563 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, k eyRange, request);
568 return request.release(); 564 return request.release();
569 } 565 }
570 566
571 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, co nst ScriptValue& key, ExceptionState& es)
572 {
573 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es);
574 if (es.hadException())
575 return 0;
576 return count(context, keyRange.release(), es);
577 }
578
579 void IDBObjectStore::transactionFinished() 567 void IDBObjectStore::transactionFinished()
580 { 568 {
581 ASSERT(m_transaction->isFinished()); 569 ASSERT(m_transaction->isFinished());
582 570
583 // Break reference cycles. 571 // Break reference cycles.
584 m_indexMap.clear(); 572 m_indexMap.clear();
585 } 573 }
586 574
587 int64_t IDBObjectStore::findIndexId(const String& name) const 575 int64_t IDBObjectStore::findIndexId(const String& name) const
588 { 576 {
589 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) { 577 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) {
590 if (it->value.name == name) { 578 if (it->value.name == name) {
591 ASSERT(it->key != IDBIndexMetadata::InvalidId); 579 ASSERT(it->key != IDBIndexMetadata::InvalidId);
592 return it->key; 580 return it->key;
593 } 581 }
594 } 582 }
595 return IDBIndexMetadata::InvalidId; 583 return IDBIndexMetadata::InvalidId;
596 } 584 }
597 585
598 IDBDatabaseBackendInterface* IDBObjectStore::backendDB() const 586 IDBDatabaseBackendInterface* IDBObjectStore::backendDB() const
599 { 587 {
600 return m_transaction->backendDB(); 588 return m_transaction->backendDB();
601 } 589 }
602 590
603 } // namespace WebCore 591 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/indexeddb/IDBObjectStore.h ('k') | Source/modules/indexeddb/IDBObjectStore.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698