Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 30 matching lines...) Expand all Loading... | |
| 41 #include "modules/indexeddb/IDBKeyPath.h" | 41 #include "modules/indexeddb/IDBKeyPath.h" |
| 42 #include "modules/indexeddb/IDBObjectStore.h" | 42 #include "modules/indexeddb/IDBObjectStore.h" |
| 43 #include "modules/indexeddb/IDBTracing.h" | 43 #include "modules/indexeddb/IDBTracing.h" |
| 44 #include "modules/indexeddb/IDBTransaction.h" | 44 #include "modules/indexeddb/IDBTransaction.h" |
| 45 #include "modules/indexeddb/IDBVersionChangeEvent.h" | 45 #include "modules/indexeddb/IDBVersionChangeEvent.h" |
| 46 #include <limits> | 46 #include <limits> |
| 47 #include "wtf/Atomics.h" | 47 #include "wtf/Atomics.h" |
| 48 | 48 |
| 49 namespace WebCore { | 49 namespace WebCore { |
| 50 | 50 |
| 51 const char IDBDatabase::notFoundErrorMessage[] = "An operation failed because th e requested database object could not be found."; | 51 const char IDBDatabase::indexDeletedErrorMessage[] = "The index or its object st ore has been deleted."; |
| 52 const char IDBDatabase::isKeyCursorErrorMessage[] = "The cursor is a key cursor. "; | |
| 53 const char IDBDatabase::noKeyOrKeyRangeErrorMessage[] = "No key or key range spe cified."; | |
| 54 const char IDBDatabase::noSuchIndexErrorMessage[] = "The specified index was not be found."; | |
| 55 const char IDBDatabase::noSuchObjectStoreErrorMessage[] = "The specified object store was not found."; | |
| 56 const char IDBDatabase::notGotValueErrorMessage[] = "The cursor is being iterate d or has iterated past its end."; | |
| 57 const char IDBDatabase::notValidKeyErrorMessage[] = "The parameter is not a vali d key."; | |
| 58 const char IDBDatabase::notVersionChangeTransactionErrorMessage[] = "The databas e is not running a version change transaction."; | |
| 59 const char IDBDatabase::objectStoreDeletedErrorMessage[] = "The object store has been deleted."; | |
| 60 const char IDBDatabase::requestNotFinishedErrorMessage[] = "The request has not finished."; | |
| 61 const char IDBDatabase::sourceDeletedErrorMessage[] = "The cursor's source or ef fective object store has been deleted."; | |
| 62 const char IDBDatabase::transactionFinishedErrorMessage[] = "The transaction has finished."; | |
| 52 | 63 |
| 53 PassRefPtr<IDBDatabase> IDBDatabase::create(ScriptExecutionContext* context, Pas sRefPtr<IDBDatabaseBackendInterface> database, PassRefPtr<IDBDatabaseCallbacks> callbacks) | 64 PassRefPtr<IDBDatabase> IDBDatabase::create(ScriptExecutionContext* context, Pas sRefPtr<IDBDatabaseBackendInterface> database, PassRefPtr<IDBDatabaseCallbacks> callbacks) |
| 54 { | 65 { |
| 55 RefPtr<IDBDatabase> idbDatabase(adoptRef(new IDBDatabase(context, database, callbacks))); | 66 RefPtr<IDBDatabase> idbDatabase(adoptRef(new IDBDatabase(context, database, callbacks))); |
| 56 idbDatabase->suspendIfNeeded(); | 67 idbDatabase->suspendIfNeeded(); |
| 57 return idbDatabase.release(); | 68 return idbDatabase.release(); |
| 58 } | 69 } |
| 59 | 70 |
| 60 IDBDatabase::IDBDatabase(ScriptExecutionContext* context, PassRefPtr<IDBDatabase BackendInterface> backend, PassRefPtr<IDBDatabaseCallbacks> callbacks) | 71 IDBDatabase::IDBDatabase(ScriptExecutionContext* context, PassRefPtr<IDBDatabase BackendInterface> backend, PassRefPtr<IDBDatabaseCallbacks> callbacks) |
| 61 : ActiveDOMObject(context) | 72 : ActiveDOMObject(context) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 } | 180 } |
| 170 | 181 |
| 171 return createObjectStore(name, keyPath, autoIncrement, es); | 182 return createObjectStore(name, keyPath, autoIncrement, es); |
| 172 } | 183 } |
| 173 | 184 |
| 174 PassRefPtr<IDBObjectStore> IDBDatabase::createObjectStore(const String& name, co nst IDBKeyPath& keyPath, bool autoIncrement, ExceptionState& es) | 185 PassRefPtr<IDBObjectStore> IDBDatabase::createObjectStore(const String& name, co nst IDBKeyPath& keyPath, bool autoIncrement, ExceptionState& es) |
| 175 { | 186 { |
| 176 IDB_TRACE("IDBDatabase::createObjectStore"); | 187 IDB_TRACE("IDBDatabase::createObjectStore"); |
| 177 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls", IDBCreateObjectStoreCall, IDBMethodsMax); | 188 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls", IDBCreateObjectStoreCall, IDBMethodsMax); |
| 178 if (!m_versionChangeTransaction) { | 189 if (!m_versionChangeTransaction) { |
| 179 es.throwDOMException(InvalidStateError); | 190 es.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTra nsactionErrorMessage); |
| 191 return 0; | |
| 192 } | |
| 193 if (m_versionChangeTransaction->isFinished()) { | |
| 194 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); | |
| 180 return 0; | 195 return 0; |
| 181 } | 196 } |
| 182 if (!m_versionChangeTransaction->isActive()) { | 197 if (!m_versionChangeTransaction->isActive()) { |
| 183 es.throwDOMException(TransactionInactiveError); | 198 es.throwDOMException(TransactionInactiveError); |
| 184 return 0; | 199 return 0; |
| 185 } | 200 } |
| 186 | 201 |
| 187 if (containsObjectStore(name)) { | 202 if (containsObjectStore(name)) { |
| 188 es.throwDOMException(ConstraintError); | 203 es.throwDOMException(ConstraintError, "An object store with the specifie d name already exists."); |
| 189 return 0; | 204 return 0; |
| 190 } | 205 } |
| 191 | 206 |
| 192 if (!keyPath.isNull() && !keyPath.isValid()) { | 207 if (!keyPath.isNull() && !keyPath.isValid()) { |
| 193 es.throwDOMException(SyntaxError); | 208 es.throwDOMException(SyntaxError, "The keyPath option is not a valid key path."); |
|
dgrogan
2013/07/12 17:58:17
What do you think of splitting this up and includi
arv (Not doing code reviews)
2013/07/12 18:07:29
One step at a time. You can use String.format or w
jsbell
2013/07/12 18:22:19
Yeah, we could go further and include the details
| |
| 194 return 0; | 209 return 0; |
| 195 } | 210 } |
| 196 | 211 |
| 197 if (autoIncrement && ((keyPath.type() == IDBKeyPath::StringType && keyPath.s tring().isEmpty()) || keyPath.type() == IDBKeyPath::ArrayType)) { | 212 if (autoIncrement && ((keyPath.type() == IDBKeyPath::StringType && keyPath.s tring().isEmpty()) || keyPath.type() == IDBKeyPath::ArrayType)) { |
| 198 es.throwDOMException(InvalidAccessError); | 213 es.throwDOMException(InvalidAccessError, "The autoIncrement option was s et but the keyPath option was not a non-empty string."); |
| 199 return 0; | 214 return 0; |
| 200 } | 215 } |
| 201 | 216 |
| 202 int64_t objectStoreId = m_metadata.maxObjectStoreId + 1; | 217 int64_t objectStoreId = m_metadata.maxObjectStoreId + 1; |
| 203 m_backend->createObjectStore(m_versionChangeTransaction->id(), objectStoreId , name, keyPath, autoIncrement); | 218 m_backend->createObjectStore(m_versionChangeTransaction->id(), objectStoreId , name, keyPath, autoIncrement); |
| 204 | 219 |
| 205 IDBObjectStoreMetadata metadata(name, objectStoreId, keyPath, autoIncrement, IDBDatabaseBackendInterface::MinimumIndexId); | 220 IDBObjectStoreMetadata metadata(name, objectStoreId, keyPath, autoIncrement, IDBDatabaseBackendInterface::MinimumIndexId); |
| 206 RefPtr<IDBObjectStore> objectStore = IDBObjectStore::create(metadata, m_vers ionChangeTransaction.get()); | 221 RefPtr<IDBObjectStore> objectStore = IDBObjectStore::create(metadata, m_vers ionChangeTransaction.get()); |
| 207 m_metadata.objectStores.set(metadata.id, metadata); | 222 m_metadata.objectStores.set(metadata.id, metadata); |
| 208 ++m_metadata.maxObjectStoreId; | 223 ++m_metadata.maxObjectStoreId; |
| 209 | 224 |
| 210 m_versionChangeTransaction->objectStoreCreated(name, objectStore); | 225 m_versionChangeTransaction->objectStoreCreated(name, objectStore); |
| 211 return objectStore.release(); | 226 return objectStore.release(); |
| 212 } | 227 } |
| 213 | 228 |
| 214 void IDBDatabase::deleteObjectStore(const String& name, ExceptionState& es) | 229 void IDBDatabase::deleteObjectStore(const String& name, ExceptionState& es) |
| 215 { | 230 { |
| 216 IDB_TRACE("IDBDatabase::deleteObjectStore"); | 231 IDB_TRACE("IDBDatabase::deleteObjectStore"); |
| 217 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls", IDBDeleteObjectStoreCall, IDBMethodsMax); | 232 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls", IDBDeleteObjectStoreCall, IDBMethodsMax); |
| 218 if (!m_versionChangeTransaction) { | 233 if (!m_versionChangeTransaction) { |
| 219 es.throwDOMException(InvalidStateError); | 234 es.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTra nsactionErrorMessage); |
| 235 return; | |
| 236 } | |
| 237 if (m_versionChangeTransaction->isFinished()) { | |
| 238 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); | |
| 220 return; | 239 return; |
| 221 } | 240 } |
| 222 if (!m_versionChangeTransaction->isActive()) { | 241 if (!m_versionChangeTransaction->isActive()) { |
| 223 es.throwDOMException(TransactionInactiveError); | 242 es.throwDOMException(TransactionInactiveError); |
|
dgrogan
2013/07/12 17:58:17
Was this skipped intentionally?
jsbell
2013/07/12 18:22:19
I was thinking the generic message was adequate, b
| |
| 224 return; | 243 return; |
| 225 } | 244 } |
| 226 | 245 |
| 227 int64_t objectStoreId = findObjectStoreId(name); | 246 int64_t objectStoreId = findObjectStoreId(name); |
| 228 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { | 247 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { |
| 229 es.throwDOMException(NotFoundError, IDBDatabase::notFoundErrorMessage); | 248 es.throwDOMException(NotFoundError, "The specified object store was not found."); |
| 230 return; | 249 return; |
| 231 } | 250 } |
| 232 | 251 |
| 233 m_backend->deleteObjectStore(m_versionChangeTransaction->id(), objectStoreId ); | 252 m_backend->deleteObjectStore(m_versionChangeTransaction->id(), objectStoreId ); |
| 234 m_versionChangeTransaction->objectStoreDeleted(name); | 253 m_versionChangeTransaction->objectStoreDeleted(name); |
| 235 m_metadata.objectStores.remove(objectStoreId); | 254 m_metadata.objectStores.remove(objectStoreId); |
| 236 } | 255 } |
| 237 | 256 |
| 238 PassRefPtr<IDBTransaction> IDBDatabase::transaction(ScriptExecutionContext* cont ext, const Vector<String>& scope, const String& modeString, ExceptionState& es) | 257 PassRefPtr<IDBTransaction> IDBDatabase::transaction(ScriptExecutionContext* cont ext, const Vector<String>& scope, const String& modeString, ExceptionState& es) |
| 239 { | 258 { |
| 240 IDB_TRACE("IDBDatabase::transaction"); | 259 IDB_TRACE("IDBDatabase::transaction"); |
| 241 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls", IDBTransactionCall, IDBMethodsMax); | 260 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls", IDBTransactionCall, IDBMethodsMax); |
| 242 if (!scope.size()) { | 261 if (!scope.size()) { |
| 243 es.throwDOMException(InvalidAccessError); | 262 es.throwDOMException(InvalidAccessError, "The storeNames parameter was e mpty."); |
| 244 return 0; | 263 return 0; |
| 245 } | 264 } |
| 246 | 265 |
| 247 IndexedDB::TransactionMode mode = IDBTransaction::stringToMode(modeString, e s); | 266 IndexedDB::TransactionMode mode = IDBTransaction::stringToMode(modeString, e s); |
| 248 if (es.hadException()) | 267 if (es.hadException()) |
| 249 return 0; | 268 return 0; |
| 250 | 269 |
| 251 if (m_versionChangeTransaction || m_closePending) { | 270 if (m_versionChangeTransaction) { |
| 252 es.throwDOMException(InvalidStateError); | 271 es.throwDOMException(InvalidStateError, "A version change transaction is running."); |
| 253 return 0; | 272 return 0; |
| 254 } | 273 } |
| 255 | 274 |
| 275 if (m_closePending) { | |
| 276 es.throwDOMException(InvalidStateError, "The database connection is clos ing."); | |
| 277 return 0; | |
| 278 } | |
| 279 | |
| 256 Vector<int64_t> objectStoreIds; | 280 Vector<int64_t> objectStoreIds; |
| 257 for (size_t i = 0; i < scope.size(); ++i) { | 281 for (size_t i = 0; i < scope.size(); ++i) { |
| 258 int64_t objectStoreId = findObjectStoreId(scope[i]); | 282 int64_t objectStoreId = findObjectStoreId(scope[i]); |
| 259 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { | 283 if (objectStoreId == IDBObjectStoreMetadata::InvalidId) { |
| 260 es.throwDOMException(NotFoundError, IDBDatabase::notFoundErrorMessag e); | 284 es.throwDOMException(NotFoundError, "One of the specified object sto res was not found."); |
| 261 return 0; | 285 return 0; |
| 262 } | 286 } |
| 263 objectStoreIds.append(objectStoreId); | 287 objectStoreIds.append(objectStoreId); |
| 264 } | 288 } |
| 265 | 289 |
| 266 int64_t transactionId = nextTransactionId(); | 290 int64_t transactionId = nextTransactionId(); |
| 267 m_backend->createTransaction(transactionId, m_databaseCallbacks, objectStore Ids, mode); | 291 m_backend->createTransaction(transactionId, m_databaseCallbacks, objectStore Ids, mode); |
| 268 | 292 |
| 269 RefPtr<IDBTransaction> transaction = IDBTransaction::create(context, transac tionId, scope, mode, this); | 293 RefPtr<IDBTransaction> transaction = IDBTransaction::create(context, transac tionId, scope, mode, this); |
| 270 return transaction.release(); | 294 return transaction.release(); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 { | 416 { |
| 393 return &m_eventTargetData; | 417 return &m_eventTargetData; |
| 394 } | 418 } |
| 395 | 419 |
| 396 EventTargetData* IDBDatabase::ensureEventTargetData() | 420 EventTargetData* IDBDatabase::ensureEventTargetData() |
| 397 { | 421 { |
| 398 return &m_eventTargetData; | 422 return &m_eventTargetData; |
| 399 } | 423 } |
| 400 | 424 |
| 401 } // namespace WebCore | 425 } // namespace WebCore |
| OLD | NEW |