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

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

Issue 2890023003: [IndexedDB] Adding async tracing for renderer calls. (Closed)
Patch Set: fixed blink tests Created 3 years, 6 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 26 matching lines...) Expand all
37 #include "core/dom/ExecutionContext.h" 37 #include "core/dom/ExecutionContext.h"
38 #include "modules/indexeddb/IDBAny.h" 38 #include "modules/indexeddb/IDBAny.h"
39 #include "modules/indexeddb/IDBCursorWithValue.h" 39 #include "modules/indexeddb/IDBCursorWithValue.h"
40 #include "modules/indexeddb/IDBDatabase.h" 40 #include "modules/indexeddb/IDBDatabase.h"
41 #include "modules/indexeddb/IDBKeyPath.h" 41 #include "modules/indexeddb/IDBKeyPath.h"
42 #include "modules/indexeddb/IDBTracing.h" 42 #include "modules/indexeddb/IDBTracing.h"
43 #include "modules/indexeddb/IDBValueWrapping.h" 43 #include "modules/indexeddb/IDBValueWrapping.h"
44 #include "platform/Histogram.h" 44 #include "platform/Histogram.h"
45 #include "platform/SharedBuffer.h" 45 #include "platform/SharedBuffer.h"
46 #include "platform/bindings/ScriptState.h" 46 #include "platform/bindings/ScriptState.h"
47 #include "platform/wtf/PtrUtil.h"
47 #include "platform/wtf/RefPtr.h" 48 #include "platform/wtf/RefPtr.h"
48 #include "public/platform/WebBlobInfo.h" 49 #include "public/platform/WebBlobInfo.h"
49 #include "public/platform/WebData.h" 50 #include "public/platform/WebData.h"
50 #include "public/platform/WebVector.h" 51 #include "public/platform/WebVector.h"
51 #include "public/platform/modules/indexeddb/WebIDBKey.h" 52 #include "public/platform/modules/indexeddb/WebIDBKey.h"
52 #include "public/platform/modules/indexeddb/WebIDBKeyRange.h" 53 #include "public/platform/modules/indexeddb/WebIDBKeyRange.h"
53 #include "v8/include/v8.h" 54 #include "v8/include/v8.h"
54 55
55 using blink::WebBlobInfo; 56 using blink::WebBlobInfo;
56 using blink::WebIDBCallbacks; 57 using blink::WebIDBCallbacks;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 DOMStringList* index_names = DOMStringList::Create(); 123 DOMStringList* index_names = DOMStringList::Create();
123 for (const auto& it : Metadata().indexes) 124 for (const auto& it : Metadata().indexes)
124 index_names->Append(it.value->name); 125 index_names->Append(it.value->name);
125 index_names->Sort(); 126 index_names->Sort();
126 return index_names; 127 return index_names;
127 } 128 }
128 129
129 IDBRequest* IDBObjectStore::get(ScriptState* script_state, 130 IDBRequest* IDBObjectStore::get(ScriptState* script_state,
130 const ScriptValue& key, 131 const ScriptValue& key,
131 ExceptionState& exception_state) { 132 ExceptionState& exception_state) {
132 IDB_TRACE("IDBObjectStore::get"); 133 IDB_TRACE("IDBObjectStore::getRequestSetup");
134 IDBRequest::AsyncTraceState metrics("IDBObjectStore::get", this);
133 if (IsDeleted()) { 135 if (IsDeleted()) {
134 exception_state.ThrowDOMException( 136 exception_state.ThrowDOMException(
135 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage); 137 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage);
136 return nullptr; 138 return nullptr;
137 } 139 }
138 if (!transaction_->IsActive()) { 140 if (!transaction_->IsActive()) {
139 exception_state.ThrowDOMException(kTransactionInactiveError, 141 exception_state.ThrowDOMException(kTransactionInactiveError,
140 transaction_->InactiveErrorMessage()); 142 transaction_->InactiveErrorMessage());
141 return nullptr; 143 return nullptr;
142 } 144 }
143 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( 145 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue(
144 ExecutionContext::From(script_state), key, exception_state); 146 ExecutionContext::From(script_state), key, exception_state);
145 if (exception_state.HadException()) 147 if (exception_state.HadException())
146 return nullptr; 148 return nullptr;
147 if (!key_range) { 149 if (!key_range) {
148 exception_state.ThrowDOMException( 150 exception_state.ThrowDOMException(
149 kDataError, IDBDatabase::kNoKeyOrKeyRangeErrorMessage); 151 kDataError, IDBDatabase::kNoKeyOrKeyRangeErrorMessage);
150 return nullptr; 152 return nullptr;
151 } 153 }
152 if (!BackendDB()) { 154 if (!BackendDB()) {
153 exception_state.ThrowDOMException(kInvalidStateError, 155 exception_state.ThrowDOMException(kInvalidStateError,
154 IDBDatabase::kDatabaseClosedErrorMessage); 156 IDBDatabase::kDatabaseClosedErrorMessage);
155 return nullptr; 157 return nullptr;
156 } 158 }
157 159
158 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 160 IDBRequest* request =
159 transaction_.Get()); 161 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(),
162 std::move(metrics));
160 BackendDB()->Get(transaction_->Id(), Id(), IDBIndexMetadata::kInvalidId, 163 BackendDB()->Get(transaction_->Id(), Id(), IDBIndexMetadata::kInvalidId,
161 key_range, /*key_only=*/false, 164 key_range, /*key_only=*/false,
162 request->CreateWebCallbacks().release()); 165 request->CreateWebCallbacks().release());
163 return request; 166 return request;
164 } 167 }
165 168
166 IDBRequest* IDBObjectStore::getKey(ScriptState* script_state, 169 IDBRequest* IDBObjectStore::getKey(ScriptState* script_state,
167 const ScriptValue& key, 170 const ScriptValue& key,
168 ExceptionState& exception_state) { 171 ExceptionState& exception_state) {
169 IDB_TRACE("IDBObjectStore::getKey"); 172 IDB_TRACE("IDBObjectStore::getKeyRequestSetup");
173 IDBRequest::AsyncTraceState metrics("IDBObjectStore::getKey", this);
170 if (IsDeleted()) { 174 if (IsDeleted()) {
171 exception_state.ThrowDOMException( 175 exception_state.ThrowDOMException(
172 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage); 176 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage);
173 return nullptr; 177 return nullptr;
174 } 178 }
175 if (!transaction_->IsActive()) { 179 if (!transaction_->IsActive()) {
176 exception_state.ThrowDOMException(kTransactionInactiveError, 180 exception_state.ThrowDOMException(kTransactionInactiveError,
177 transaction_->InactiveErrorMessage()); 181 transaction_->InactiveErrorMessage());
178 return nullptr; 182 return nullptr;
179 } 183 }
180 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( 184 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue(
181 ExecutionContext::From(script_state), key, exception_state); 185 ExecutionContext::From(script_state), key, exception_state);
182 if (exception_state.HadException()) 186 if (exception_state.HadException())
183 return nullptr; 187 return nullptr;
184 if (!key_range) { 188 if (!key_range) {
185 exception_state.ThrowDOMException( 189 exception_state.ThrowDOMException(
186 kDataError, IDBDatabase::kNoKeyOrKeyRangeErrorMessage); 190 kDataError, IDBDatabase::kNoKeyOrKeyRangeErrorMessage);
187 return nullptr; 191 return nullptr;
188 } 192 }
189 if (!BackendDB()) { 193 if (!BackendDB()) {
190 exception_state.ThrowDOMException(kInvalidStateError, 194 exception_state.ThrowDOMException(kInvalidStateError,
191 IDBDatabase::kDatabaseClosedErrorMessage); 195 IDBDatabase::kDatabaseClosedErrorMessage);
192 return nullptr; 196 return nullptr;
193 } 197 }
194 198
195 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 199 IDBRequest* request =
196 transaction_.Get()); 200 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(),
201 std::move(metrics));
197 BackendDB()->Get(transaction_->Id(), Id(), IDBIndexMetadata::kInvalidId, 202 BackendDB()->Get(transaction_->Id(), Id(), IDBIndexMetadata::kInvalidId,
198 key_range, /*key_only=*/true, 203 key_range, /*key_only=*/true,
199 request->CreateWebCallbacks().release()); 204 request->CreateWebCallbacks().release());
200 return request; 205 return request;
201 } 206 }
202 207
203 IDBRequest* IDBObjectStore::getAll(ScriptState* script_state, 208 IDBRequest* IDBObjectStore::getAll(ScriptState* script_state,
204 const ScriptValue& key_range, 209 const ScriptValue& key_range,
205 ExceptionState& exception_state) { 210 ExceptionState& exception_state) {
206 return getAll(script_state, key_range, std::numeric_limits<uint32_t>::max(), 211 return getAll(script_state, key_range, std::numeric_limits<uint32_t>::max(),
207 exception_state); 212 exception_state);
208 } 213 }
209 214
210 IDBRequest* IDBObjectStore::getAll(ScriptState* script_state, 215 IDBRequest* IDBObjectStore::getAll(ScriptState* script_state,
211 const ScriptValue& key_range, 216 const ScriptValue& key_range,
212 unsigned long max_count, 217 unsigned long max_count,
213 ExceptionState& exception_state) { 218 ExceptionState& exception_state) {
214 IDB_TRACE("IDBObjectStore::getAll"); 219 IDB_TRACE("IDBObjectStore::getAllRequestSetup");
220 IDBRequest::AsyncTraceState metrics("IDBObjectStore::getAll", this);
215 if (!max_count) 221 if (!max_count)
216 max_count = std::numeric_limits<uint32_t>::max(); 222 max_count = std::numeric_limits<uint32_t>::max();
217 223
218 if (IsDeleted()) { 224 if (IsDeleted()) {
219 exception_state.ThrowDOMException( 225 exception_state.ThrowDOMException(
220 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage); 226 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage);
221 return nullptr; 227 return nullptr;
222 } 228 }
223 if (!transaction_->IsActive()) { 229 if (!transaction_->IsActive()) {
224 exception_state.ThrowDOMException(kTransactionInactiveError, 230 exception_state.ThrowDOMException(kTransactionInactiveError,
225 transaction_->InactiveErrorMessage()); 231 transaction_->InactiveErrorMessage());
226 return nullptr; 232 return nullptr;
227 } 233 }
228 IDBKeyRange* range = IDBKeyRange::FromScriptValue( 234 IDBKeyRange* range = IDBKeyRange::FromScriptValue(
229 ExecutionContext::From(script_state), key_range, exception_state); 235 ExecutionContext::From(script_state), key_range, exception_state);
230 if (exception_state.HadException()) 236 if (exception_state.HadException())
231 return nullptr; 237 return nullptr;
232 if (!BackendDB()) { 238 if (!BackendDB()) {
233 exception_state.ThrowDOMException(kInvalidStateError, 239 exception_state.ThrowDOMException(kInvalidStateError,
234 IDBDatabase::kDatabaseClosedErrorMessage); 240 IDBDatabase::kDatabaseClosedErrorMessage);
235 return nullptr; 241 return nullptr;
236 } 242 }
237 243
238 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 244 IDBRequest* request =
239 transaction_.Get()); 245 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(),
246 std::move(metrics));
240 BackendDB()->GetAll(transaction_->Id(), Id(), IDBIndexMetadata::kInvalidId, 247 BackendDB()->GetAll(transaction_->Id(), Id(), IDBIndexMetadata::kInvalidId,
241 range, max_count, false, 248 range, max_count, false,
242 request->CreateWebCallbacks().release()); 249 request->CreateWebCallbacks().release());
243 return request; 250 return request;
244 } 251 }
245 252
246 IDBRequest* IDBObjectStore::getAllKeys(ScriptState* script_state, 253 IDBRequest* IDBObjectStore::getAllKeys(ScriptState* script_state,
247 const ScriptValue& key_range, 254 const ScriptValue& key_range,
248 ExceptionState& exception_state) { 255 ExceptionState& exception_state) {
249 return getAllKeys(script_state, key_range, 256 return getAllKeys(script_state, key_range,
250 std::numeric_limits<uint32_t>::max(), exception_state); 257 std::numeric_limits<uint32_t>::max(), exception_state);
251 } 258 }
252 259
253 IDBRequest* IDBObjectStore::getAllKeys(ScriptState* script_state, 260 IDBRequest* IDBObjectStore::getAllKeys(ScriptState* script_state,
254 const ScriptValue& key_range, 261 const ScriptValue& key_range,
255 unsigned long max_count, 262 unsigned long max_count,
256 ExceptionState& exception_state) { 263 ExceptionState& exception_state) {
257 IDB_TRACE("IDBObjectStore::getAll"); 264 IDB_TRACE("IDBObjectStore::getAllKeysRequestSetup");
265 IDBRequest::AsyncTraceState metrics("IDBObjectStore::getAllKeys", this);
258 if (!max_count) 266 if (!max_count)
259 max_count = std::numeric_limits<uint32_t>::max(); 267 max_count = std::numeric_limits<uint32_t>::max();
260 268
261 if (IsDeleted()) { 269 if (IsDeleted()) {
262 exception_state.ThrowDOMException( 270 exception_state.ThrowDOMException(
263 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage); 271 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage);
264 return nullptr; 272 return nullptr;
265 } 273 }
266 if (!transaction_->IsActive()) { 274 if (!transaction_->IsActive()) {
267 exception_state.ThrowDOMException(kTransactionInactiveError, 275 exception_state.ThrowDOMException(kTransactionInactiveError,
268 transaction_->InactiveErrorMessage()); 276 transaction_->InactiveErrorMessage());
269 return nullptr; 277 return nullptr;
270 } 278 }
271 IDBKeyRange* range = IDBKeyRange::FromScriptValue( 279 IDBKeyRange* range = IDBKeyRange::FromScriptValue(
272 ExecutionContext::From(script_state), key_range, exception_state); 280 ExecutionContext::From(script_state), key_range, exception_state);
273 if (exception_state.HadException()) 281 if (exception_state.HadException())
274 return nullptr; 282 return nullptr;
275 if (!BackendDB()) { 283 if (!BackendDB()) {
276 exception_state.ThrowDOMException(kInvalidStateError, 284 exception_state.ThrowDOMException(kInvalidStateError,
277 IDBDatabase::kDatabaseClosedErrorMessage); 285 IDBDatabase::kDatabaseClosedErrorMessage);
278 return nullptr; 286 return nullptr;
279 } 287 }
280 288
281 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 289 IDBRequest* request =
282 transaction_.Get()); 290 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(),
291 std::move(metrics));
283 BackendDB()->GetAll(transaction_->Id(), Id(), IDBIndexMetadata::kInvalidId, 292 BackendDB()->GetAll(transaction_->Id(), Id(), IDBIndexMetadata::kInvalidId,
284 range, max_count, true, 293 range, max_count, true,
285 request->CreateWebCallbacks().release()); 294 request->CreateWebCallbacks().release());
286 return request; 295 return request;
287 } 296 }
288 297
289 static void GenerateIndexKeysForValue(v8::Isolate* isolate, 298 static void GenerateIndexKeysForValue(v8::Isolate* isolate,
290 const IDBIndexMetadata& index_metadata, 299 const IDBIndexMetadata& index_metadata,
291 const ScriptValue& object_value, 300 const ScriptValue& object_value,
292 IndexKeys* index_keys) { 301 IndexKeys* index_keys) {
(...skipping 24 matching lines...) Expand all
317 for (const IDBKey* key : array) 326 for (const IDBKey* key : array)
318 key_type_histogram.Count(static_cast<int>(key->GetType())); 327 key_type_histogram.Count(static_cast<int>(key->GetType()));
319 index_keys->AppendVector(array); 328 index_keys->AppendVector(array);
320 } 329 }
321 } 330 }
322 331
323 IDBRequest* IDBObjectStore::add(ScriptState* script_state, 332 IDBRequest* IDBObjectStore::add(ScriptState* script_state,
324 const ScriptValue& value, 333 const ScriptValue& value,
325 const ScriptValue& key, 334 const ScriptValue& key,
326 ExceptionState& exception_state) { 335 ExceptionState& exception_state) {
327 IDB_TRACE("IDBObjectStore::add"); 336 IDB_TRACE("IDBObjectStore::addRequestSetup");
328 return put(script_state, kWebIDBPutModeAddOnly, IDBAny::Create(this), value, 337 return put(script_state, kWebIDBPutModeAddOnly, IDBAny::Create(this), value,
329 key, exception_state); 338 key, exception_state);
330 } 339 }
331 340
332 IDBRequest* IDBObjectStore::put(ScriptState* script_state, 341 IDBRequest* IDBObjectStore::put(ScriptState* script_state,
333 const ScriptValue& value, 342 const ScriptValue& value,
334 const ScriptValue& key, 343 const ScriptValue& key,
335 ExceptionState& exception_state) { 344 ExceptionState& exception_state) {
336 IDB_TRACE("IDBObjectStore::put"); 345 IDB_TRACE("IDBObjectStore::putRequestSetup");
337 return put(script_state, kWebIDBPutModeAddOrUpdate, IDBAny::Create(this), 346 return put(script_state, kWebIDBPutModeAddOrUpdate, IDBAny::Create(this),
338 value, key, exception_state); 347 value, key, exception_state);
339 } 348 }
340 349
341 IDBRequest* IDBObjectStore::put(ScriptState* script_state, 350 IDBRequest* IDBObjectStore::put(ScriptState* script_state,
342 WebIDBPutMode put_mode, 351 WebIDBPutMode put_mode,
343 IDBAny* source, 352 IDBAny* source,
344 const ScriptValue& value, 353 const ScriptValue& value,
345 const ScriptValue& key_value, 354 const ScriptValue& key_value,
346 ExceptionState& exception_state) { 355 ExceptionState& exception_state) {
347 IDBKey* key = key_value.IsUndefined() 356 IDBKey* key = key_value.IsUndefined()
348 ? nullptr 357 ? nullptr
349 : ScriptValue::To<IDBKey*>(script_state->GetIsolate(), 358 : ScriptValue::To<IDBKey*>(script_state->GetIsolate(),
350 key_value, exception_state); 359 key_value, exception_state);
351 if (exception_state.HadException()) 360 if (exception_state.HadException())
352 return nullptr; 361 return nullptr;
353 return put(script_state, put_mode, source, value, key, exception_state); 362 return put(script_state, put_mode, source, value, key, exception_state);
354 } 363 }
355 364
356 IDBRequest* IDBObjectStore::put(ScriptState* script_state, 365 IDBRequest* IDBObjectStore::put(ScriptState* script_state,
357 WebIDBPutMode put_mode, 366 WebIDBPutMode put_mode,
358 IDBAny* source, 367 IDBAny* source,
359 const ScriptValue& value, 368 const ScriptValue& value,
360 IDBKey* key, 369 IDBKey* key,
361 ExceptionState& exception_state) { 370 ExceptionState& exception_state) {
371 const char* tracing_name = nullptr;
372 switch (put_mode) {
373 case kWebIDBPutModeAddOrUpdate:
374 tracing_name = "IDBObjectStore::put";
375 break;
376 case kWebIDBPutModeAddOnly:
377 tracing_name = "IDBObjectStore::add";
378 break;
379 case kWebIDBPutModeCursorUpdate:
380 tracing_name = "IDBCursor::update";
381 break;
382 }
383 IDBRequest::AsyncTraceState metrics(tracing_name, this);
362 if (IsDeleted()) { 384 if (IsDeleted()) {
363 exception_state.ThrowDOMException( 385 exception_state.ThrowDOMException(
364 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage); 386 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage);
365 return nullptr; 387 return nullptr;
366 } 388 }
367 if (!transaction_->IsActive()) { 389 if (!transaction_->IsActive()) {
368 exception_state.ThrowDOMException(kTransactionInactiveError, 390 exception_state.ThrowDOMException(kTransactionInactiveError,
369 transaction_->InactiveErrorMessage()); 391 transaction_->InactiveErrorMessage());
370 return nullptr; 392 return nullptr;
371 } 393 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 for (const auto& it : Metadata().indexes) { 510 for (const auto& it : Metadata().indexes) {
489 if (clone.IsEmpty()) 511 if (clone.IsEmpty())
490 value_wrapper.Clone(script_state, &clone); 512 value_wrapper.Clone(script_state, &clone);
491 IndexKeys keys; 513 IndexKeys keys;
492 GenerateIndexKeysForValue(script_state->GetIsolate(), *it.value, clone, 514 GenerateIndexKeysForValue(script_state->GetIsolate(), *it.value, clone,
493 &keys); 515 &keys);
494 index_ids.push_back(it.key); 516 index_ids.push_back(it.key);
495 index_keys.push_back(keys); 517 index_keys.push_back(keys);
496 } 518 }
497 519
498 IDBRequest* request = 520 IDBRequest* request = IDBRequest::Create(
499 IDBRequest::Create(script_state, source, transaction_.Get()); 521 script_state, source, transaction_.Get(), std::move(metrics));
500 522
501 value_wrapper.ExtractBlobDataHandles(request->transit_blob_handles()); 523 value_wrapper.ExtractBlobDataHandles(request->transit_blob_handles());
502 value_wrapper.WrapIfBiggerThan(IDBValueWrapper::kWrapThreshold); 524 value_wrapper.WrapIfBiggerThan(IDBValueWrapper::kWrapThreshold);
503 525
504 BackendDB()->Put( 526 BackendDB()->Put(
505 transaction_->Id(), Id(), WebData(value_wrapper.ExtractWireBytes()), 527 transaction_->Id(), Id(), WebData(value_wrapper.ExtractWireBytes()),
506 value_wrapper.WrappedBlobInfo(), key, 528 value_wrapper.WrappedBlobInfo(), key,
507 static_cast<WebIDBPutMode>(put_mode), 529 static_cast<WebIDBPutMode>(put_mode),
508 request->CreateWebCallbacks().release(), index_ids, index_keys); 530 request->CreateWebCallbacks().release(), index_ids, index_keys);
509 531
510 return request; 532 return request;
511 } 533 }
512 534
513 IDBRequest* IDBObjectStore::deleteFunction(ScriptState* script_state, 535 IDBRequest* IDBObjectStore::deleteFunction(ScriptState* script_state,
514 const ScriptValue& key, 536 const ScriptValue& key,
515 ExceptionState& exception_state) { 537 ExceptionState& exception_state) {
516 IDB_TRACE("IDBObjectStore::delete"); 538 IDB_TRACE("IDBObjectStore::deleteRequestSetup");
539 IDBRequest::AsyncTraceState metrics("IDBObjectStore::delete", this);
517 if (IsDeleted()) { 540 if (IsDeleted()) {
518 exception_state.ThrowDOMException( 541 exception_state.ThrowDOMException(
519 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage); 542 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage);
520 return nullptr; 543 return nullptr;
521 } 544 }
522 if (!transaction_->IsActive()) { 545 if (!transaction_->IsActive()) {
523 exception_state.ThrowDOMException(kTransactionInactiveError, 546 exception_state.ThrowDOMException(kTransactionInactiveError,
524 transaction_->InactiveErrorMessage()); 547 transaction_->InactiveErrorMessage());
525 return nullptr; 548 return nullptr;
526 } 549 }
(...skipping 11 matching lines...) Expand all
538 exception_state.ThrowDOMException( 561 exception_state.ThrowDOMException(
539 kDataError, IDBDatabase::kNoKeyOrKeyRangeErrorMessage); 562 kDataError, IDBDatabase::kNoKeyOrKeyRangeErrorMessage);
540 return nullptr; 563 return nullptr;
541 } 564 }
542 if (!BackendDB()) { 565 if (!BackendDB()) {
543 exception_state.ThrowDOMException(kInvalidStateError, 566 exception_state.ThrowDOMException(kInvalidStateError,
544 IDBDatabase::kDatabaseClosedErrorMessage); 567 IDBDatabase::kDatabaseClosedErrorMessage);
545 return nullptr; 568 return nullptr;
546 } 569 }
547 570
548 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 571 IDBRequest* request =
549 transaction_.Get()); 572 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(),
573 std::move(metrics));
550 BackendDB()->DeleteRange(transaction_->Id(), Id(), key_range, 574 BackendDB()->DeleteRange(transaction_->Id(), Id(), key_range,
551 request->CreateWebCallbacks().release()); 575 request->CreateWebCallbacks().release());
552 return request; 576 return request;
553 } 577 }
554 578
555 IDBRequest* IDBObjectStore::clear(ScriptState* script_state, 579 IDBRequest* IDBObjectStore::clear(ScriptState* script_state,
556 ExceptionState& exception_state) { 580 ExceptionState& exception_state) {
557 IDB_TRACE("IDBObjectStore::clear"); 581 IDB_TRACE("IDBObjectStore::clearRequestSetup");
582 IDBRequest::AsyncTraceState metrics("IDBObjectStore::clear", this);
558 if (IsDeleted()) { 583 if (IsDeleted()) {
559 exception_state.ThrowDOMException( 584 exception_state.ThrowDOMException(
560 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage); 585 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage);
561 return nullptr; 586 return nullptr;
562 } 587 }
563 if (!transaction_->IsActive()) { 588 if (!transaction_->IsActive()) {
564 exception_state.ThrowDOMException(kTransactionInactiveError, 589 exception_state.ThrowDOMException(kTransactionInactiveError,
565 transaction_->InactiveErrorMessage()); 590 transaction_->InactiveErrorMessage());
566 return nullptr; 591 return nullptr;
567 } 592 }
568 if (transaction_->IsReadOnly()) { 593 if (transaction_->IsReadOnly()) {
569 exception_state.ThrowDOMException( 594 exception_state.ThrowDOMException(
570 kReadOnlyError, IDBDatabase::kTransactionReadOnlyErrorMessage); 595 kReadOnlyError, IDBDatabase::kTransactionReadOnlyErrorMessage);
571 return nullptr; 596 return nullptr;
572 } 597 }
573 if (!BackendDB()) { 598 if (!BackendDB()) {
574 exception_state.ThrowDOMException(kInvalidStateError, 599 exception_state.ThrowDOMException(kInvalidStateError,
575 IDBDatabase::kDatabaseClosedErrorMessage); 600 IDBDatabase::kDatabaseClosedErrorMessage);
576 return nullptr; 601 return nullptr;
577 } 602 }
578 603
579 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 604 IDBRequest* request =
580 transaction_.Get()); 605 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(),
606 std::move(metrics));
581 BackendDB()->Clear(transaction_->Id(), Id(), 607 BackendDB()->Clear(transaction_->Id(), Id(),
582 request->CreateWebCallbacks().release()); 608 request->CreateWebCallbacks().release());
583 return request; 609 return request;
584 } 610 }
585 611
586 namespace { 612 namespace {
587 // This class creates the index keys for a given index by extracting 613 // This class creates the index keys for a given index by extracting
588 // them from the SerializedScriptValue, for all the existing values in 614 // them from the SerializedScriptValue, for all the existing values in
589 // the object store. It only needs to be kept alive by virtue of being 615 // the object store. It only needs to be kept alive by virtue of being
590 // a listener on an IDBRequest object, in the same way that JavaScript 616 // a listener on an IDBRequest object, in the same way that JavaScript
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 object_store_id_(object_store_id), 648 object_store_id_(object_store_id),
623 index_metadata_(std::move(index_metadata)) { 649 index_metadata_(std::move(index_metadata)) {
624 DCHECK(index_metadata_.Get()); 650 DCHECK(index_metadata_.Get());
625 } 651 }
626 652
627 const IDBIndexMetadata& IndexMetadata() const { return *index_metadata_; } 653 const IDBIndexMetadata& IndexMetadata() const { return *index_metadata_; }
628 654
629 void handleEvent(ExecutionContext* execution_context, Event* event) override { 655 void handleEvent(ExecutionContext* execution_context, Event* event) override {
630 if (!script_state_->ContextIsValid()) 656 if (!script_state_->ContextIsValid())
631 return; 657 return;
658 IDB_TRACE("IDBObjectStore::IndexPopulator::handleEvent");
632 659
633 DCHECK_EQ(ExecutionContext::From(script_state_.Get()), execution_context); 660 DCHECK_EQ(ExecutionContext::From(script_state_.Get()), execution_context);
634 DCHECK_EQ(event->type(), EventTypeNames::success); 661 DCHECK_EQ(event->type(), EventTypeNames::success);
635 EventTarget* target = event->target(); 662 EventTarget* target = event->target();
636 IDBRequest* request = static_cast<IDBRequest*>(target); 663 IDBRequest* request = static_cast<IDBRequest*>(target);
637 664
638 if (!database_->Backend()) // If database is stopped? 665 if (!database_->Backend()) // If database is stopped?
639 return; 666 return;
640 667
641 ScriptState::Scope scope(script_state_.Get()); 668 ScriptState::Scope scope(script_state_.Get());
642 669
643 IDBAny* cursor_any = request->ResultAsAny(); 670 IDBAny* cursor_any = request->ResultAsAny();
644 IDBCursorWithValue* cursor = nullptr; 671 IDBCursorWithValue* cursor = nullptr;
645 if (cursor_any->GetType() == IDBAny::kIDBCursorWithValueType) 672 if (cursor_any->GetType() == IDBAny::kIDBCursorWithValueType)
646 cursor = cursor_any->IdbCursorWithValue(); 673 cursor = cursor_any->IdbCursorWithValue();
647 674
648 Vector<int64_t> index_ids; 675 Vector<int64_t> index_ids;
649 index_ids.push_back(IndexMetadata().id); 676 index_ids.push_back(IndexMetadata().id);
650 if (cursor && !cursor->IsDeleted()) { 677 if (cursor && !cursor->IsDeleted()) {
651 cursor->Continue(nullptr, nullptr, ASSERT_NO_EXCEPTION); 678 cursor->Continue(nullptr, nullptr,
679 IDBRequest::AsyncTraceState("IDBCursor::continue", this),
680 ASSERT_NO_EXCEPTION);
652 681
653 IDBKey* primary_key = cursor->IdbPrimaryKey(); 682 IDBKey* primary_key = cursor->IdbPrimaryKey();
654 ScriptValue value = cursor->value(script_state_.Get()); 683 ScriptValue value = cursor->value(script_state_.Get());
655 684
656 IndexKeys index_keys; 685 IndexKeys index_keys;
657 GenerateIndexKeysForValue(script_state_->GetIsolate(), IndexMetadata(), 686 GenerateIndexKeysForValue(script_state_->GetIsolate(), IndexMetadata(),
658 value, &index_keys); 687 value, &index_keys);
659 688
660 HeapVector<IndexKeys> index_keys_list; 689 HeapVector<IndexKeys> index_keys_list;
661 index_keys_list.push_back(index_keys); 690 index_keys_list.push_back(index_keys);
(...skipping 16 matching lines...) Expand all
678 const int64_t object_store_id_; 707 const int64_t object_store_id_;
679 RefPtr<const IDBIndexMetadata> index_metadata_; 708 RefPtr<const IDBIndexMetadata> index_metadata_;
680 }; 709 };
681 } // namespace 710 } // namespace
682 711
683 IDBIndex* IDBObjectStore::createIndex(ScriptState* script_state, 712 IDBIndex* IDBObjectStore::createIndex(ScriptState* script_state,
684 const String& name, 713 const String& name,
685 const IDBKeyPath& key_path, 714 const IDBKeyPath& key_path,
686 const IDBIndexParameters& options, 715 const IDBIndexParameters& options,
687 ExceptionState& exception_state) { 716 ExceptionState& exception_state) {
688 IDB_TRACE("IDBObjectStore::createIndex"); 717 IDB_TRACE("IDBObjectStore::createIndexRequestSetup");
718 IDBRequest::AsyncTraceState metrics("IDBObjectStore::createIndex", this);
689 if (!transaction_->IsVersionChange()) { 719 if (!transaction_->IsVersionChange()) {
690 exception_state.ThrowDOMException( 720 exception_state.ThrowDOMException(
691 kInvalidStateError, 721 kInvalidStateError,
692 IDBDatabase::kNotVersionChangeTransactionErrorMessage); 722 IDBDatabase::kNotVersionChangeTransactionErrorMessage);
693 return nullptr; 723 return nullptr;
694 } 724 }
695 if (IsDeleted()) { 725 if (IsDeleted()) {
696 exception_state.ThrowDOMException( 726 exception_state.ThrowDOMException(
697 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage); 727 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage);
698 return nullptr; 728 return nullptr;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 IDBIndex* index = IDBIndex::Create(index_metadata, this, transaction_.Get()); 766 IDBIndex* index = IDBIndex::Create(index_metadata, this, transaction_.Get());
737 index_map_.Set(name, index); 767 index_map_.Set(name, index);
738 metadata_->indexes.Set(index_id, index_metadata); 768 metadata_->indexes.Set(index_id, index_metadata);
739 769
740 DCHECK(!exception_state.HadException()); 770 DCHECK(!exception_state.HadException());
741 if (exception_state.HadException()) 771 if (exception_state.HadException())
742 return nullptr; 772 return nullptr;
743 773
744 IDBRequest* index_request = 774 IDBRequest* index_request =
745 openCursor(script_state, nullptr, kWebIDBCursorDirectionNext, 775 openCursor(script_state, nullptr, kWebIDBCursorDirectionNext,
746 kWebIDBTaskTypePreemptive); 776 kWebIDBTaskTypePreemptive, std::move(metrics));
747 index_request->PreventPropagation(); 777 index_request->PreventPropagation();
748 778
749 // This is kept alive by being the success handler of the request, which is in 779 // This is kept alive by being the success handler of the request, which is in
750 // turn kept alive by the owning transaction. 780 // turn kept alive by the owning transaction.
751 IndexPopulator* index_populator = IndexPopulator::Create( 781 IndexPopulator* index_populator = IndexPopulator::Create(
752 script_state, transaction()->db(), transaction_->Id(), Id(), 782 script_state, transaction()->db(), transaction_->Id(), Id(),
753 std::move(index_metadata)); 783 std::move(index_metadata));
754 index_request->setOnsuccess(index_populator); 784 index_request->setOnsuccess(index_populator);
755 return index; 785 return index;
756 } 786 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 transaction_->IndexDeleted(it->value); 858 transaction_->IndexDeleted(it->value);
829 it->value->MarkDeleted(); 859 it->value->MarkDeleted();
830 index_map_.erase(name); 860 index_map_.erase(name);
831 } 861 }
832 } 862 }
833 863
834 IDBRequest* IDBObjectStore::openCursor(ScriptState* script_state, 864 IDBRequest* IDBObjectStore::openCursor(ScriptState* script_state,
835 const ScriptValue& range, 865 const ScriptValue& range,
836 const String& direction_string, 866 const String& direction_string,
837 ExceptionState& exception_state) { 867 ExceptionState& exception_state) {
838 IDB_TRACE("IDBObjectStore::openCursor"); 868 IDB_TRACE("IDBObjectStore::openCursorRequestSetup");
869 IDBRequest::AsyncTraceState metrics("IDBObjectStore::openCursor", this);
839 if (IsDeleted()) { 870 if (IsDeleted()) {
840 exception_state.ThrowDOMException( 871 exception_state.ThrowDOMException(
841 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage); 872 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage);
842 return nullptr; 873 return nullptr;
843 } 874 }
844 if (!transaction_->IsActive()) { 875 if (!transaction_->IsActive()) {
845 exception_state.ThrowDOMException(kTransactionInactiveError, 876 exception_state.ThrowDOMException(kTransactionInactiveError,
846 transaction_->InactiveErrorMessage()); 877 transaction_->InactiveErrorMessage());
847 return nullptr; 878 return nullptr;
848 } 879 }
849 880
850 WebIDBCursorDirection direction = 881 WebIDBCursorDirection direction =
851 IDBCursor::StringToDirection(direction_string); 882 IDBCursor::StringToDirection(direction_string);
852 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( 883 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue(
853 ExecutionContext::From(script_state), range, exception_state); 884 ExecutionContext::From(script_state), range, exception_state);
854 if (exception_state.HadException()) 885 if (exception_state.HadException())
855 return nullptr; 886 return nullptr;
856 887
857 if (!BackendDB()) { 888 if (!BackendDB()) {
858 exception_state.ThrowDOMException(kInvalidStateError, 889 exception_state.ThrowDOMException(kInvalidStateError,
859 IDBDatabase::kDatabaseClosedErrorMessage); 890 IDBDatabase::kDatabaseClosedErrorMessage);
860 return nullptr; 891 return nullptr;
861 } 892 }
862 893
863 return openCursor(script_state, key_range, direction, kWebIDBTaskTypeNormal); 894 return openCursor(script_state, key_range, direction, kWebIDBTaskTypeNormal,
895 std::move(metrics));
864 } 896 }
865 897
866 IDBRequest* IDBObjectStore::openCursor(ScriptState* script_state, 898 IDBRequest* IDBObjectStore::openCursor(ScriptState* script_state,
867 IDBKeyRange* range, 899 IDBKeyRange* range,
868 WebIDBCursorDirection direction, 900 WebIDBCursorDirection direction,
869 WebIDBTaskType task_type) { 901 WebIDBTaskType task_type,
870 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 902 IDBRequest::AsyncTraceState metrics) {
871 transaction_.Get()); 903 IDBRequest* request =
904 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(),
905 std::move(metrics));
872 request->SetCursorDetails(IndexedDB::kCursorKeyAndValue, direction); 906 request->SetCursorDetails(IndexedDB::kCursorKeyAndValue, direction);
873 907
874 BackendDB()->OpenCursor(transaction_->Id(), Id(), 908 BackendDB()->OpenCursor(transaction_->Id(), Id(),
875 IDBIndexMetadata::kInvalidId, range, direction, false, 909 IDBIndexMetadata::kInvalidId, range, direction, false,
876 task_type, request->CreateWebCallbacks().release()); 910 task_type, request->CreateWebCallbacks().release());
877 return request; 911 return request;
878 } 912 }
879 913
880 IDBRequest* IDBObjectStore::openKeyCursor(ScriptState* script_state, 914 IDBRequest* IDBObjectStore::openKeyCursor(ScriptState* script_state,
881 const ScriptValue& range, 915 const ScriptValue& range,
882 const String& direction_string, 916 const String& direction_string,
883 ExceptionState& exception_state) { 917 ExceptionState& exception_state) {
884 IDB_TRACE("IDBObjectStore::openKeyCursor"); 918 IDB_TRACE("IDBObjectStore::openKeyCursorRequestSetup");
919 IDBRequest::AsyncTraceState metrics("IDBObjectStore::openKeyCursor", this);
885 if (IsDeleted()) { 920 if (IsDeleted()) {
886 exception_state.ThrowDOMException( 921 exception_state.ThrowDOMException(
887 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage); 922 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage);
888 return nullptr; 923 return nullptr;
889 } 924 }
890 if (!transaction_->IsActive()) { 925 if (!transaction_->IsActive()) {
891 exception_state.ThrowDOMException(kTransactionInactiveError, 926 exception_state.ThrowDOMException(kTransactionInactiveError,
892 transaction_->InactiveErrorMessage()); 927 transaction_->InactiveErrorMessage());
893 return nullptr; 928 return nullptr;
894 } 929 }
895 930
896 WebIDBCursorDirection direction = 931 WebIDBCursorDirection direction =
897 IDBCursor::StringToDirection(direction_string); 932 IDBCursor::StringToDirection(direction_string);
898 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( 933 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue(
899 ExecutionContext::From(script_state), range, exception_state); 934 ExecutionContext::From(script_state), range, exception_state);
900 if (exception_state.HadException()) 935 if (exception_state.HadException())
901 return nullptr; 936 return nullptr;
902 937
903 if (!BackendDB()) { 938 if (!BackendDB()) {
904 exception_state.ThrowDOMException(kInvalidStateError, 939 exception_state.ThrowDOMException(kInvalidStateError,
905 IDBDatabase::kDatabaseClosedErrorMessage); 940 IDBDatabase::kDatabaseClosedErrorMessage);
906 return nullptr; 941 return nullptr;
907 } 942 }
908 943
909 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 944 IDBRequest* request =
910 transaction_.Get()); 945 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(),
946 std::move(metrics));
911 request->SetCursorDetails(IndexedDB::kCursorKeyOnly, direction); 947 request->SetCursorDetails(IndexedDB::kCursorKeyOnly, direction);
912 948
913 BackendDB()->OpenCursor(transaction_->Id(), Id(), 949 BackendDB()->OpenCursor(transaction_->Id(), Id(),
914 IDBIndexMetadata::kInvalidId, key_range, direction, 950 IDBIndexMetadata::kInvalidId, key_range, direction,
915 true, kWebIDBTaskTypeNormal, 951 true, kWebIDBTaskTypeNormal,
916 request->CreateWebCallbacks().release()); 952 request->CreateWebCallbacks().release());
917 return request; 953 return request;
918 } 954 }
919 955
920 IDBRequest* IDBObjectStore::count(ScriptState* script_state, 956 IDBRequest* IDBObjectStore::count(ScriptState* script_state,
921 const ScriptValue& range, 957 const ScriptValue& range,
922 ExceptionState& exception_state) { 958 ExceptionState& exception_state) {
923 IDB_TRACE("IDBObjectStore::count"); 959 IDB_TRACE("IDBObjectStore::countRequestSetup");
960 IDBRequest::AsyncTraceState metrics("IDBObjectStore::count", this);
924 if (IsDeleted()) { 961 if (IsDeleted()) {
925 exception_state.ThrowDOMException( 962 exception_state.ThrowDOMException(
926 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage); 963 kInvalidStateError, IDBDatabase::kObjectStoreDeletedErrorMessage);
927 return nullptr; 964 return nullptr;
928 } 965 }
929 if (!transaction_->IsActive()) { 966 if (!transaction_->IsActive()) {
930 exception_state.ThrowDOMException(kTransactionInactiveError, 967 exception_state.ThrowDOMException(kTransactionInactiveError,
931 transaction_->InactiveErrorMessage()); 968 transaction_->InactiveErrorMessage());
932 return nullptr; 969 return nullptr;
933 } 970 }
934 971
935 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( 972 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue(
936 ExecutionContext::From(script_state), range, exception_state); 973 ExecutionContext::From(script_state), range, exception_state);
937 if (exception_state.HadException()) 974 if (exception_state.HadException())
938 return nullptr; 975 return nullptr;
939 976
940 if (!BackendDB()) { 977 if (!BackendDB()) {
941 exception_state.ThrowDOMException(kInvalidStateError, 978 exception_state.ThrowDOMException(kInvalidStateError,
942 IDBDatabase::kDatabaseClosedErrorMessage); 979 IDBDatabase::kDatabaseClosedErrorMessage);
943 return nullptr; 980 return nullptr;
944 } 981 }
945 982
946 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 983 IDBRequest* request =
947 transaction_.Get()); 984 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(),
985 std::move(metrics));
948 BackendDB()->Count(transaction_->Id(), Id(), IDBIndexMetadata::kInvalidId, 986 BackendDB()->Count(transaction_->Id(), Id(), IDBIndexMetadata::kInvalidId,
949 key_range, request->CreateWebCallbacks().release()); 987 key_range, request->CreateWebCallbacks().release());
950 return request; 988 return request;
951 } 989 }
952 990
953 void IDBObjectStore::MarkDeleted() { 991 void IDBObjectStore::MarkDeleted() {
954 DCHECK(transaction_->IsVersionChange()) 992 DCHECK(transaction_->IsVersionChange())
955 << "An object store got deleted outside a versionchange transaction."; 993 << "An object store got deleted outside a versionchange transaction.";
956 994
957 deleted_ = true; 995 deleted_ = true;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 } 1087 }
1050 } 1088 }
1051 return IDBIndexMetadata::kInvalidId; 1089 return IDBIndexMetadata::kInvalidId;
1052 } 1090 }
1053 1091
1054 WebIDBDatabase* IDBObjectStore::BackendDB() const { 1092 WebIDBDatabase* IDBObjectStore::BackendDB() const {
1055 return transaction_->BackendDB(); 1093 return transaction_->BackendDB();
1056 } 1094 }
1057 1095
1058 } // namespace blink 1096 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698