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

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

Issue 325683002: [IndexedDB] Use consistent enums on both sides of IPC. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 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
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 indexKey = IDBKey::createMultiEntryArray(indexKey->array()); 136 indexKey = IDBKey::createMultiEntryArray(indexKey->array());
137 137
138 for (size_t i = 0; i < indexKey->array().size(); ++i) 138 for (size_t i = 0; i < indexKey->array().size(); ++i)
139 indexKeys->append(indexKey->array()[i]); 139 indexKeys->append(indexKey->array()[i]);
140 } 140 }
141 } 141 }
142 142
143 IDBRequest* IDBObjectStore::add(ScriptState* scriptState, ScriptValue& value, co nst ScriptValue& key, ExceptionState& exceptionState) 143 IDBRequest* IDBObjectStore::add(ScriptState* scriptState, ScriptValue& value, co nst ScriptValue& key, ExceptionState& exceptionState)
144 { 144 {
145 IDB_TRACE("IDBObjectStore::add"); 145 IDB_TRACE("IDBObjectStore::add");
146 return put(scriptState, WebIDBDatabase::AddOnly, IDBAny::create(this), value , key, exceptionState); 146 return put(scriptState, blink::AddOnly, IDBAny::create(this), value, key, ex ceptionState);
147 } 147 }
148 148
149 IDBRequest* IDBObjectStore::put(ScriptState* scriptState, ScriptValue& value, co nst ScriptValue& key, ExceptionState& exceptionState) 149 IDBRequest* IDBObjectStore::put(ScriptState* scriptState, ScriptValue& value, co nst ScriptValue& key, ExceptionState& exceptionState)
150 { 150 {
151 IDB_TRACE("IDBObjectStore::put"); 151 IDB_TRACE("IDBObjectStore::put");
152 return put(scriptState, WebIDBDatabase::AddOrUpdate, IDBAny::create(this), v alue, key, exceptionState); 152 return put(scriptState, blink::AddOrUpdate, IDBAny::create(this), value, key , exceptionState);
153 } 153 }
154 154
155 IDBRequest* IDBObjectStore::put(ScriptState* scriptState, WebIDBDatabase::PutMod e putMode, IDBAny* source, ScriptValue& value, const ScriptValue& keyValue, Exce ptionState& exceptionState) 155 IDBRequest* IDBObjectStore::put(ScriptState* scriptState, blink::PutMode putMode , IDBAny* source, ScriptValue& value, const ScriptValue& keyValue, ExceptionStat e& exceptionState)
156 { 156 {
157 IDBKey* key = keyValue.isUndefined() ? nullptr : scriptValueToIDBKey(scriptS tate->isolate(), keyValue); 157 IDBKey* key = keyValue.isUndefined() ? nullptr : scriptValueToIDBKey(scriptS tate->isolate(), keyValue);
158 return put(scriptState, putMode, source, value, key, exceptionState); 158 return put(scriptState, putMode, source, value, key, exceptionState);
159 } 159 }
160 160
161 IDBRequest* IDBObjectStore::put(ScriptState* scriptState, WebIDBDatabase::PutMod e putMode, IDBAny* source, ScriptValue& value, IDBKey* key, ExceptionState& exce ptionState) 161 IDBRequest* IDBObjectStore::put(ScriptState* scriptState, blink::PutMode putMode , IDBAny* source, ScriptValue& value, IDBKey* key, ExceptionState& exceptionStat e)
162 { 162 {
163 if (isDeleted()) { 163 if (isDeleted()) {
164 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 164 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
165 return 0; 165 return 0;
166 } 166 }
167 if (m_transaction->isFinished() || m_transaction->isFinishing()) { 167 if (m_transaction->isFinished() || m_transaction->isFinishing()) {
168 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 168 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
169 return 0; 169 return 0;
170 } 170 }
171 if (!m_transaction->isActive()) { 171 if (!m_transaction->isActive()) {
(...skipping 15 matching lines...) Expand all
187 // FIXME: Add Blob/File/FileList support 187 // FIXME: Add Blob/File/FileList support
188 exceptionState.throwDOMException(DataCloneError, "The object store curre ntly does not support blob values."); 188 exceptionState.throwDOMException(DataCloneError, "The object store curre ntly does not support blob values.");
189 return 0; 189 return 0;
190 } 190 }
191 ASSERT(blobInfo.isEmpty()); 191 ASSERT(blobInfo.isEmpty());
192 192
193 const IDBKeyPath& keyPath = m_metadata.keyPath; 193 const IDBKeyPath& keyPath = m_metadata.keyPath;
194 const bool usesInLineKeys = !keyPath.isNull(); 194 const bool usesInLineKeys = !keyPath.isNull();
195 const bool hasKeyGenerator = autoIncrement(); 195 const bool hasKeyGenerator = autoIncrement();
196 196
197 if (putMode != WebIDBDatabase::CursorUpdate && usesInLineKeys && key) { 197 if (putMode != blink::CursorUpdate && usesInLineKeys && key) {
198 exceptionState.throwDOMException(DataError, "The object store uses in-li ne keys and the key parameter was provided."); 198 exceptionState.throwDOMException(DataError, "The object store uses in-li ne keys and the key parameter was provided.");
199 return 0; 199 return 0;
200 } 200 }
201 if (!usesInLineKeys && !hasKeyGenerator && !key) { 201 if (!usesInLineKeys && !hasKeyGenerator && !key) {
202 exceptionState.throwDOMException(DataError, "The object store uses out-o f-line keys and has no key generator and the key parameter was not provided."); 202 exceptionState.throwDOMException(DataError, "The object store uses out-o f-line keys and has no key generator and the key parameter was not provided.");
203 return 0; 203 return 0;
204 } 204 }
205 if (usesInLineKeys) { 205 if (usesInLineKeys) {
206 IDBKey* keyPathKey = createIDBKeyFromScriptValueAndKeyPath(scriptState-> isolate(), value, keyPath); 206 IDBKey* keyPathKey = createIDBKeyFromScriptValueAndKeyPath(scriptState-> isolate(), value, keyPath);
207 if (keyPathKey && !keyPathKey->isValid()) { 207 if (keyPathKey && !keyPathKey->isValid()) {
(...skipping 30 matching lines...) Expand all
238 generateIndexKeysForValue(scriptState->isolate(), it->value, value, &key s); 238 generateIndexKeysForValue(scriptState->isolate(), it->value, value, &key s);
239 indexIds.append(it->key); 239 indexIds.append(it->key);
240 indexKeys.append(keys); 240 indexKeys.append(keys);
241 } 241 }
242 242
243 IDBRequest* request = IDBRequest::create(scriptState, source, m_transaction. get()); 243 IDBRequest* request = IDBRequest::create(scriptState, source, m_transaction. get());
244 Vector<char> wireBytes; 244 Vector<char> wireBytes;
245 serializedValue->toWireBytes(wireBytes); 245 serializedValue->toWireBytes(wireBytes);
246 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); 246 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes);
247 247
248 backendDB()->put(m_transaction->id(), id(), blink::WebData(valueBuffer), blo bInfo, key, static_cast<WebIDBDatabase::PutMode>(putMode), WebIDBCallbacksImpl:: create(request).leakPtr(), indexIds, indexKeys); 248 backendDB()->put(m_transaction->id(), id(), blink::WebData(valueBuffer), blo bInfo, key, static_cast<blink::PutMode>(putMode), WebIDBCallbacksImpl::create(re quest).leakPtr(), indexIds, indexKeys);
249 return request; 249 return request;
250 } 250 }
251 251
252 IDBRequest* IDBObjectStore::deleteFunction(ScriptState* scriptState, const Scrip tValue& key, ExceptionState& exceptionState) 252 IDBRequest* IDBObjectStore::deleteFunction(ScriptState* scriptState, const Scrip tValue& key, ExceptionState& exceptionState)
253 { 253 {
254 IDB_TRACE("IDBObjectStore::delete"); 254 IDB_TRACE("IDBObjectStore::delete");
255 if (isDeleted()) { 255 if (isDeleted()) {
256 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 256 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
257 return 0; 257 return 0;
258 } 258 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); 451 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry);
452 IDBIndex* index = IDBIndex::create(metadata, this, m_transaction.get()); 452 IDBIndex* index = IDBIndex::create(metadata, this, m_transaction.get());
453 m_indexMap.set(name, index); 453 m_indexMap.set(name, index);
454 m_metadata.indexes.set(indexId, metadata); 454 m_metadata.indexes.set(indexId, metadata);
455 m_transaction->db()->indexCreated(id(), metadata); 455 m_transaction->db()->indexCreated(id(), metadata);
456 456
457 ASSERT(!exceptionState.hadException()); 457 ASSERT(!exceptionState.hadException());
458 if (exceptionState.hadException()) 458 if (exceptionState.hadException())
459 return 0; 459 return 0;
460 460
461 IDBRequest* indexRequest = openCursor(scriptState, static_cast<IDBKeyRange*> (0), blink::WebIDBCursor::Next, WebIDBDatabase::PreemptiveTask); 461 IDBRequest* indexRequest = openCursor(scriptState, static_cast<IDBKeyRange*> (0), blink::Next, blink::PreemptiveTask);
462 indexRequest->preventPropagation(); 462 indexRequest->preventPropagation();
463 463
464 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction. 464 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction.
465 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(scriptState, transaction()->db(), m_transaction->id(), id(), metadata); 465 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(scriptState, transaction()->db(), m_transaction->id(), id(), metadata);
466 indexRequest->setOnsuccess(indexPopulator); 466 indexRequest->setOnsuccess(indexPopulator);
467 return index; 467 return index;
468 } 468 }
469 469
470 IDBIndex* IDBObjectStore::index(const String& name, ExceptionState& exceptionSta te) 470 IDBIndex* IDBObjectStore::index(const String& name, ExceptionState& exceptionSta te)
471 { 471 {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 } 553 }
554 if (m_transaction->isFinished() || m_transaction->isFinishing()) { 554 if (m_transaction->isFinished() || m_transaction->isFinishing()) {
555 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 555 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
556 return 0; 556 return 0;
557 } 557 }
558 if (!m_transaction->isActive()) { 558 if (!m_transaction->isActive()) {
559 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 559 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
560 return 0; 560 return 0;
561 } 561 }
562 562
563 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt ring, exceptionState); 563 blink::Direction direction = IDBCursor::stringToDirection(directionString, e xceptionState);
564 if (exceptionState.hadException()) 564 if (exceptionState.hadException())
565 return 0; 565 return 0;
566 566
567 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC ontext(), range, exceptionState); 567 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC ontext(), range, exceptionState);
568 if (exceptionState.hadException()) 568 if (exceptionState.hadException())
569 return 0; 569 return 0;
570 570
571 if (!backendDB()) { 571 if (!backendDB()) {
572 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); 572 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage);
573 return 0; 573 return 0;
574 } 574 }
575 575
576 return openCursor(scriptState, keyRange, direction, WebIDBDatabase::NormalTa sk); 576 return openCursor(scriptState, keyRange, direction, blink::NormalTask);
577 } 577 }
578 578
579 IDBRequest* IDBObjectStore::openCursor(ScriptState* scriptState, IDBKeyRange* ra nge, WebIDBCursor::Direction direction, WebIDBDatabase::TaskType taskType) 579 IDBRequest* IDBObjectStore::openCursor(ScriptState* scriptState, IDBKeyRange* ra nge, blink::Direction direction, blink::TaskType taskType)
580 { 580 {
581 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); 581 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get());
582 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); 582 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction);
583 583
584 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, taskType, WebIDBCallbacksImpl::create(request).leak Ptr()); 584 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, taskType, WebIDBCallbacksImpl::create(request).leak Ptr());
585 return request; 585 return request;
586 } 586 }
587 587
588 IDBRequest* IDBObjectStore::openKeyCursor(ScriptState* scriptState, const Script Value& range, const String& directionString, ExceptionState& exceptionState) 588 IDBRequest* IDBObjectStore::openKeyCursor(ScriptState* scriptState, const Script Value& range, const String& directionString, ExceptionState& exceptionState)
589 { 589 {
590 IDB_TRACE("IDBObjectStore::openKeyCursor"); 590 IDB_TRACE("IDBObjectStore::openKeyCursor");
591 if (isDeleted()) { 591 if (isDeleted()) {
592 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 592 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
593 return 0; 593 return 0;
594 } 594 }
595 if (m_transaction->isFinished() || m_transaction->isFinishing()) { 595 if (m_transaction->isFinished() || m_transaction->isFinishing()) {
596 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 596 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
597 return 0; 597 return 0;
598 } 598 }
599 if (!m_transaction->isActive()) { 599 if (!m_transaction->isActive()) {
600 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 600 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
601 return 0; 601 return 0;
602 } 602 }
603 603
604 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt ring, exceptionState); 604 blink::Direction direction = IDBCursor::stringToDirection(directionString, e xceptionState);
605 if (exceptionState.hadException()) 605 if (exceptionState.hadException())
606 return 0; 606 return 0;
607 607
608 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC ontext(), range, exceptionState); 608 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC ontext(), range, exceptionState);
609 if (exceptionState.hadException()) 609 if (exceptionState.hadException())
610 return 0; 610 return 0;
611 611
612 if (!backendDB()) { 612 if (!backendDB()) {
613 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); 613 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage);
614 return 0; 614 return 0;
615 } 615 }
616 616
617 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); 617 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get());
618 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); 618 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction);
619 619
620 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, keyRange, direction, true, WebIDBDatabase::NormalTask, WebIDBCallbacksImpl:: create(request).leakPtr()); 620 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, keyRange, direction, true, blink::NormalTask, WebIDBCallbacksImpl::create(re quest).leakPtr());
621 return request; 621 return request;
622 } 622 }
623 623
624 IDBRequest* IDBObjectStore::count(ScriptState* scriptState, const ScriptValue& r ange, ExceptionState& exceptionState) 624 IDBRequest* IDBObjectStore::count(ScriptState* scriptState, const ScriptValue& r ange, ExceptionState& exceptionState)
625 { 625 {
626 IDB_TRACE("IDBObjectStore::count"); 626 IDB_TRACE("IDBObjectStore::count");
627 if (isDeleted()) { 627 if (isDeleted()) {
628 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 628 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
629 return 0; 629 return 0;
630 } 630 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 } 669 }
670 return IDBIndexMetadata::InvalidId; 670 return IDBIndexMetadata::InvalidId;
671 } 671 }
672 672
673 WebIDBDatabase* IDBObjectStore::backendDB() const 673 WebIDBDatabase* IDBObjectStore::backendDB() const
674 { 674 {
675 return m_transaction->backendDB(); 675 return m_transaction->backendDB();
676 } 676 }
677 677
678 } // namespace WebCore 678 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698