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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 using blink::WebIDBCursor; | 43 using blink::WebIDBCursor; |
| 44 using blink::WebIDBDatabase; | 44 using blink::WebIDBDatabase; |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 | 47 |
| 48 IDBIndex::IDBIndex(const IDBIndexMetadata& metadata, IDBObjectStore* objectStore , IDBTransaction* transaction) | 48 IDBIndex::IDBIndex(const IDBIndexMetadata& metadata, IDBObjectStore* objectStore , IDBTransaction* transaction) |
| 49 : m_metadata(metadata) | 49 : m_metadata(metadata) |
| 50 , m_objectStore(objectStore) | 50 , m_objectStore(objectStore) |
| 51 , m_transaction(transaction) | 51 , m_transaction(transaction) |
| 52 { | 52 { |
| 53 ASSERT(m_objectStore); | 53 DCHECK(m_objectStore); |
| 54 ASSERT(m_transaction); | 54 DCHECK(m_transaction); |
| 55 ASSERT(m_metadata.id != IDBIndexMetadata::InvalidId); | 55 DCHECK(id() != IDBIndexMetadata::InvalidId); |
|
cmumford
2016/09/19 23:26:48
DCHECK_NE
pwnall
2016/09/20 09:11:14
Done.
TBH, I was trying to be smart and thinking
| |
| 56 } | 56 } |
| 57 | 57 |
| 58 IDBIndex::~IDBIndex() | 58 IDBIndex::~IDBIndex() |
| 59 { | 59 { |
| 60 } | 60 } |
| 61 | 61 |
| 62 DEFINE_TRACE(IDBIndex) | 62 DEFINE_TRACE(IDBIndex) |
| 63 { | 63 { |
| 64 visitor->trace(m_objectStore); | 64 visitor->trace(m_objectStore); |
| 65 visitor->trace(m_transaction); | 65 visitor->trace(m_transaction); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void IDBIndex::setName(const String& name, ExceptionState& exceptionState) | 68 void IDBIndex::setName(const String& newName, ExceptionState& exceptionState) |
|
cmumford
2016/09/19 23:26:48
Nit: Several other Blink "setName" methods use "na
pwnall
2016/09/20 09:11:14
Done.
I was mostly trying to avoid if (this->name
| |
| 69 { | 69 { |
| 70 if (!RuntimeEnabledFeatures::indexedDBExperimentalEnabled()) | 70 if (!RuntimeEnabledFeatures::indexedDBExperimentalEnabled()) |
| 71 return; | 71 return; |
| 72 | 72 |
| 73 IDB_TRACE("IDBIndex::setName"); | 73 IDB_TRACE("IDBIndex::setName"); |
| 74 if (!m_transaction->isVersionChange()) { | 74 if (!m_transaction->isVersionChange()) { |
| 75 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVers ionChangeTransactionErrorMessage); | 75 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVers ionChangeTransactionErrorMessage); |
| 76 return; | 76 return; |
| 77 } | 77 } |
| 78 if (isDeleted()) { | 78 if (isDeleted()) { |
| 79 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage); | 79 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage); |
| 80 return; | 80 return; |
| 81 } | 81 } |
| 82 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 82 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 83 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); | 83 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); |
| 84 return; | 84 return; |
| 85 } | 85 } |
| 86 if (!m_transaction->isActive()) { | 86 if (!m_transaction->isActive()) { |
| 87 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); | 87 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); |
| 88 return; | 88 return; |
| 89 } | 89 } |
| 90 | 90 |
| 91 if (m_metadata.name == name) | 91 if (name() == newName) |
| 92 return; | 92 return; |
| 93 if (m_objectStore->containsIndex(name)) { | 93 if (m_objectStore->containsIndex(newName)) { |
| 94 exceptionState.throwDOMException(ConstraintError, IDBDatabase::indexName TakenErrorMessage); | 94 exceptionState.throwDOMException(ConstraintError, IDBDatabase::indexName TakenErrorMessage); |
| 95 return; | 95 return; |
| 96 } | 96 } |
| 97 if (!backendDB()) { | 97 if (!backendDB()) { |
| 98 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); | 98 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); |
| 99 return; | 99 return; |
| 100 } | 100 } |
| 101 | 101 |
| 102 backendDB()->renameIndex(m_transaction->id(), m_objectStore->id(), id(), nam e); | 102 backendDB()->renameIndex(m_transaction->id(), m_objectStore->id(), id(), new Name); |
| 103 m_metadata.name = name; | 103 m_metadata.name = newName; |
| 104 m_objectStore->indexRenamed(m_metadata.id, name); | 104 m_objectStore->indexRenamed(m_metadata.id, newName); |
| 105 m_transaction->db()->indexRenamed(m_objectStore->id(), id(), name); | 105 m_transaction->db()->indexRenamed(m_objectStore->id(), id(), newName); |
| 106 } | 106 } |
| 107 | 107 |
| 108 ScriptValue IDBIndex::keyPath(ScriptState* scriptState) const | 108 ScriptValue IDBIndex::keyPath(ScriptState* scriptState) const |
| 109 { | 109 { |
| 110 return ScriptValue::from(scriptState, m_metadata.keyPath); | 110 return ScriptValue::from(scriptState, metadata().keyPath); |
| 111 } | 111 } |
| 112 | 112 |
| 113 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, const ScriptValue& ra nge, const String& directionString, ExceptionState& exceptionState) | 113 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, const ScriptValue& ra nge, const String& directionString, ExceptionState& exceptionState) |
| 114 { | 114 { |
| 115 IDB_TRACE("IDBIndex::openCursor"); | 115 IDB_TRACE("IDBIndex::openCursor"); |
| 116 if (isDeleted()) { | 116 if (isDeleted()) { |
| 117 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage); | 117 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage); |
| 118 return nullptr; | 118 return nullptr; |
| 119 } | 119 } |
| 120 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 120 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 135 return nullptr; | 135 return nullptr; |
| 136 } | 136 } |
| 137 | 137 |
| 138 return openCursor(scriptState, keyRange, direction); | 138 return openCursor(scriptState, keyRange, direction); |
| 139 } | 139 } |
| 140 | 140 |
| 141 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, IDBKeyRange* keyRange , WebIDBCursorDirection direction) | 141 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, IDBKeyRange* keyRange , WebIDBCursorDirection direction) |
| 142 { | 142 { |
| 143 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); | 143 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); |
| 144 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 144 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); |
| 145 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata .id, keyRange, direction, false, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::crea te(request).release()); | 145 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), id(), keyR ange, direction, false, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::create(reques t).release()); |
| 146 return request; | 146 return request; |
| 147 } | 147 } |
| 148 | 148 |
| 149 IDBRequest* IDBIndex::count(ScriptState* scriptState, const ScriptValue& range, ExceptionState& exceptionState) | 149 IDBRequest* IDBIndex::count(ScriptState* scriptState, const ScriptValue& range, ExceptionState& exceptionState) |
| 150 { | 150 { |
| 151 IDB_TRACE("IDBIndex::count"); | 151 IDB_TRACE("IDBIndex::count"); |
| 152 if (isDeleted()) { | 152 if (isDeleted()) { |
| 153 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage); | 153 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage); |
| 154 return nullptr; | 154 return nullptr; |
| 155 } | 155 } |
| 156 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 156 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 157 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); | 157 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); |
| 158 return nullptr; | 158 return nullptr; |
| 159 } | 159 } |
| 160 if (!m_transaction->isActive()) { | 160 if (!m_transaction->isActive()) { |
| 161 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); | 161 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); |
| 162 return nullptr; | 162 return nullptr; |
| 163 } | 163 } |
| 164 | 164 |
| 165 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti onContext(), range, exceptionState); | 165 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti onContext(), range, exceptionState); |
| 166 if (exceptionState.hadException()) | 166 if (exceptionState.hadException()) |
| 167 return nullptr; | 167 return nullptr; |
| 168 | 168 |
| 169 if (!backendDB()) { | 169 if (!backendDB()) { |
| 170 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); | 170 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); |
| 171 return nullptr; | 171 return nullptr; |
| 172 } | 172 } |
| 173 | 173 |
| 174 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); | 174 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); |
| 175 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id, keyRange, WebIDBCallbacksImpl::create(request).release()); | 175 backendDB()->count(m_transaction->id(), m_objectStore->id(), id(), keyRange, WebIDBCallbacksImpl::create(request).release()); |
| 176 return request; | 176 return request; |
| 177 } | 177 } |
| 178 | 178 |
| 179 IDBRequest* IDBIndex::openKeyCursor(ScriptState* scriptState, const ScriptValue& range, const String& directionString, ExceptionState& exceptionState) | 179 IDBRequest* IDBIndex::openKeyCursor(ScriptState* scriptState, const ScriptValue& range, const String& directionString, ExceptionState& exceptionState) |
| 180 { | 180 { |
| 181 IDB_TRACE("IDBIndex::openKeyCursor"); | 181 IDB_TRACE("IDBIndex::openKeyCursor"); |
| 182 if (isDeleted()) { | 182 if (isDeleted()) { |
| 183 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage); | 183 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage); |
| 184 return nullptr; | 184 return nullptr; |
| 185 } | 185 } |
| 186 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 186 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 187 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); | 187 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); |
| 188 return nullptr; | 188 return nullptr; |
| 189 } | 189 } |
| 190 if (!m_transaction->isActive()) { | 190 if (!m_transaction->isActive()) { |
| 191 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); | 191 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); |
| 192 return nullptr; | 192 return nullptr; |
| 193 } | 193 } |
| 194 WebIDBCursorDirection direction = IDBCursor::stringToDirection(directionStri ng); | 194 WebIDBCursorDirection direction = IDBCursor::stringToDirection(directionStri ng); |
| 195 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti onContext(), range, exceptionState); | 195 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti onContext(), range, exceptionState); |
| 196 if (exceptionState.hadException()) | 196 if (exceptionState.hadException()) |
| 197 return nullptr; | 197 return nullptr; |
| 198 if (!backendDB()) { | 198 if (!backendDB()) { |
| 199 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); | 199 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); |
| 200 return nullptr; | 200 return nullptr; |
| 201 } | 201 } |
| 202 | 202 |
| 203 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); | 203 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); |
| 204 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); | 204 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); |
| 205 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata .id, keyRange, direction, true, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::creat e(request).release()); | 205 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), id(), keyR ange, direction, true, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::create(request ).release()); |
| 206 return request; | 206 return request; |
| 207 } | 207 } |
| 208 | 208 |
| 209 IDBRequest* IDBIndex::get(ScriptState* scriptState, const ScriptValue& key, Exce ptionState& exceptionState) | 209 IDBRequest* IDBIndex::get(ScriptState* scriptState, const ScriptValue& key, Exce ptionState& exceptionState) |
| 210 { | 210 { |
| 211 IDB_TRACE("IDBIndex::get"); | 211 IDB_TRACE("IDBIndex::get"); |
| 212 return getInternal(scriptState, key, exceptionState, false); | 212 return getInternal(scriptState, key, exceptionState, false); |
| 213 } | 213 } |
| 214 | 214 |
| 215 IDBRequest* IDBIndex::getAll(ScriptState* scriptState, const ScriptValue& range, ExceptionState& exceptionState) | 215 IDBRequest* IDBIndex::getAll(ScriptState* scriptState, const ScriptValue& range, ExceptionState& exceptionState) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 if (!keyRange) { | 261 if (!keyRange) { |
| 262 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage); | 262 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage); |
| 263 return nullptr; | 263 return nullptr; |
| 264 } | 264 } |
| 265 if (!backendDB()) { | 265 if (!backendDB()) { |
| 266 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); | 266 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); |
| 267 return nullptr; | 267 return nullptr; |
| 268 } | 268 } |
| 269 | 269 |
| 270 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); | 270 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); |
| 271 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke yRange, keyOnly, WebIDBCallbacksImpl::create(request).release()); | 271 backendDB()->get(m_transaction->id(), m_objectStore->id(), id(), keyRange, k eyOnly, WebIDBCallbacksImpl::create(request).release()); |
| 272 return request; | 272 return request; |
| 273 } | 273 } |
| 274 | 274 |
| 275 IDBRequest* IDBIndex::getAllInternal(ScriptState* scriptState, const ScriptValue & range, unsigned long maxCount, ExceptionState& exceptionState, bool keyOnly) | 275 IDBRequest* IDBIndex::getAllInternal(ScriptState* scriptState, const ScriptValue & range, unsigned long maxCount, ExceptionState& exceptionState, bool keyOnly) |
| 276 { | 276 { |
| 277 if (!maxCount) | 277 if (!maxCount) |
| 278 maxCount = std::numeric_limits<uint32_t>::max(); | 278 maxCount = std::numeric_limits<uint32_t>::max(); |
| 279 | 279 |
| 280 if (isDeleted()) { | 280 if (isDeleted()) { |
| 281 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage); | 281 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 292 | 292 |
| 293 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti onContext(), range, exceptionState); | 293 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti onContext(), range, exceptionState); |
| 294 if (exceptionState.hadException()) | 294 if (exceptionState.hadException()) |
| 295 return nullptr; | 295 return nullptr; |
| 296 if (!backendDB()) { | 296 if (!backendDB()) { |
| 297 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); | 297 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); |
| 298 return nullptr; | 298 return nullptr; |
| 299 } | 299 } |
| 300 | 300 |
| 301 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); | 301 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); |
| 302 backendDB()->getAll(m_transaction->id(), m_objectStore->id(), m_metadata.id, keyRange, maxCount, keyOnly, WebIDBCallbacksImpl::create(request).release()); | 302 backendDB()->getAll(m_transaction->id(), m_objectStore->id(), id(), keyRange , maxCount, keyOnly, WebIDBCallbacksImpl::create(request).release()); |
| 303 return request; | 303 return request; |
| 304 } | 304 } |
| 305 | 305 |
| 306 WebIDBDatabase* IDBIndex::backendDB() const | 306 WebIDBDatabase* IDBIndex::backendDB() const |
| 307 { | 307 { |
| 308 return m_transaction->backendDB(); | 308 return m_transaction->backendDB(); |
| 309 } | 309 } |
| 310 | 310 |
| 311 bool IDBIndex::isDeleted() const | 311 bool IDBIndex::isDeleted() const |
| 312 { | 312 { |
| 313 return m_deleted || m_objectStore->isDeleted(); | 313 return m_deleted || m_objectStore->isDeleted(); |
| 314 } | 314 } |
| 315 | 315 |
| 316 } // namespace blink | 316 } // namespace blink |
| OLD | NEW |