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

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: Incorporated review comments as build bot was failing with previous patch. 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
« no previous file with comments | « Source/modules/indexeddb/IDBObjectStore.h ('k') | Source/modules/indexeddb/IDBRequest.h » ('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 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::WebIDBPutModeAddOnly, IDBAny::create(this), v alue, key, exceptionState);
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::WebIDBPutModeAddOrUpdate, 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::WebIDBPutMode p utMode, IDBAny* source, ScriptValue& value, const ScriptValue& keyValue, Excepti onState& 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::WebIDBPutMode p utMode, IDBAny* source, ScriptValue& value, IDBKey* key, ExceptionState& excepti onState)
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()) {
172 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 172 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
173 return 0; 173 return 0;
174 } 174 }
175 if (m_transaction->isReadOnly()) { 175 if (m_transaction->isReadOnly()) {
176 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transaction ReadOnlyErrorMessage); 176 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transaction ReadOnlyErrorMessage);
177 return 0; 177 return 0;
178 } 178 }
179 179
180 Vector<WebBlobInfo> blobInfo; 180 Vector<WebBlobInfo> blobInfo;
181 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat e(value, &blobInfo, exceptionState, scriptState->isolate()); 181 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat e(value, &blobInfo, exceptionState, scriptState->isolate());
182 if (exceptionState.hadException()) 182 if (exceptionState.hadException())
183 return 0; 183 return 0;
184 184
185 const IDBKeyPath& keyPath = m_metadata.keyPath; 185 const IDBKeyPath& keyPath = m_metadata.keyPath;
186 const bool usesInLineKeys = !keyPath.isNull(); 186 const bool usesInLineKeys = !keyPath.isNull();
187 const bool hasKeyGenerator = autoIncrement(); 187 const bool hasKeyGenerator = autoIncrement();
188 188
189 if (putMode != WebIDBDatabase::CursorUpdate && usesInLineKeys && key) { 189 if (putMode != blink::WebIDBPutModeCursorUpdate && usesInLineKeys && key) {
190 exceptionState.throwDOMException(DataError, "The object store uses in-li ne keys and the key parameter was provided."); 190 exceptionState.throwDOMException(DataError, "The object store uses in-li ne keys and the key parameter was provided.");
191 return 0; 191 return 0;
192 } 192 }
193 if (!usesInLineKeys && !hasKeyGenerator && !key) { 193 if (!usesInLineKeys && !hasKeyGenerator && !key) {
194 exceptionState.throwDOMException(DataError, "The object store uses out-o f-line keys and has no key generator and the key parameter was not provided."); 194 exceptionState.throwDOMException(DataError, "The object store uses out-o f-line keys and has no key generator and the key parameter was not provided.");
195 return 0; 195 return 0;
196 } 196 }
197 if (usesInLineKeys) { 197 if (usesInLineKeys) {
198 IDBKey* keyPathKey = createIDBKeyFromScriptValueAndKeyPath(scriptState-> isolate(), value, keyPath); 198 IDBKey* keyPathKey = createIDBKeyFromScriptValueAndKeyPath(scriptState-> isolate(), value, keyPath);
199 if (keyPathKey && !keyPathKey->isValid()) { 199 if (keyPathKey && !keyPathKey->isValid()) {
(...skipping 30 matching lines...) Expand all
230 generateIndexKeysForValue(scriptState->isolate(), it->value, value, &key s); 230 generateIndexKeysForValue(scriptState->isolate(), it->value, value, &key s);
231 indexIds.append(it->key); 231 indexIds.append(it->key);
232 indexKeys.append(keys); 232 indexKeys.append(keys);
233 } 233 }
234 234
235 IDBRequest* request = IDBRequest::create(scriptState, source, m_transaction. get()); 235 IDBRequest* request = IDBRequest::create(scriptState, source, m_transaction. get());
236 Vector<char> wireBytes; 236 Vector<char> wireBytes;
237 serializedValue->toWireBytes(wireBytes); 237 serializedValue->toWireBytes(wireBytes);
238 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); 238 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes);
239 239
240 backendDB()->put(m_transaction->id(), id(), blink::WebData(valueBuffer), blo bInfo, key, static_cast<WebIDBDatabase::PutMode>(putMode), WebIDBCallbacksImpl:: create(request).leakPtr(), indexIds, indexKeys); 240 backendDB()->put(m_transaction->id(), id(), blink::WebData(valueBuffer), blo bInfo, key, static_cast<blink::WebIDBPutMode>(putMode), WebIDBCallbacksImpl::cre ate(request).leakPtr(), indexIds, indexKeys);
241 return request; 241 return request;
242 } 242 }
243 243
244 IDBRequest* IDBObjectStore::deleteFunction(ScriptState* scriptState, const Scrip tValue& key, ExceptionState& exceptionState) 244 IDBRequest* IDBObjectStore::deleteFunction(ScriptState* scriptState, const Scrip tValue& key, ExceptionState& exceptionState)
245 { 245 {
246 IDB_TRACE("IDBObjectStore::delete"); 246 IDB_TRACE("IDBObjectStore::delete");
247 if (isDeleted()) { 247 if (isDeleted()) {
248 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 248 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
249 return 0; 249 return 0;
250 } 250 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); 443 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry);
444 IDBIndex* index = IDBIndex::create(metadata, this, m_transaction.get()); 444 IDBIndex* index = IDBIndex::create(metadata, this, m_transaction.get());
445 m_indexMap.set(name, index); 445 m_indexMap.set(name, index);
446 m_metadata.indexes.set(indexId, metadata); 446 m_metadata.indexes.set(indexId, metadata);
447 m_transaction->db()->indexCreated(id(), metadata); 447 m_transaction->db()->indexCreated(id(), metadata);
448 448
449 ASSERT(!exceptionState.hadException()); 449 ASSERT(!exceptionState.hadException());
450 if (exceptionState.hadException()) 450 if (exceptionState.hadException())
451 return 0; 451 return 0;
452 452
453 IDBRequest* indexRequest = openCursor(scriptState, static_cast<IDBKeyRange*> (0), blink::WebIDBCursor::Next, WebIDBDatabase::PreemptiveTask); 453 IDBRequest* indexRequest = openCursor(scriptState, static_cast<IDBKeyRange*> (0), blink::WebIDBCursorDirectionNext, blink::WebIDBTaskTypePreemptive);
454 indexRequest->preventPropagation(); 454 indexRequest->preventPropagation();
455 455
456 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction. 456 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction.
457 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(scriptState, transaction()->db(), m_transaction->id(), id(), metadata); 457 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(scriptState, transaction()->db(), m_transaction->id(), id(), metadata);
458 indexRequest->setOnsuccess(indexPopulator); 458 indexRequest->setOnsuccess(indexPopulator);
459 return index; 459 return index;
460 } 460 }
461 461
462 IDBIndex* IDBObjectStore::index(const String& name, ExceptionState& exceptionSta te) 462 IDBIndex* IDBObjectStore::index(const String& name, ExceptionState& exceptionSta te)
463 { 463 {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 } 545 }
546 if (m_transaction->isFinished() || m_transaction->isFinishing()) { 546 if (m_transaction->isFinished() || m_transaction->isFinishing()) {
547 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 547 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
548 return 0; 548 return 0;
549 } 549 }
550 if (!m_transaction->isActive()) { 550 if (!m_transaction->isActive()) {
551 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 551 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
552 return 0; 552 return 0;
553 } 553 }
554 554
555 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt ring, exceptionState); 555 blink::WebIDBCursorDirection direction = IDBCursor::stringToDirection(direct ionString, exceptionState);
556 if (exceptionState.hadException()) 556 if (exceptionState.hadException())
557 return 0; 557 return 0;
558 558
559 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC ontext(), range, exceptionState); 559 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC ontext(), range, exceptionState);
560 if (exceptionState.hadException()) 560 if (exceptionState.hadException())
561 return 0; 561 return 0;
562 562
563 if (!backendDB()) { 563 if (!backendDB()) {
564 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); 564 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage);
565 return 0; 565 return 0;
566 } 566 }
567 567
568 return openCursor(scriptState, keyRange, direction, WebIDBDatabase::NormalTa sk); 568 return openCursor(scriptState, keyRange, direction, blink::WebIDBTaskTypeNor mal);
569 } 569 }
570 570
571 IDBRequest* IDBObjectStore::openCursor(ScriptState* scriptState, IDBKeyRange* ra nge, WebIDBCursor::Direction direction, WebIDBDatabase::TaskType taskType) 571 IDBRequest* IDBObjectStore::openCursor(ScriptState* scriptState, IDBKeyRange* ra nge, blink::WebIDBCursorDirection direction, blink::WebIDBTaskType taskType)
572 { 572 {
573 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); 573 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get());
574 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); 574 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction);
575 575
576 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, taskType, WebIDBCallbacksImpl::create(request).leak Ptr()); 576 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, taskType, WebIDBCallbacksImpl::create(request).leak Ptr());
577 return request; 577 return request;
578 } 578 }
579 579
580 IDBRequest* IDBObjectStore::openKeyCursor(ScriptState* scriptState, const Script Value& range, const String& directionString, ExceptionState& exceptionState) 580 IDBRequest* IDBObjectStore::openKeyCursor(ScriptState* scriptState, const Script Value& range, const String& directionString, ExceptionState& exceptionState)
581 { 581 {
582 IDB_TRACE("IDBObjectStore::openKeyCursor"); 582 IDB_TRACE("IDBObjectStore::openKeyCursor");
583 if (isDeleted()) { 583 if (isDeleted()) {
584 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 584 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
585 return 0; 585 return 0;
586 } 586 }
587 if (m_transaction->isFinished() || m_transaction->isFinishing()) { 587 if (m_transaction->isFinished() || m_transaction->isFinishing()) {
588 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 588 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
589 return 0; 589 return 0;
590 } 590 }
591 if (!m_transaction->isActive()) { 591 if (!m_transaction->isActive()) {
592 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 592 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
593 return 0; 593 return 0;
594 } 594 }
595 595
596 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt ring, exceptionState); 596 blink::WebIDBCursorDirection direction = IDBCursor::stringToDirection(direct ionString, exceptionState);
597 if (exceptionState.hadException()) 597 if (exceptionState.hadException())
598 return 0; 598 return 0;
599 599
600 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC ontext(), range, exceptionState); 600 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC ontext(), range, exceptionState);
601 if (exceptionState.hadException()) 601 if (exceptionState.hadException())
602 return 0; 602 return 0;
603 603
604 if (!backendDB()) { 604 if (!backendDB()) {
605 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); 605 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage);
606 return 0; 606 return 0;
607 } 607 }
608 608
609 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); 609 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get());
610 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); 610 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction);
611 611
612 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, keyRange, direction, true, WebIDBDatabase::NormalTask, WebIDBCallbacksImpl:: create(request).leakPtr()); 612 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, keyRange, direction, true, blink::WebIDBTaskTypeNormal, WebIDBCallbacksImpl: :create(request).leakPtr());
613 return request; 613 return request;
614 } 614 }
615 615
616 IDBRequest* IDBObjectStore::count(ScriptState* scriptState, const ScriptValue& r ange, ExceptionState& exceptionState) 616 IDBRequest* IDBObjectStore::count(ScriptState* scriptState, const ScriptValue& r ange, ExceptionState& exceptionState)
617 { 617 {
618 IDB_TRACE("IDBObjectStore::count"); 618 IDB_TRACE("IDBObjectStore::count");
619 if (isDeleted()) { 619 if (isDeleted()) {
620 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 620 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
621 return 0; 621 return 0;
622 } 622 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 } 661 }
662 return IDBIndexMetadata::InvalidId; 662 return IDBIndexMetadata::InvalidId;
663 } 663 }
664 664
665 WebIDBDatabase* IDBObjectStore::backendDB() const 665 WebIDBDatabase* IDBObjectStore::backendDB() const
666 { 666 {
667 return m_transaction->backendDB(); 667 return m_transaction->backendDB();
668 } 668 }
669 669
670 } // namespace WebCore 670 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/indexeddb/IDBObjectStore.h ('k') | Source/modules/indexeddb/IDBRequest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698