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

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

Issue 2890023003: [IndexedDB] Adding async tracing for renderer calls. (Closed)
Patch Set: fixed tests Created 3 years, 7 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 108
109 // An index's metadata will only get reverted if the index was in the 109 // An index's metadata will only get reverted if the index was in the
110 // database when the versionchange transaction started. 110 // database when the versionchange transaction started.
111 deleted_ = false; 111 deleted_ = false;
112 } 112 }
113 113
114 IDBRequest* IDBIndex::openCursor(ScriptState* script_state, 114 IDBRequest* IDBIndex::openCursor(ScriptState* script_state,
115 const ScriptValue& range, 115 const ScriptValue& range,
116 const String& direction_string, 116 const String& direction_string,
117 ExceptionState& exception_state) { 117 ExceptionState& exception_state) {
118 IDB_TRACE("IDBIndex::openCursor"); 118 IDB_TRACE("IDBIndex::openCursorCall");
119 auto metrics = WTF::MakeUnique<IDBRequest::ScopedMetricsTracker>(
120 nullptr, "IDBIndex::openCursor", this);
119 if (IsDeleted()) { 121 if (IsDeleted()) {
120 exception_state.ThrowDOMException(kInvalidStateError, 122 exception_state.ThrowDOMException(kInvalidStateError,
121 IDBDatabase::kIndexDeletedErrorMessage); 123 IDBDatabase::kIndexDeletedErrorMessage);
122 return nullptr; 124 return nullptr;
123 } 125 }
124 if (!transaction_->IsActive()) { 126 if (!transaction_->IsActive()) {
125 exception_state.ThrowDOMException(kTransactionInactiveError, 127 exception_state.ThrowDOMException(kTransactionInactiveError,
126 transaction_->InactiveErrorMessage()); 128 transaction_->InactiveErrorMessage());
127 return nullptr; 129 return nullptr;
128 } 130 }
129 WebIDBCursorDirection direction = 131 WebIDBCursorDirection direction =
130 IDBCursor::StringToDirection(direction_string); 132 IDBCursor::StringToDirection(direction_string);
131 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( 133 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue(
132 ExecutionContext::From(script_state), range, exception_state); 134 ExecutionContext::From(script_state), range, exception_state);
133 if (exception_state.HadException()) 135 if (exception_state.HadException())
134 return nullptr; 136 return nullptr;
135 137
136 if (!BackendDB()) { 138 if (!BackendDB()) {
137 exception_state.ThrowDOMException(kInvalidStateError, 139 exception_state.ThrowDOMException(kInvalidStateError,
138 IDBDatabase::kDatabaseClosedErrorMessage); 140 IDBDatabase::kDatabaseClosedErrorMessage);
139 return nullptr; 141 return nullptr;
140 } 142 }
141 143
142 return openCursor(script_state, key_range, direction); 144 return openCursor(script_state, key_range, direction, std::move(metrics));
143 } 145 }
144 146
145 IDBRequest* IDBIndex::openCursor(ScriptState* script_state, 147 IDBRequest* IDBIndex::openCursor(
146 IDBKeyRange* key_range, 148 ScriptState* script_state,
147 WebIDBCursorDirection direction) { 149 IDBKeyRange* key_range,
148 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 150 WebIDBCursorDirection direction,
149 transaction_.Get()); 151 std::unique_ptr<IDBRequest::ScopedMetricsTracker> metrics) {
152 IDBRequest* request =
153 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(),
154 std::move(metrics));
150 request->SetCursorDetails(IndexedDB::kCursorKeyAndValue, direction); 155 request->SetCursorDetails(IndexedDB::kCursorKeyAndValue, direction);
151 BackendDB()->OpenCursor(transaction_->Id(), object_store_->Id(), Id(), 156 BackendDB()->OpenCursor(transaction_->Id(), object_store_->Id(), Id(),
152 key_range, direction, false, kWebIDBTaskTypeNormal, 157 key_range, direction, false, kWebIDBTaskTypeNormal,
153 request->CreateWebCallbacks().release()); 158 request->CreateWebCallbacks().release());
154 return request; 159 return request;
155 } 160 }
156 161
157 IDBRequest* IDBIndex::count(ScriptState* script_state, 162 IDBRequest* IDBIndex::count(ScriptState* script_state,
158 const ScriptValue& range, 163 const ScriptValue& range,
159 ExceptionState& exception_state) { 164 ExceptionState& exception_state) {
160 IDB_TRACE("IDBIndex::count"); 165 IDB_TRACE("IDBIndex::countCall");
166 auto metrics = WTF::MakeUnique<IDBRequest::ScopedMetricsTracker>(
167 nullptr, "IDBIndex::count", this);
161 if (IsDeleted()) { 168 if (IsDeleted()) {
162 exception_state.ThrowDOMException(kInvalidStateError, 169 exception_state.ThrowDOMException(kInvalidStateError,
163 IDBDatabase::kIndexDeletedErrorMessage); 170 IDBDatabase::kIndexDeletedErrorMessage);
164 return nullptr; 171 return nullptr;
165 } 172 }
166 if (!transaction_->IsActive()) { 173 if (!transaction_->IsActive()) {
167 exception_state.ThrowDOMException(kTransactionInactiveError, 174 exception_state.ThrowDOMException(kTransactionInactiveError,
168 transaction_->InactiveErrorMessage()); 175 transaction_->InactiveErrorMessage());
169 return nullptr; 176 return nullptr;
170 } 177 }
171 178
172 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( 179 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue(
173 ExecutionContext::From(script_state), range, exception_state); 180 ExecutionContext::From(script_state), range, exception_state);
174 if (exception_state.HadException()) 181 if (exception_state.HadException())
175 return nullptr; 182 return nullptr;
176 183
177 if (!BackendDB()) { 184 if (!BackendDB()) {
178 exception_state.ThrowDOMException(kInvalidStateError, 185 exception_state.ThrowDOMException(kInvalidStateError,
179 IDBDatabase::kDatabaseClosedErrorMessage); 186 IDBDatabase::kDatabaseClosedErrorMessage);
180 return nullptr; 187 return nullptr;
181 } 188 }
182 189
183 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 190 IDBRequest* request =
184 transaction_.Get()); 191 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(),
192 std::move(metrics));
185 BackendDB()->Count(transaction_->Id(), object_store_->Id(), Id(), key_range, 193 BackendDB()->Count(transaction_->Id(), object_store_->Id(), Id(), key_range,
186 request->CreateWebCallbacks().release()); 194 request->CreateWebCallbacks().release());
187 return request; 195 return request;
188 } 196 }
189 197
190 IDBRequest* IDBIndex::openKeyCursor(ScriptState* script_state, 198 IDBRequest* IDBIndex::openKeyCursor(ScriptState* script_state,
191 const ScriptValue& range, 199 const ScriptValue& range,
192 const String& direction_string, 200 const String& direction_string,
193 ExceptionState& exception_state) { 201 ExceptionState& exception_state) {
194 IDB_TRACE("IDBIndex::openKeyCursor"); 202 IDB_TRACE("IDBIndex::openKeyCursorCall");
203 auto metrics = WTF::MakeUnique<IDBRequest::ScopedMetricsTracker>(
204 nullptr, "IDBIndex::openKeyCursor", this);
195 if (IsDeleted()) { 205 if (IsDeleted()) {
196 exception_state.ThrowDOMException(kInvalidStateError, 206 exception_state.ThrowDOMException(kInvalidStateError,
197 IDBDatabase::kIndexDeletedErrorMessage); 207 IDBDatabase::kIndexDeletedErrorMessage);
198 return nullptr; 208 return nullptr;
199 } 209 }
200 if (!transaction_->IsActive()) { 210 if (!transaction_->IsActive()) {
201 exception_state.ThrowDOMException(kTransactionInactiveError, 211 exception_state.ThrowDOMException(kTransactionInactiveError,
202 transaction_->InactiveErrorMessage()); 212 transaction_->InactiveErrorMessage());
203 return nullptr; 213 return nullptr;
204 } 214 }
205 WebIDBCursorDirection direction = 215 WebIDBCursorDirection direction =
206 IDBCursor::StringToDirection(direction_string); 216 IDBCursor::StringToDirection(direction_string);
207 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( 217 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue(
208 ExecutionContext::From(script_state), range, exception_state); 218 ExecutionContext::From(script_state), range, exception_state);
209 if (exception_state.HadException()) 219 if (exception_state.HadException())
210 return nullptr; 220 return nullptr;
211 if (!BackendDB()) { 221 if (!BackendDB()) {
212 exception_state.ThrowDOMException(kInvalidStateError, 222 exception_state.ThrowDOMException(kInvalidStateError,
213 IDBDatabase::kDatabaseClosedErrorMessage); 223 IDBDatabase::kDatabaseClosedErrorMessage);
214 return nullptr; 224 return nullptr;
215 } 225 }
216 226
217 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 227 IDBRequest* request =
218 transaction_.Get()); 228 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(),
229 std::move(metrics));
219 request->SetCursorDetails(IndexedDB::kCursorKeyOnly, direction); 230 request->SetCursorDetails(IndexedDB::kCursorKeyOnly, direction);
220 BackendDB()->OpenCursor(transaction_->Id(), object_store_->Id(), Id(), 231 BackendDB()->OpenCursor(transaction_->Id(), object_store_->Id(), Id(),
221 key_range, direction, true, kWebIDBTaskTypeNormal, 232 key_range, direction, true, kWebIDBTaskTypeNormal,
222 request->CreateWebCallbacks().release()); 233 request->CreateWebCallbacks().release());
223 return request; 234 return request;
224 } 235 }
225 236
226 IDBRequest* IDBIndex::get(ScriptState* script_state, 237 IDBRequest* IDBIndex::get(ScriptState* script_state,
227 const ScriptValue& key, 238 const ScriptValue& key,
228 ExceptionState& exception_state) { 239 ExceptionState& exception_state) {
229 IDB_TRACE("IDBIndex::get"); 240 IDB_TRACE("IDBIndex::getCall");
230 return GetInternal(script_state, key, exception_state, false); 241 return GetInternal(script_state, key, exception_state, false);
231 } 242 }
232 243
233 IDBRequest* IDBIndex::getAll(ScriptState* script_state, 244 IDBRequest* IDBIndex::getAll(ScriptState* script_state,
234 const ScriptValue& range, 245 const ScriptValue& range,
235 ExceptionState& exception_state) { 246 ExceptionState& exception_state) {
236 return getAll(script_state, range, std::numeric_limits<uint32_t>::max(), 247 return getAll(script_state, range, std::numeric_limits<uint32_t>::max(),
237 exception_state); 248 exception_state);
238 } 249 }
239 250
240 IDBRequest* IDBIndex::getAll(ScriptState* script_state, 251 IDBRequest* IDBIndex::getAll(ScriptState* script_state,
241 const ScriptValue& range, 252 const ScriptValue& range,
242 unsigned long max_count, 253 unsigned long max_count,
243 ExceptionState& exception_state) { 254 ExceptionState& exception_state) {
244 IDB_TRACE("IDBIndex::getAll"); 255 IDB_TRACE("IDBIndex::getAllCall");
245 return GetAllInternal(script_state, range, max_count, exception_state, false); 256 return GetAllInternal(script_state, range, max_count, exception_state, false);
246 } 257 }
247 258
248 IDBRequest* IDBIndex::getAllKeys(ScriptState* script_state, 259 IDBRequest* IDBIndex::getAllKeys(ScriptState* script_state,
249 const ScriptValue& range, 260 const ScriptValue& range,
250 ExceptionState& exception_state) { 261 ExceptionState& exception_state) {
251 return getAllKeys(script_state, range, std::numeric_limits<uint32_t>::max(), 262 return getAllKeys(script_state, range, std::numeric_limits<uint32_t>::max(),
252 exception_state); 263 exception_state);
253 } 264 }
254 265
255 IDBRequest* IDBIndex::getAllKeys(ScriptState* script_state, 266 IDBRequest* IDBIndex::getAllKeys(ScriptState* script_state,
256 const ScriptValue& range, 267 const ScriptValue& range,
257 uint32_t max_count, 268 uint32_t max_count,
258 ExceptionState& exception_state) { 269 ExceptionState& exception_state) {
259 IDB_TRACE("IDBIndex::getAllKeys"); 270 IDB_TRACE("IDBIndex::getAllKeysCall");
260 return GetAllInternal(script_state, range, max_count, exception_state, 271 return GetAllInternal(script_state, range, max_count, exception_state,
261 /*key_only=*/true); 272 /*key_only=*/true);
262 } 273 }
263 274
264 IDBRequest* IDBIndex::getKey(ScriptState* script_state, 275 IDBRequest* IDBIndex::getKey(ScriptState* script_state,
265 const ScriptValue& key, 276 const ScriptValue& key,
266 ExceptionState& exception_state) { 277 ExceptionState& exception_state) {
267 IDB_TRACE("IDBIndex::getKey"); 278 IDB_TRACE("IDBIndex::getKeyCall");
268 return GetInternal(script_state, key, exception_state, true); 279 return GetInternal(script_state, key, exception_state, true);
269 } 280 }
270 281
271 IDBRequest* IDBIndex::GetInternal(ScriptState* script_state, 282 IDBRequest* IDBIndex::GetInternal(ScriptState* script_state,
272 const ScriptValue& key, 283 const ScriptValue& key,
273 ExceptionState& exception_state, 284 ExceptionState& exception_state,
274 bool key_only) { 285 bool key_only) {
286 auto metrics = WTF::MakeUnique<IDBRequest::ScopedMetricsTracker>(
287 nullptr, key_only ? "IDBIndex::getKey" : "IDBIndex::get", this);
275 if (IsDeleted()) { 288 if (IsDeleted()) {
276 exception_state.ThrowDOMException(kInvalidStateError, 289 exception_state.ThrowDOMException(kInvalidStateError,
277 IDBDatabase::kIndexDeletedErrorMessage); 290 IDBDatabase::kIndexDeletedErrorMessage);
278 return nullptr; 291 return nullptr;
279 } 292 }
280 if (!transaction_->IsActive()) { 293 if (!transaction_->IsActive()) {
281 exception_state.ThrowDOMException(kTransactionInactiveError, 294 exception_state.ThrowDOMException(kTransactionInactiveError,
282 transaction_->InactiveErrorMessage()); 295 transaction_->InactiveErrorMessage());
283 return nullptr; 296 return nullptr;
284 } 297 }
285 298
286 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( 299 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue(
287 ExecutionContext::From(script_state), key, exception_state); 300 ExecutionContext::From(script_state), key, exception_state);
288 if (exception_state.HadException()) 301 if (exception_state.HadException())
289 return nullptr; 302 return nullptr;
290 if (!key_range) { 303 if (!key_range) {
291 exception_state.ThrowDOMException( 304 exception_state.ThrowDOMException(
292 kDataError, IDBDatabase::kNoKeyOrKeyRangeErrorMessage); 305 kDataError, IDBDatabase::kNoKeyOrKeyRangeErrorMessage);
293 return nullptr; 306 return nullptr;
294 } 307 }
295 if (!BackendDB()) { 308 if (!BackendDB()) {
296 exception_state.ThrowDOMException(kInvalidStateError, 309 exception_state.ThrowDOMException(kInvalidStateError,
297 IDBDatabase::kDatabaseClosedErrorMessage); 310 IDBDatabase::kDatabaseClosedErrorMessage);
298 return nullptr; 311 return nullptr;
299 } 312 }
300 313
301 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 314 IDBRequest* request =
302 transaction_.Get()); 315 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(),
316 std::move(metrics));
303 BackendDB()->Get(transaction_->Id(), object_store_->Id(), Id(), key_range, 317 BackendDB()->Get(transaction_->Id(), object_store_->Id(), Id(), key_range,
304 key_only, request->CreateWebCallbacks().release()); 318 key_only, request->CreateWebCallbacks().release());
305 return request; 319 return request;
306 } 320 }
307 321
308 IDBRequest* IDBIndex::GetAllInternal(ScriptState* script_state, 322 IDBRequest* IDBIndex::GetAllInternal(ScriptState* script_state,
309 const ScriptValue& range, 323 const ScriptValue& range,
310 unsigned long max_count, 324 unsigned long max_count,
311 ExceptionState& exception_state, 325 ExceptionState& exception_state,
312 bool key_only) { 326 bool key_only) {
327 auto metrics = WTF::MakeUnique<IDBRequest::ScopedMetricsTracker>(
328 nullptr, key_only ? "IDBIndex::getAllKeys" : "IDBIndex::getAll", this);
313 if (!max_count) 329 if (!max_count)
314 max_count = std::numeric_limits<uint32_t>::max(); 330 max_count = std::numeric_limits<uint32_t>::max();
315 331
316 if (IsDeleted()) { 332 if (IsDeleted()) {
317 exception_state.ThrowDOMException(kInvalidStateError, 333 exception_state.ThrowDOMException(kInvalidStateError,
318 IDBDatabase::kIndexDeletedErrorMessage); 334 IDBDatabase::kIndexDeletedErrorMessage);
319 return nullptr; 335 return nullptr;
320 } 336 }
321 if (!transaction_->IsActive()) { 337 if (!transaction_->IsActive()) {
322 exception_state.ThrowDOMException(kTransactionInactiveError, 338 exception_state.ThrowDOMException(kTransactionInactiveError,
323 transaction_->InactiveErrorMessage()); 339 transaction_->InactiveErrorMessage());
324 return nullptr; 340 return nullptr;
325 } 341 }
326 342
327 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( 343 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue(
328 ExecutionContext::From(script_state), range, exception_state); 344 ExecutionContext::From(script_state), range, exception_state);
329 if (exception_state.HadException()) 345 if (exception_state.HadException())
330 return nullptr; 346 return nullptr;
331 if (!BackendDB()) { 347 if (!BackendDB()) {
332 exception_state.ThrowDOMException(kInvalidStateError, 348 exception_state.ThrowDOMException(kInvalidStateError,
333 IDBDatabase::kDatabaseClosedErrorMessage); 349 IDBDatabase::kDatabaseClosedErrorMessage);
334 return nullptr; 350 return nullptr;
335 } 351 }
336 352
337 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 353 IDBRequest* request =
338 transaction_.Get()); 354 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(),
355 std::move(metrics));
339 BackendDB()->GetAll(transaction_->Id(), object_store_->Id(), Id(), key_range, 356 BackendDB()->GetAll(transaction_->Id(), object_store_->Id(), Id(), key_range,
340 max_count, key_only, 357 max_count, key_only,
341 request->CreateWebCallbacks().release()); 358 request->CreateWebCallbacks().release());
342 return request; 359 return request;
343 } 360 }
344 361
345 WebIDBDatabase* IDBIndex::BackendDB() const { 362 WebIDBDatabase* IDBIndex::BackendDB() const {
346 return transaction_->BackendDB(); 363 return transaction_->BackendDB();
347 } 364 }
348 365
349 } // namespace blink 366 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698