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

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

Issue 170603003: Use nullptr_t for RefPtr, PassRefPtr and RawPtr. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Final rebase Created 6 years, 10 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/IDBKeyRange.cpp ('k') | Source/modules/indexeddb/IDBOpenDBRequest.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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 indexNames->append(it->value.name); 75 indexNames->append(it->value.name);
76 indexNames->sort(); 76 indexNames->sort();
77 return indexNames.release(); 77 return indexNames.release();
78 } 78 }
79 79
80 PassRefPtr<IDBRequest> IDBObjectStore::get(ExecutionContext* context, const Scri ptValue& key, ExceptionState& exceptionState) 80 PassRefPtr<IDBRequest> IDBObjectStore::get(ExecutionContext* context, const Scri ptValue& key, ExceptionState& exceptionState)
81 { 81 {
82 IDB_TRACE("IDBObjectStore::get"); 82 IDB_TRACE("IDBObjectStore::get");
83 if (isDeleted()) { 83 if (isDeleted()) {
84 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 84 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
85 return 0; 85 return nullptr;
86 } 86 }
87 if (m_transaction->isFinished()) { 87 if (m_transaction->isFinished()) {
88 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 88 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
89 return 0; 89 return nullptr;
90 } 90 }
91 if (!m_transaction->isActive()) { 91 if (!m_transaction->isActive()) {
92 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 92 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
93 return 0; 93 return nullptr;
94 } 94 }
95 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex ceptionState); 95 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex ceptionState);
96 if (exceptionState.hadException()) 96 if (exceptionState.hadException())
97 return 0; 97 return nullptr;
98 if (!keyRange) { 98 if (!keyRange) {
99 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage); 99 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage);
100 return 0; 100 return nullptr;
101 } 101 }
102 102
103 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 103 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
104 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, key Range.release(), false, WebIDBCallbacksImpl::create(request).leakPtr()); 104 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, key Range.release(), false, WebIDBCallbacksImpl::create(request).leakPtr());
105 return request.release(); 105 return request.release();
106 } 106 }
107 107
108 static void generateIndexKeysForValue(DOMRequestState* requestState, const IDBIn dexMetadata& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::Inde xKeys* indexKeys) 108 static void generateIndexKeysForValue(DOMRequestState* requestState, const IDBIn dexMetadata& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::Inde xKeys* indexKeys)
109 { 109 {
110 ASSERT(indexKeys); 110 ASSERT(indexKeys);
(...skipping 26 matching lines...) Expand all
137 PassRefPtr<IDBRequest> IDBObjectStore::put(ScriptState* state, ScriptValue& valu e, const ScriptValue& key, ExceptionState& exceptionState) 137 PassRefPtr<IDBRequest> IDBObjectStore::put(ScriptState* state, ScriptValue& valu e, const ScriptValue& key, ExceptionState& exceptionState)
138 { 138 {
139 IDB_TRACE("IDBObjectStore::put"); 139 IDB_TRACE("IDBObjectStore::put");
140 return put(WebIDBDatabase::AddOrUpdate, IDBAny::create(this), state, value, key, exceptionState); 140 return put(WebIDBDatabase::AddOrUpdate, IDBAny::create(this), state, value, key, exceptionState);
141 } 141 }
142 142
143 PassRefPtr<IDBRequest> IDBObjectStore::put(WebIDBDatabase::PutMode putMode, Pass RefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, const ScriptValue & keyValue, ExceptionState& exceptionState) 143 PassRefPtr<IDBRequest> IDBObjectStore::put(WebIDBDatabase::PutMode putMode, Pass RefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, const ScriptValue & keyValue, ExceptionState& exceptionState)
144 { 144 {
145 ExecutionContext* context = state->executionContext(); 145 ExecutionContext* context = state->executionContext();
146 DOMRequestState requestState(context); 146 DOMRequestState requestState(context);
147 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&reque stState, keyValue); 147 RefPtr<IDBKey> key = keyValue.isUndefined() ? nullptr : scriptValueToIDBKey( &requestState, keyValue);
148 return put(putMode, source, state, value, key.release(), exceptionState); 148 return put(putMode, source, state, value, key.release(), exceptionState);
149 } 149 }
150 150
151 PassRefPtr<IDBRequest> IDBObjectStore::put(WebIDBDatabase::PutMode putMode, Pass RefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, PassRefPtr<IDBKey > prpKey, ExceptionState& exceptionState) 151 PassRefPtr<IDBRequest> IDBObjectStore::put(WebIDBDatabase::PutMode putMode, Pass RefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, PassRefPtr<IDBKey > prpKey, ExceptionState& exceptionState)
152 { 152 {
153 RefPtr<IDBKey> key = prpKey; 153 RefPtr<IDBKey> key = prpKey;
154 if (isDeleted()) { 154 if (isDeleted()) {
155 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 155 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
156 return 0; 156 return nullptr;
157 } 157 }
158 if (m_transaction->isFinished()) { 158 if (m_transaction->isFinished()) {
159 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 159 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
160 return 0; 160 return nullptr;
161 } 161 }
162 if (!m_transaction->isActive()) { 162 if (!m_transaction->isActive()) {
163 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 163 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
164 return 0; 164 return nullptr;
165 } 165 }
166 if (m_transaction->isReadOnly()) { 166 if (m_transaction->isReadOnly()) {
167 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transaction ReadOnlyErrorMessage); 167 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transaction ReadOnlyErrorMessage);
168 return 0; 168 return nullptr;
169 } 169 }
170 170
171 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat e(value, exceptionState, state); 171 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat e(value, exceptionState, state);
172 if (exceptionState.hadException()) 172 if (exceptionState.hadException())
173 return 0; 173 return nullptr;
174 174
175 if (serializedValue->containsBlobs()) { 175 if (serializedValue->containsBlobs()) {
176 // FIXME: Add Blob/File/FileList support 176 // FIXME: Add Blob/File/FileList support
177 exceptionState.throwDOMException(DataCloneError, "The object store curre ntly does not support blob values."); 177 exceptionState.throwDOMException(DataCloneError, "The object store curre ntly does not support blob values.");
178 return 0; 178 return nullptr;
179 } 179 }
180 180
181 const IDBKeyPath& keyPath = m_metadata.keyPath; 181 const IDBKeyPath& keyPath = m_metadata.keyPath;
182 const bool usesInLineKeys = !keyPath.isNull(); 182 const bool usesInLineKeys = !keyPath.isNull();
183 const bool hasKeyGenerator = autoIncrement(); 183 const bool hasKeyGenerator = autoIncrement();
184 184
185 ExecutionContext* context = state->executionContext(); 185 ExecutionContext* context = state->executionContext();
186 DOMRequestState requestState(context); 186 DOMRequestState requestState(context);
187 187
188 if (putMode != WebIDBDatabase::CursorUpdate && usesInLineKeys && key) { 188 if (putMode != WebIDBDatabase::CursorUpdate && usesInLineKeys && key) {
189 exceptionState.throwDOMException(DataError, "The object store uses in-li ne keys and the key parameter was provided."); 189 exceptionState.throwDOMException(DataError, "The object store uses in-li ne keys and the key parameter was provided.");
190 return 0; 190 return nullptr;
191 } 191 }
192 if (!usesInLineKeys && !hasKeyGenerator && !key) { 192 if (!usesInLineKeys && !hasKeyGenerator && !key) {
193 exceptionState.throwDOMException(DataError, "The object store uses out-o f-line keys and has no key generator and the key parameter was not provided."); 193 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 return 0; 194 return nullptr;
195 } 195 }
196 if (usesInLineKeys) { 196 if (usesInLineKeys) {
197 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(&reque stState, value, keyPath); 197 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(&reque stState, value, keyPath);
198 if (keyPathKey && !keyPathKey->isValid()) { 198 if (keyPathKey && !keyPathKey->isValid()) {
199 exceptionState.throwDOMException(DataError, "Evaluating the object s tore's key path yielded a value that is not a valid key."); 199 exceptionState.throwDOMException(DataError, "Evaluating the object s tore's key path yielded a value that is not a valid key.");
200 return 0; 200 return nullptr;
201 } 201 }
202 if (!hasKeyGenerator && !keyPathKey) { 202 if (!hasKeyGenerator && !keyPathKey) {
203 exceptionState.throwDOMException(DataError, "Evaluating the object s tore's key path did not yield a value."); 203 exceptionState.throwDOMException(DataError, "Evaluating the object s tore's key path did not yield a value.");
204 return 0; 204 return nullptr;
205 } 205 }
206 if (hasKeyGenerator && !keyPathKey) { 206 if (hasKeyGenerator && !keyPathKey) {
207 if (!canInjectIDBKeyIntoScriptValue(&requestState, value, keyPath)) { 207 if (!canInjectIDBKeyIntoScriptValue(&requestState, value, keyPath)) {
208 exceptionState.throwDOMException(DataError, "A generated key cou ld not be inserted into the value."); 208 exceptionState.throwDOMException(DataError, "A generated key cou ld not be inserted into the value.");
209 return 0; 209 return nullptr;
210 } 210 }
211 } 211 }
212 if (keyPathKey) 212 if (keyPathKey)
213 key = keyPathKey; 213 key = keyPathKey;
214 } 214 }
215 if (key && !key->isValid()) { 215 if (key && !key->isValid()) {
216 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro rMessage); 216 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro rMessage);
217 return 0; 217 return nullptr;
218 } 218 }
219 219
220 Vector<int64_t> indexIds; 220 Vector<int64_t> indexIds;
221 Vector<IndexKeys> indexKeys; 221 Vector<IndexKeys> indexKeys;
222 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) { 222 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) {
223 IndexKeys keys; 223 IndexKeys keys;
224 generateIndexKeysForValue(&requestState, it->value, value, &keys); 224 generateIndexKeysForValue(&requestState, it->value, value, &keys);
225 indexIds.append(it->key); 225 indexIds.append(it->key);
226 indexKeys.append(keys); 226 indexKeys.append(keys);
227 } 227 }
228 228
229 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti on.get()); 229 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti on.get());
230 Vector<char> wireBytes; 230 Vector<char> wireBytes;
231 serializedValue->toWireBytes(wireBytes); 231 serializedValue->toWireBytes(wireBytes);
232 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); 232 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes);
233 backendDB()->put(m_transaction->id(), id(), blink::WebData(valueBuffer), key .release(), static_cast<WebIDBDatabase::PutMode>(putMode), WebIDBCallbacksImpl:: create(request).leakPtr(), indexIds, indexKeys); 233 backendDB()->put(m_transaction->id(), id(), blink::WebData(valueBuffer), key .release(), static_cast<WebIDBDatabase::PutMode>(putMode), WebIDBCallbacksImpl:: create(request).leakPtr(), indexIds, indexKeys);
234 return request.release(); 234 return request.release();
235 } 235 }
236 236
237 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ExecutionContext* context, const ScriptValue& key, ExceptionState& exceptionState) 237 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ExecutionContext* context, const ScriptValue& key, ExceptionState& exceptionState)
238 { 238 {
239 IDB_TRACE("IDBObjectStore::delete"); 239 IDB_TRACE("IDBObjectStore::delete");
240 if (isDeleted()) { 240 if (isDeleted()) {
241 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 241 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
242 return 0; 242 return nullptr;
243 } 243 }
244 if (m_transaction->isFinished()) { 244 if (m_transaction->isFinished()) {
245 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 245 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
246 return 0; 246 return nullptr;
247 } 247 }
248 if (!m_transaction->isActive()) { 248 if (!m_transaction->isActive()) {
249 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 249 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
250 return 0; 250 return nullptr;
251 } 251 }
252 if (m_transaction->isReadOnly()) { 252 if (m_transaction->isReadOnly()) {
253 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transaction ReadOnlyErrorMessage); 253 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transaction ReadOnlyErrorMessage);
254 return 0; 254 return nullptr;
255 } 255 }
256 256
257 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex ceptionState); 257 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex ceptionState);
258 if (exceptionState.hadException()) 258 if (exceptionState.hadException())
259 return 0; 259 return nullptr;
260 if (!keyRange) { 260 if (!keyRange) {
261 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage); 261 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage);
262 return 0; 262 return nullptr;
263 } 263 }
264 264
265 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 265 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
266 backendDB()->deleteRange(m_transaction->id(), id(), keyRange.release(), WebI DBCallbacksImpl::create(request).leakPtr()); 266 backendDB()->deleteRange(m_transaction->id(), id(), keyRange.release(), WebI DBCallbacksImpl::create(request).leakPtr());
267 return request.release(); 267 return request.release();
268 } 268 }
269 269
270 PassRefPtr<IDBRequest> IDBObjectStore::clear(ExecutionContext* context, Exceptio nState& exceptionState) 270 PassRefPtr<IDBRequest> IDBObjectStore::clear(ExecutionContext* context, Exceptio nState& exceptionState)
271 { 271 {
272 IDB_TRACE("IDBObjectStore::clear"); 272 IDB_TRACE("IDBObjectStore::clear");
273 if (isDeleted()) { 273 if (isDeleted()) {
274 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 274 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
275 return 0; 275 return nullptr;
276 } 276 }
277 if (m_transaction->isFinished()) { 277 if (m_transaction->isFinished()) {
278 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 278 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
279 return 0; 279 return nullptr;
280 } 280 }
281 if (!m_transaction->isActive()) { 281 if (!m_transaction->isActive()) {
282 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 282 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
283 return 0; 283 return nullptr;
284 } 284 }
285 if (m_transaction->isReadOnly()) { 285 if (m_transaction->isReadOnly()) {
286 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transaction ReadOnlyErrorMessage); 286 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transaction ReadOnlyErrorMessage);
287 return 0; 287 return nullptr;
288 } 288 }
289 289
290 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 290 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
291 backendDB()->clear(m_transaction->id(), id(), WebIDBCallbacksImpl::create(re quest).leakPtr()); 291 backendDB()->clear(m_transaction->id(), id(), WebIDBCallbacksImpl::create(re quest).leakPtr());
292 return request.release(); 292 return request.release();
293 } 293 }
294 294
295 namespace { 295 namespace {
296 // This class creates the index keys for a given index by extracting 296 // This class creates the index keys for a given index by extracting
297 // them from the SerializedScriptValue, for all the existing values in 297 // them from the SerializedScriptValue, for all the existing values in
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 options.get("multiEntry", multiEntry); 371 options.get("multiEntry", multiEntry);
372 372
373 return createIndex(context, name, keyPath, unique, multiEntry, exceptionStat e); 373 return createIndex(context, name, keyPath, unique, multiEntry, exceptionStat e);
374 } 374 }
375 375
376 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ExecutionContext* context, cons t String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, Excepti onState& exceptionState) 376 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ExecutionContext* context, cons t String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, Excepti onState& exceptionState)
377 { 377 {
378 IDB_TRACE("IDBObjectStore::createIndex"); 378 IDB_TRACE("IDBObjectStore::createIndex");
379 if (!m_transaction->isVersionChange()) { 379 if (!m_transaction->isVersionChange()) {
380 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVers ionChangeTransactionErrorMessage); 380 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVers ionChangeTransactionErrorMessage);
381 return 0; 381 return nullptr;
382 } 382 }
383 if (isDeleted()) { 383 if (isDeleted()) {
384 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 384 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
385 return 0; 385 return nullptr;
386 } 386 }
387 if (m_transaction->isFinished()) { 387 if (m_transaction->isFinished()) {
388 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 388 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
389 return 0; 389 return nullptr;
390 } 390 }
391 if (!m_transaction->isActive()) { 391 if (!m_transaction->isActive()) {
392 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 392 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
393 return 0; 393 return nullptr;
394 } 394 }
395 if (!keyPath.isValid()) { 395 if (!keyPath.isValid()) {
396 exceptionState.throwDOMException(SyntaxError, "The keyPath argument cont ains an invalid key path."); 396 exceptionState.throwDOMException(SyntaxError, "The keyPath argument cont ains an invalid key path.");
397 return 0; 397 return nullptr;
398 } 398 }
399 if (name.isNull()) { 399 if (name.isNull()) {
400 exceptionState.throwTypeError("The name provided is null."); 400 exceptionState.throwTypeError("The name provided is null.");
401 return 0; 401 return nullptr;
402 } 402 }
403 if (containsIndex(name)) { 403 if (containsIndex(name)) {
404 exceptionState.throwDOMException(ConstraintError, "An index with the spe cified name already exists."); 404 exceptionState.throwDOMException(ConstraintError, "An index with the spe cified name already exists.");
405 return 0; 405 return nullptr;
406 } 406 }
407 407
408 if (keyPath.type() == IDBKeyPath::ArrayType && multiEntry) { 408 if (keyPath.type() == IDBKeyPath::ArrayType && multiEntry) {
409 exceptionState.throwDOMException(InvalidAccessError, "The keyPath argume nt was an array and the multiEntry option is true."); 409 exceptionState.throwDOMException(InvalidAccessError, "The keyPath argume nt was an array and the multiEntry option is true.");
410 return 0; 410 return nullptr;
411 } 411 }
412 412
413 int64_t indexId = m_metadata.maxIndexId + 1; 413 int64_t indexId = m_metadata.maxIndexId + 1;
414 backendDB()->createIndex(m_transaction->id(), id(), indexId, name, keyPath, unique, multiEntry); 414 backendDB()->createIndex(m_transaction->id(), id(), indexId, name, keyPath, unique, multiEntry);
415 415
416 ++m_metadata.maxIndexId; 416 ++m_metadata.maxIndexId;
417 417
418 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); 418 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry);
419 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get( )); 419 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get( ));
420 m_indexMap.set(name, index); 420 m_indexMap.set(name, index);
421 m_metadata.indexes.set(indexId, metadata); 421 m_metadata.indexes.set(indexId, metadata);
422 m_transaction->db()->indexCreated(id(), metadata); 422 m_transaction->db()->indexCreated(id(), metadata);
423 423
424 ASSERT(!exceptionState.hadException()); 424 ASSERT(!exceptionState.hadException());
425 if (exceptionState.hadException()) 425 if (exceptionState.hadException())
426 return 0; 426 return nullptr;
427 427
428 RefPtr<IDBRequest> indexRequest = openCursor(context, static_cast<IDBKeyRang e*>(0), blink::WebIDBCursor::Next, WebIDBDatabase::PreemptiveTask); 428 RefPtr<IDBRequest> indexRequest = openCursor(context, static_cast<IDBKeyRang e*>(0), blink::WebIDBCursor::Next, WebIDBDatabase::PreemptiveTask);
429 indexRequest->preventPropagation(); 429 indexRequest->preventPropagation();
430 430
431 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction. 431 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction.
432 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(transaction() ->db(), m_transaction->id(), id(), metadata); 432 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(transaction() ->db(), m_transaction->id(), id(), metadata);
433 indexRequest->setOnsuccess(indexPopulator); 433 indexRequest->setOnsuccess(indexPopulator);
434 434
435 return index.release(); 435 return index.release();
436 } 436 }
437 437
438 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& e xceptionState) 438 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& e xceptionState)
439 { 439 {
440 IDB_TRACE("IDBObjectStore::index"); 440 IDB_TRACE("IDBObjectStore::index");
441 if (isDeleted()) { 441 if (isDeleted()) {
442 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 442 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
443 return 0; 443 return nullptr;
444 } 444 }
445 if (m_transaction->isFinished()) { 445 if (m_transaction->isFinished()) {
446 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::transac tionFinishedErrorMessage); 446 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::transac tionFinishedErrorMessage);
447 return 0; 447 return nullptr;
448 } 448 }
449 449
450 IDBIndexMap::iterator it = m_indexMap.find(name); 450 IDBIndexMap::iterator it = m_indexMap.find(name);
451 if (it != m_indexMap.end()) 451 if (it != m_indexMap.end())
452 return it->value; 452 return it->value;
453 453
454 int64_t indexId = findIndexId(name); 454 int64_t indexId = findIndexId(name);
455 if (indexId == IDBIndexMetadata::InvalidId) { 455 if (indexId == IDBIndexMetadata::InvalidId) {
456 exceptionState.throwDOMException(NotFoundError, IDBDatabase::noSuchIndex ErrorMessage); 456 exceptionState.throwDOMException(NotFoundError, IDBDatabase::noSuchIndex ErrorMessage);
457 return 0; 457 return nullptr;
458 } 458 }
459 459
460 const IDBIndexMetadata* indexMetadata(0); 460 const IDBIndexMetadata* indexMetadata(0);
461 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) { 461 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) {
462 if (it->value.name == name) { 462 if (it->value.name == name) {
463 indexMetadata = &it->value; 463 indexMetadata = &it->value;
464 break; 464 break;
465 } 465 }
466 } 466 }
467 ASSERT(indexMetadata); 467 ASSERT(indexMetadata);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 it->value->markDeleted(); 506 it->value->markDeleted();
507 m_indexMap.remove(name); 507 m_indexMap.remove(name);
508 } 508 }
509 } 509 }
510 510
511 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ExecutionContext* context, con st ScriptValue& range, const String& directionString, ExceptionState& exceptionS tate) 511 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ExecutionContext* context, con st ScriptValue& range, const String& directionString, ExceptionState& exceptionS tate)
512 { 512 {
513 IDB_TRACE("IDBObjectStore::openCursor"); 513 IDB_TRACE("IDBObjectStore::openCursor");
514 if (isDeleted()) { 514 if (isDeleted()) {
515 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 515 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
516 return 0; 516 return nullptr;
517 } 517 }
518 if (m_transaction->isFinished()) { 518 if (m_transaction->isFinished()) {
519 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 519 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
520 return 0; 520 return nullptr;
521 } 521 }
522 if (!m_transaction->isActive()) { 522 if (!m_transaction->isActive()) {
523 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 523 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
524 return 0; 524 return nullptr;
525 } 525 }
526 526
527 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt ring, exceptionState); 527 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt ring, exceptionState);
528 if (exceptionState.hadException()) 528 if (exceptionState.hadException())
529 return 0; 529 return nullptr;
530 530
531 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState); 531 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState);
532 if (exceptionState.hadException()) 532 if (exceptionState.hadException())
533 return 0; 533 return nullptr;
534 534
535 return openCursor(context, keyRange, direction, WebIDBDatabase::NormalTask); 535 return openCursor(context, keyRange, direction, WebIDBDatabase::NormalTask);
536 } 536 }
537 537
538 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ExecutionContext* context, Pas sRefPtr<IDBKeyRange> range, WebIDBCursor::Direction direction, WebIDBDatabase::T askType taskType) 538 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ExecutionContext* context, Pas sRefPtr<IDBKeyRange> range, WebIDBCursor::Direction direction, WebIDBDatabase::T askType taskType)
539 { 539 {
540 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 540 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
541 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); 541 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction);
542 542
543 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, taskType, WebIDBCallbacksImpl::create(request).leak Ptr()); 543 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, taskType, WebIDBCallbacksImpl::create(request).leak Ptr());
544 return request.release(); 544 return request.release();
545 } 545 }
546 546
547 PassRefPtr<IDBRequest> IDBObjectStore::openKeyCursor(ExecutionContext* context, const ScriptValue& range, const String& directionString, ExceptionState& excepti onState) 547 PassRefPtr<IDBRequest> IDBObjectStore::openKeyCursor(ExecutionContext* context, const ScriptValue& range, const String& directionString, ExceptionState& excepti onState)
548 { 548 {
549 IDB_TRACE("IDBObjectStore::openKeyCursor"); 549 IDB_TRACE("IDBObjectStore::openKeyCursor");
550 if (isDeleted()) { 550 if (isDeleted()) {
551 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 551 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
552 return 0; 552 return nullptr;
553 } 553 }
554 if (m_transaction->isFinished()) { 554 if (m_transaction->isFinished()) {
555 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 555 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
556 return 0; 556 return nullptr;
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 nullptr;
561 } 561 }
562 562
563 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt ring, exceptionState); 563 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt ring, exceptionState);
564 if (exceptionState.hadException()) 564 if (exceptionState.hadException())
565 return 0; 565 return nullptr;
566 566
567 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState); 567 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState);
568 if (exceptionState.hadException()) 568 if (exceptionState.hadException())
569 return 0; 569 return nullptr;
570 570
571 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 571 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
572 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); 572 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction);
573 573
574 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, keyRange.release(), direction, true, WebIDBDatabase::NormalTask, WebIDBCallb acksImpl::create(request).leakPtr()); 574 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, keyRange.release(), direction, true, WebIDBDatabase::NormalTask, WebIDBCallb acksImpl::create(request).leakPtr());
575 return request.release(); 575 return request.release();
576 } 576 }
577 577
578 PassRefPtr<IDBRequest> IDBObjectStore::count(ExecutionContext* context, const Sc riptValue& range, ExceptionState& exceptionState) 578 PassRefPtr<IDBRequest> IDBObjectStore::count(ExecutionContext* context, const Sc riptValue& range, ExceptionState& exceptionState)
579 { 579 {
580 IDB_TRACE("IDBObjectStore::count"); 580 IDB_TRACE("IDBObjectStore::count");
581 if (isDeleted()) { 581 if (isDeleted()) {
582 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage); 582 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
583 return 0; 583 return nullptr;
584 } 584 }
585 if (m_transaction->isFinished()) { 585 if (m_transaction->isFinished()) {
586 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 586 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
587 return 0; 587 return nullptr;
588 } 588 }
589 if (!m_transaction->isActive()) { 589 if (!m_transaction->isActive()) {
590 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 590 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
591 return 0; 591 return nullptr;
592 } 592 }
593 593
594 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState); 594 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState);
595 if (exceptionState.hadException()) 595 if (exceptionState.hadException())
596 return 0; 596 return nullptr;
597 597
598 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 598 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
599 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, k eyRange.release(), WebIDBCallbacksImpl::create(request).leakPtr()); 599 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, k eyRange.release(), WebIDBCallbacksImpl::create(request).leakPtr());
600 return request.release(); 600 return request.release();
601 } 601 }
602 602
603 void IDBObjectStore::transactionFinished() 603 void IDBObjectStore::transactionFinished()
604 { 604 {
605 ASSERT(m_transaction->isFinished()); 605 ASSERT(m_transaction->isFinished());
606 606
(...skipping 11 matching lines...) Expand all
618 } 618 }
619 return IDBIndexMetadata::InvalidId; 619 return IDBIndexMetadata::InvalidId;
620 } 620 }
621 621
622 WebIDBDatabase* IDBObjectStore::backendDB() const 622 WebIDBDatabase* IDBObjectStore::backendDB() const
623 { 623 {
624 return m_transaction->backendDB(); 624 return m_transaction->backendDB();
625 } 625 }
626 626
627 } // namespace WebCore 627 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/indexeddb/IDBKeyRange.cpp ('k') | Source/modules/indexeddb/IDBOpenDBRequest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698