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

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

Issue 1963293002: Replacing Indexed DB Chromium IPC with Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Some (incomplete) work on struct traits. Created 4 years, 5 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 13 matching lines...) Expand all
24 */ 24 */
25 25
26 #include "modules/indexeddb/IDBIndex.h" 26 #include "modules/indexeddb/IDBIndex.h"
27 27
28 #include "bindings/core/v8/ExceptionState.h" 28 #include "bindings/core/v8/ExceptionState.h"
29 #include "bindings/modules/v8/ToV8ForModules.h" 29 #include "bindings/modules/v8/ToV8ForModules.h"
30 #include "bindings/modules/v8/V8BindingForModules.h" 30 #include "bindings/modules/v8/V8BindingForModules.h"
31 #include "core/dom/ExceptionCode.h" 31 #include "core/dom/ExceptionCode.h"
32 #include "core/dom/ExecutionContext.h" 32 #include "core/dom/ExecutionContext.h"
33 #include "modules/indexeddb/IDBDatabase.h" 33 #include "modules/indexeddb/IDBDatabase.h"
34 #include "modules/indexeddb/IDBDatabaseProxy.h"
34 #include "modules/indexeddb/IDBKey.h" 35 #include "modules/indexeddb/IDBKey.h"
35 #include "modules/indexeddb/IDBObjectStore.h" 36 #include "modules/indexeddb/IDBObjectStore.h"
36 #include "modules/indexeddb/IDBTracing.h" 37 #include "modules/indexeddb/IDBTracing.h"
37 #include "modules/indexeddb/IDBTransaction.h" 38 #include "modules/indexeddb/IDBTransaction.h"
38 #include "modules/indexeddb/WebIDBCallbacksImpl.h" 39 #include "modules/indexeddb/ResponseHandler.h"
39 #include "public/platform/modules/indexeddb/WebIDBKeyRange.h" 40 #include "public/platform/modules/indexeddb/WebIDBKeyRange.h"
40 #include <memory> 41 #include <memory>
41 42
42 using blink::WebIDBCallbacks; 43 using indexed_db::mojom::blink::CursorDirection;
43 using blink::WebIDBCursor;
44 using blink::WebIDBDatabase;
45 44
46 namespace blink { 45 namespace blink {
47 46
48 IDBIndex::IDBIndex(const IDBIndexMetadata& metadata, IDBObjectStore* objectStore , IDBTransaction* transaction) 47 IDBIndex::IDBIndex(const IDBIndexMetadata& metadata, IDBObjectStore* objectStore , IDBTransaction* transaction)
49 : m_metadata(metadata) 48 : m_metadata(metadata)
50 , m_objectStore(objectStore) 49 , m_objectStore(objectStore)
51 , m_transaction(transaction) 50 , m_transaction(transaction)
52 { 51 {
53 ASSERT(m_objectStore); 52 ASSERT(m_objectStore);
54 ASSERT(m_transaction); 53 ASSERT(m_transaction);
(...skipping 23 matching lines...) Expand all
78 return nullptr; 77 return nullptr;
79 } 78 }
80 if (m_transaction->isFinished() || m_transaction->isFinishing()) { 79 if (m_transaction->isFinished() || m_transaction->isFinishing()) {
81 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 80 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
82 return nullptr; 81 return nullptr;
83 } 82 }
84 if (!m_transaction->isActive()) { 83 if (!m_transaction->isActive()) {
85 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 84 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
86 return nullptr; 85 return nullptr;
87 } 86 }
88 WebIDBCursorDirection direction = IDBCursor::stringToDirection(directionStri ng); 87 CursorDirection direction = IDBCursor::stringToDirection(directionString);
89 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti onContext(), range, exceptionState); 88 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti onContext(), range, exceptionState);
90 if (exceptionState.hadException()) 89 if (exceptionState.hadException())
91 return nullptr; 90 return nullptr;
92 91
93 if (!backendDB()) { 92 if (!backendDB()) {
94 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); 93 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage);
95 return nullptr; 94 return nullptr;
96 } 95 }
97 96
98 return openCursor(scriptState, keyRange, direction); 97 return openCursor(scriptState, keyRange, direction);
99 } 98 }
100 99
101 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, IDBKeyRange* keyRange , WebIDBCursorDirection direction) 100 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, IDBKeyRange* keyRange , CursorDirection direction)
102 { 101 {
103 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); 102 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get());
104 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); 103 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction);
105 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata .id, keyRange, direction, false, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::crea te(request).release()); 104 backendDB()->OpenCursor(m_transaction->id(), m_objectStore->id(), m_metadata .id, keyRange, direction, false, indexed_db::mojom::blink::TaskType::Normal);
106 return request; 105 return request;
107 } 106 }
108 107
109 IDBRequest* IDBIndex::count(ScriptState* scriptState, const ScriptValue& range, ExceptionState& exceptionState) 108 IDBRequest* IDBIndex::count(ScriptState* scriptState, const ScriptValue& range, ExceptionState& exceptionState)
110 { 109 {
111 IDB_TRACE("IDBIndex::count"); 110 IDB_TRACE("IDBIndex::count");
112 if (isDeleted()) { 111 if (isDeleted()) {
113 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage); 112 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage);
114 return nullptr; 113 return nullptr;
115 } 114 }
116 if (m_transaction->isFinished() || m_transaction->isFinishing()) { 115 if (m_transaction->isFinished() || m_transaction->isFinishing()) {
117 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 116 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
118 return nullptr; 117 return nullptr;
119 } 118 }
120 if (!m_transaction->isActive()) { 119 if (!m_transaction->isActive()) {
121 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 120 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
122 return nullptr; 121 return nullptr;
123 } 122 }
124 123
125 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti onContext(), range, exceptionState); 124 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti onContext(), range, exceptionState);
126 if (exceptionState.hadException()) 125 if (exceptionState.hadException())
127 return nullptr; 126 return nullptr;
128 127
129 if (!backendDB()) { 128 if (!backendDB()) {
130 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); 129 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage);
131 return nullptr; 130 return nullptr;
132 } 131 }
133 132
134 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); 133 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get());
135 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id, keyRange, WebIDBCallbacksImpl::create(request).release()); 134 backendDB()->Count(m_transaction->id(), m_objectStore->id(), m_metadata.id, keyRange);
136 return request; 135 return request;
137 } 136 }
138 137
139 IDBRequest* IDBIndex::openKeyCursor(ScriptState* scriptState, const ScriptValue& range, const String& directionString, ExceptionState& exceptionState) 138 IDBRequest* IDBIndex::openKeyCursor(ScriptState* scriptState, const ScriptValue& range, const String& directionString, ExceptionState& exceptionState)
140 { 139 {
141 IDB_TRACE("IDBIndex::openKeyCursor"); 140 IDB_TRACE("IDBIndex::openKeyCursor");
142 if (isDeleted()) { 141 if (isDeleted()) {
143 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage); 142 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage);
144 return nullptr; 143 return nullptr;
145 } 144 }
146 if (m_transaction->isFinished() || m_transaction->isFinishing()) { 145 if (m_transaction->isFinished() || m_transaction->isFinishing()) {
147 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage); 146 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
148 return nullptr; 147 return nullptr;
149 } 148 }
150 if (!m_transaction->isActive()) { 149 if (!m_transaction->isActive()) {
151 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage); 150 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
152 return nullptr; 151 return nullptr;
153 } 152 }
154 WebIDBCursorDirection direction = IDBCursor::stringToDirection(directionStri ng); 153 CursorDirection direction = IDBCursor::stringToDirection(directionString);
155 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti onContext(), range, exceptionState); 154 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti onContext(), range, exceptionState);
156 if (exceptionState.hadException()) 155 if (exceptionState.hadException())
157 return nullptr; 156 return nullptr;
158 if (!backendDB()) { 157 if (!backendDB()) {
159 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); 158 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage);
160 return nullptr; 159 return nullptr;
161 } 160 }
162 161
163 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); 162 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get());
164 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); 163 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction);
165 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata .id, keyRange, direction, true, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::creat e(request).release()); 164 backendDB()->OpenCursor(m_transaction->id(), m_objectStore->id(), m_metadata .id, keyRange, direction, true, indexed_db::mojom::blink::TaskType::Normal);
166 return request; 165 return request;
167 } 166 }
168 167
169 IDBRequest* IDBIndex::get(ScriptState* scriptState, const ScriptValue& key, Exce ptionState& exceptionState) 168 IDBRequest* IDBIndex::get(ScriptState* scriptState, const ScriptValue& key, Exce ptionState& exceptionState)
170 { 169 {
171 IDB_TRACE("IDBIndex::get"); 170 IDB_TRACE("IDBIndex::get");
172 return getInternal(scriptState, key, exceptionState, false); 171 return getInternal(scriptState, key, exceptionState, false);
173 } 172 }
174 173
175 IDBRequest* IDBIndex::getAll(ScriptState* scriptState, const ScriptValue& range, ExceptionState& exceptionState) 174 IDBRequest* IDBIndex::getAll(ScriptState* scriptState, const ScriptValue& range, ExceptionState& exceptionState)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 if (!keyRange) { 220 if (!keyRange) {
222 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage); 221 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage);
223 return nullptr; 222 return nullptr;
224 } 223 }
225 if (!backendDB()) { 224 if (!backendDB()) {
226 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); 225 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage);
227 return nullptr; 226 return nullptr;
228 } 227 }
229 228
230 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); 229 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get());
231 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke yRange, keyOnly, WebIDBCallbacksImpl::create(request).release()); 230 backendDB()->Get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke yRange, keyOnly, ResponseHandler::createGetCallback(request));
232 return request; 231 return request;
233 } 232 }
234 233
235 IDBRequest* IDBIndex::getAllInternal(ScriptState* scriptState, const ScriptValue & range, unsigned long maxCount, ExceptionState& exceptionState, bool keyOnly) 234 IDBRequest* IDBIndex::getAllInternal(ScriptState* scriptState, const ScriptValue & range, unsigned long maxCount, ExceptionState& exceptionState, bool keyOnly)
236 { 235 {
237 if (!maxCount) 236 if (!maxCount)
238 maxCount = std::numeric_limits<uint32_t>::max(); 237 maxCount = std::numeric_limits<uint32_t>::max();
239 238
240 if (isDeleted()) { 239 if (isDeleted()) {
241 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage); 240 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe letedErrorMessage);
(...skipping 10 matching lines...) Expand all
252 251
253 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti onContext(), range, exceptionState); 252 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti onContext(), range, exceptionState);
254 if (exceptionState.hadException()) 253 if (exceptionState.hadException())
255 return nullptr; 254 return nullptr;
256 if (!backendDB()) { 255 if (!backendDB()) {
257 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage); 256 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas eClosedErrorMessage);
258 return nullptr; 257 return nullptr;
259 } 258 }
260 259
261 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get()); 260 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), m_transaction.get());
262 backendDB()->getAll(m_transaction->id(), m_objectStore->id(), m_metadata.id, keyRange, maxCount, keyOnly, WebIDBCallbacksImpl::create(request).release()); 261 backendDB()->GetAll(m_transaction->id(), m_objectStore->id(), m_metadata.id, keyRange, maxCount, keyOnly);
263 return request; 262 return request;
264 } 263 }
265 264
266 WebIDBDatabase* IDBIndex::backendDB() const 265 IDBDatabaseProxy* IDBIndex::backendDB() const
267 { 266 {
268 return m_transaction->backendDB(); 267 return m_transaction->backendDB();
269 } 268 }
270 269
271 bool IDBIndex::isDeleted() const 270 bool IDBIndex::isDeleted() const
272 { 271 {
273 return m_deleted || m_objectStore->isDeleted(); 272 return m_deleted || m_objectStore->isDeleted();
274 } 273 }
275 274
276 } // namespace blink 275 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698