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

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBDatabase.cpp

Issue 2276593002: Support renaming of IndexedDB indexes and object stores. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests for create rename in the same aborted transaction. Created 4 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
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "public/platform/modules/indexeddb/WebIDBTypes.h" 45 #include "public/platform/modules/indexeddb/WebIDBTypes.h"
46 #include "wtf/Atomics.h" 46 #include "wtf/Atomics.h"
47 #include <limits> 47 #include <limits>
48 #include <memory> 48 #include <memory>
49 49
50 using blink::WebIDBDatabase; 50 using blink::WebIDBDatabase;
51 51
52 namespace blink { 52 namespace blink {
53 53
54 const char IDBDatabase::indexDeletedErrorMessage[] = "The index or its object st ore has been deleted."; 54 const char IDBDatabase::indexDeletedErrorMessage[] = "The index or its object st ore has been deleted.";
55 const char IDBDatabase::indexNameTakenErrorMessage[] = "An index with the specif ied name already exists.";
55 const char IDBDatabase::isKeyCursorErrorMessage[] = "The cursor is a key cursor. "; 56 const char IDBDatabase::isKeyCursorErrorMessage[] = "The cursor is a key cursor. ";
56 const char IDBDatabase::noKeyOrKeyRangeErrorMessage[] = "No key or key range spe cified."; 57 const char IDBDatabase::noKeyOrKeyRangeErrorMessage[] = "No key or key range spe cified.";
57 const char IDBDatabase::noSuchIndexErrorMessage[] = "The specified index was not found."; 58 const char IDBDatabase::noSuchIndexErrorMessage[] = "The specified index was not found.";
58 const char IDBDatabase::noSuchObjectStoreErrorMessage[] = "The specified object store was not found."; 59 const char IDBDatabase::noSuchObjectStoreErrorMessage[] = "The specified object store was not found.";
59 const char IDBDatabase::noValueErrorMessage[] = "The cursor is being iterated or has iterated past its end."; 60 const char IDBDatabase::noValueErrorMessage[] = "The cursor is being iterated or has iterated past its end.";
60 const char IDBDatabase::notValidKeyErrorMessage[] = "The parameter is not a vali d key."; 61 const char IDBDatabase::notValidKeyErrorMessage[] = "The parameter is not a vali d key.";
61 const char IDBDatabase::notVersionChangeTransactionErrorMessage[] = "The databas e is not running a version change transaction."; 62 const char IDBDatabase::notVersionChangeTransactionErrorMessage[] = "The databas e is not running a version change transaction.";
62 const char IDBDatabase::objectStoreDeletedErrorMessage[] = "The object store has been deleted."; 63 const char IDBDatabase::objectStoreDeletedErrorMessage[] = "The object store has been deleted.";
64 const char IDBDatabase::objectStoreNameTakenErrorMessage[] = "An object store wi th the specified name already exists.";
63 const char IDBDatabase::requestNotFinishedErrorMessage[] = "The request has not finished."; 65 const char IDBDatabase::requestNotFinishedErrorMessage[] = "The request has not finished.";
64 const char IDBDatabase::sourceDeletedErrorMessage[] = "The cursor's source or ef fective object store has been deleted."; 66 const char IDBDatabase::sourceDeletedErrorMessage[] = "The cursor's source or ef fective object store has been deleted.";
65 const char IDBDatabase::transactionInactiveErrorMessage[] = "The transaction is not active."; 67 const char IDBDatabase::transactionInactiveErrorMessage[] = "The transaction is not active.";
66 const char IDBDatabase::transactionFinishedErrorMessage[] = "The transaction has finished."; 68 const char IDBDatabase::transactionFinishedErrorMessage[] = "The transaction has finished.";
67 const char IDBDatabase::transactionReadOnlyErrorMessage[] = "The transaction is read-only."; 69 const char IDBDatabase::transactionReadOnlyErrorMessage[] = "The transaction is read-only.";
68 const char IDBDatabase::databaseClosedErrorMessage[] = "The database connection is closed."; 70 const char IDBDatabase::databaseClosedErrorMessage[] = "The database connection is closed.";
69 71
70 IDBDatabase* IDBDatabase::create(ExecutionContext* context, std::unique_ptr<WebI DBDatabase> database, IDBDatabaseCallbacks* callbacks) 72 IDBDatabase* IDBDatabase::create(ExecutionContext* context, std::unique_ptr<WebI DBDatabase> database, IDBDatabaseCallbacks* callbacks)
71 { 73 {
72 IDBDatabase* idbDatabase = new IDBDatabase(context, std::move(database), cal lbacks); 74 IDBDatabase* idbDatabase = new IDBDatabase(context, std::move(database), cal lbacks);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 it->value.indexes.set(metadata.id, metadata); 116 it->value.indexes.set(metadata.id, metadata);
115 } 117 }
116 118
117 void IDBDatabase::indexDeleted(int64_t objectStoreId, int64_t indexId) 119 void IDBDatabase::indexDeleted(int64_t objectStoreId, int64_t indexId)
118 { 120 {
119 IDBDatabaseMetadata::ObjectStoreMap::iterator it = m_metadata.objectStores.f ind(objectStoreId); 121 IDBDatabaseMetadata::ObjectStoreMap::iterator it = m_metadata.objectStores.f ind(objectStoreId);
120 ASSERT_WITH_SECURITY_IMPLICATION(it != m_metadata.objectStores.end()); 122 ASSERT_WITH_SECURITY_IMPLICATION(it != m_metadata.objectStores.end());
121 it->value.indexes.remove(indexId); 123 it->value.indexes.remove(indexId);
122 } 124 }
123 125
126 void IDBDatabase::indexRenamed(int64_t objectStoreId, int64_t indexId, const Str ing& newName)
127 {
128 IDBDatabaseMetadata::ObjectStoreMap::iterator storeIterator = m_metadata.obj ectStores.find(objectStoreId);
129 SECURITY_DCHECK(storeIterator != m_metadata.objectStores.end());
130
131 IDBObjectStoreMetadata& storeMetadata = storeIterator->value;
132 IDBObjectStoreMetadata::IndexMap::iterator indexIterator = storeMetadata.ind exes.find(indexId);
133 DCHECK(indexIterator != storeMetadata.indexes.end());
134 indexIterator->value.name = newName;
135 }
136
124 void IDBDatabase::transactionCreated(IDBTransaction* transaction) 137 void IDBDatabase::transactionCreated(IDBTransaction* transaction)
125 { 138 {
126 ASSERT(transaction); 139 ASSERT(transaction);
127 ASSERT(!m_transactions.contains(transaction->id())); 140 ASSERT(!m_transactions.contains(transaction->id()));
128 m_transactions.add(transaction->id(), transaction); 141 m_transactions.add(transaction->id(), transaction);
129 142
130 if (transaction->isVersionChange()) { 143 if (transaction->isVersionChange()) {
131 ASSERT(!m_versionChangeTransaction); 144 ASSERT(!m_versionChangeTransaction);
132 m_versionChangeTransaction = transaction; 145 m_versionChangeTransaction = transaction;
133 } 146 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 207 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
195 return nullptr; 208 return nullptr;
196 } 209 }
197 210
198 if (!keyPath.isNull() && !keyPath.isValid()) { 211 if (!keyPath.isNull() && !keyPath.isValid()) {
199 exceptionState.throwDOMException(SyntaxError, "The keyPath option is not a valid key path."); 212 exceptionState.throwDOMException(SyntaxError, "The keyPath option is not a valid key path.");
200 return nullptr; 213 return nullptr;
201 } 214 }
202 215
203 if (containsObjectStore(name)) { 216 if (containsObjectStore(name)) {
204 exceptionState.throwDOMException(ConstraintError, "An object store with the specified name already exists."); 217 exceptionState.throwDOMException(ConstraintError, IDBDatabase::objectSto reNameTakenErrorMessage);
205 return nullptr; 218 return nullptr;
206 } 219 }
207 220
208 if (autoIncrement && ((keyPath.getType() == IDBKeyPath::StringType && keyPat h.string().isEmpty()) || keyPath.getType() == IDBKeyPath::ArrayType)) { 221 if (autoIncrement && ((keyPath.getType() == IDBKeyPath::StringType && keyPat h.string().isEmpty()) || keyPath.getType() == IDBKeyPath::ArrayType)) {
209 exceptionState.throwDOMException(InvalidAccessError, "The autoIncrement option was set but the keyPath option was empty or an array."); 222 exceptionState.throwDOMException(InvalidAccessError, "The autoIncrement option was set but the keyPath option was empty or an array.");
210 return nullptr; 223 return nullptr;
211 } 224 }
212 225
213 if (!m_backend) { 226 if (!m_backend) {
214 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); 227 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 { 428 {
416 for (const auto& it : m_metadata.objectStores) { 429 for (const auto& it : m_metadata.objectStores) {
417 if (it.value.name == name) { 430 if (it.value.name == name) {
418 ASSERT(it.key != IDBObjectStoreMetadata::InvalidId); 431 ASSERT(it.key != IDBObjectStoreMetadata::InvalidId);
419 return it.key; 432 return it.key;
420 } 433 }
421 } 434 }
422 return IDBObjectStoreMetadata::InvalidId; 435 return IDBObjectStoreMetadata::InvalidId;
423 } 436 }
424 437
438 void IDBDatabase::objectStoreRenamed(int64_t storeId, const String& newName)
439 {
440 DCHECK(m_metadata.objectStores.contains(storeId));
441 IDBDatabaseMetadata::ObjectStoreMap::iterator it = m_metadata.objectStores.f ind(storeId);
442 it->value.name = newName;
443 }
444
425 bool IDBDatabase::hasPendingActivity() const 445 bool IDBDatabase::hasPendingActivity() const
426 { 446 {
427 // The script wrapper must not be collected before the object is closed or 447 // The script wrapper must not be collected before the object is closed or
428 // we can't fire a "versionchange" event to let script manually close the co nnection. 448 // we can't fire a "versionchange" event to let script manually close the co nnection.
429 return !m_closePending && hasEventListeners() && !m_contextStopped; 449 return !m_closePending && hasEventListeners() && !m_contextStopped;
430 } 450 }
431 451
432 void IDBDatabase::stop() 452 void IDBDatabase::stop()
433 { 453 {
434 m_contextStopped = true; 454 m_contextStopped = true;
(...skipping 17 matching lines...) Expand all
452 return ActiveDOMObject::getExecutionContext(); 472 return ActiveDOMObject::getExecutionContext();
453 } 473 }
454 474
455 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method) 475 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method)
456 { 476 {
457 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, apiCallsHistogram, new EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls", IDBMethodsMax)); 477 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, apiCallsHistogram, new EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls", IDBMethodsMax));
458 apiCallsHistogram.count(method); 478 apiCallsHistogram.count(method);
459 } 479 }
460 480
461 } // namespace blink 481 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698