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

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

Issue 128683004: Refactor IDBIndex::get/getKey (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 11 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/IDBIndex.h ('k') | no next file » | 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 148
149 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 149 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
150 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); 150 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction);
151 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata .id, keyRange.release(), direction, true, WebIDBDatabase::NormalTask, WebIDBCall backsImpl::create(request).leakPtr()); 151 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata .id, keyRange.release(), direction, true, WebIDBDatabase::NormalTask, WebIDBCall backsImpl::create(request).leakPtr());
152 return request; 152 return request;
153 } 153 }
154 154
155 PassRefPtr<IDBRequest> IDBIndex::get(ExecutionContext* context, const ScriptValu e& key, ExceptionState& exceptionState) 155 PassRefPtr<IDBRequest> IDBIndex::get(ExecutionContext* context, const ScriptValu e& key, ExceptionState& exceptionState)
156 { 156 {
157 IDB_TRACE("IDBIndex::get"); 157 IDB_TRACE("IDBIndex::get");
158 if (isDeleted()) { 158 return getInternal(context, key, exceptionState, false);
159 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage);
160 return 0;
161 }
162 if (m_transaction->isFinished()) {
163 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
164 return 0;
165 }
166 if (!m_transaction->isActive()) {
167 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
168 return 0;
169 }
170
171 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex ceptionState);
172 if (exceptionState.hadException())
173 return 0;
174 if (!keyRange) {
175 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage);
176 return 0;
177 }
178
179 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
180 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke yRange.release(), false, WebIDBCallbacksImpl::create(request).leakPtr());
181 return request;
182 } 159 }
183 160
184 PassRefPtr<IDBRequest> IDBIndex::getKey(ExecutionContext* context, const ScriptV alue& key, ExceptionState& exceptionState) 161 PassRefPtr<IDBRequest> IDBIndex::getKey(ExecutionContext* context, const ScriptV alue& key, ExceptionState& exceptionState)
185 { 162 {
186 IDB_TRACE("IDBIndex::getKey"); 163 IDB_TRACE("IDBIndex::getKey");
164 return getInternal(context, key, exceptionState, true);
165 }
166
167 PassRefPtr<IDBRequest> IDBIndex::getInternal(ExecutionContext* context, const Sc riptValue& key, ExceptionState& exceptionState, bool keyOnly)
168 {
187 if (isDeleted()) { 169 if (isDeleted()) {
188 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage); 170 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage);
189 return 0; 171 return 0;
190 } 172 }
191 if (m_transaction->isFinished()) { 173 if (m_transaction->isFinished()) {
192 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 174 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
193 return 0; 175 return 0;
194 } 176 }
195 if (!m_transaction->isActive()) { 177 if (!m_transaction->isActive()) {
196 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 178 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
197 return 0; 179 return 0;
198 } 180 }
199 181
200 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex ceptionState); 182 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex ceptionState);
201 if (exceptionState.hadException()) 183 if (exceptionState.hadException())
202 return 0; 184 return 0;
203 if (!keyRange) { 185 if (!keyRange) {
204 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage); 186 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage);
205 return 0; 187 return 0;
206 } 188 }
207 189
208 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 190 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
209 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke yRange.release(), true, WebIDBCallbacksImpl::create(request).leakPtr()); 191 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke yRange.release(), keyOnly, WebIDBCallbacksImpl::create(request).leakPtr());
210 return request; 192 return request;
211 } 193 }
212 194
213 WebIDBDatabase* IDBIndex::backendDB() const 195 WebIDBDatabase* IDBIndex::backendDB() const
214 { 196 {
215 return m_transaction->backendDB(); 197 return m_transaction->backendDB();
216 } 198 }
217 199
218 bool IDBIndex::isDeleted() const 200 bool IDBIndex::isDeleted() const
219 { 201 {
220 return m_deleted || m_objectStore->isDeleted(); 202 return m_deleted || m_objectStore->isDeleted();
221 } 203 }
222 204
223 } // namespace WebCore 205 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/indexeddb/IDBIndex.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698