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

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

Issue 2473203002: IndexedDB: Remove m_contextStopped from ActiveDOMObjecs (Closed)
Patch Set: Created 4 years, 1 month 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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 DCHECK(m_transactions.isEmpty()); 390 DCHECK(m_transactions.isEmpty());
391 391
392 if (m_backend) { 392 if (m_backend) {
393 m_backend->close(); 393 m_backend->close();
394 m_backend.reset(); 394 m_backend.reset();
395 } 395 }
396 396
397 if (m_databaseCallbacks) 397 if (m_databaseCallbacks)
398 m_databaseCallbacks->detachWebCallbacks(); 398 m_databaseCallbacks->detachWebCallbacks();
399 399
400 if (m_contextStopped || !getExecutionContext()) 400 if (!getExecutionContext())
401 return; 401 return;
402 402
403 EventQueue* eventQueue = getExecutionContext()->getEventQueue(); 403 EventQueue* eventQueue = getExecutionContext()->getEventQueue();
404 // Remove any pending versionchange events scheduled to fire on this 404 // Remove any pending versionchange events scheduled to fire on this
405 // connection. They would have been scheduled by the backend when another 405 // connection. They would have been scheduled by the backend when another
406 // connection attempted an upgrade, but the frontend connection is being 406 // connection attempted an upgrade, but the frontend connection is being
407 // closed before they could fire. 407 // closed before they could fire.
408 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { 408 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) {
409 bool removed = eventQueue->cancelEvent(m_enqueuedEvents[i].get()); 409 bool removed = eventQueue->cancelEvent(m_enqueuedEvents[i].get());
410 DCHECK(removed); 410 DCHECK(removed);
411 } 411 }
412 } 412 }
413 413
414 void IDBDatabase::onVersionChange(int64_t oldVersion, int64_t newVersion) { 414 void IDBDatabase::onVersionChange(int64_t oldVersion, int64_t newVersion) {
415 IDB_TRACE("IDBDatabase::onVersionChange"); 415 IDB_TRACE("IDBDatabase::onVersionChange");
416 if (m_contextStopped || !getExecutionContext()) 416 if (!getExecutionContext())
417 return; 417 return;
418 418
419 if (m_closePending) { 419 if (m_closePending) {
420 // If we're pending, that means there's a busy transaction. We won't 420 // If we're pending, that means there's a busy transaction. We won't
421 // fire 'versionchange' but since we're not closing immediately the 421 // fire 'versionchange' but since we're not closing immediately the
422 // back-end should still send out 'blocked'. 422 // back-end should still send out 'blocked'.
423 m_backend->versionChangeIgnored(); 423 m_backend->versionChangeIgnored();
424 return; 424 return;
425 } 425 }
426 426
427 Nullable<unsigned long long> newVersionNullable = 427 Nullable<unsigned long long> newVersionNullable =
428 (newVersion == IDBDatabaseMetadata::NoVersion) 428 (newVersion == IDBDatabaseMetadata::NoVersion)
429 ? Nullable<unsigned long long>() 429 ? Nullable<unsigned long long>()
430 : Nullable<unsigned long long>(newVersion); 430 : Nullable<unsigned long long>(newVersion);
431 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::versionchange, 431 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::versionchange,
432 oldVersion, newVersionNullable)); 432 oldVersion, newVersionNullable));
433 } 433 }
434 434
435 void IDBDatabase::enqueueEvent(Event* event) { 435 void IDBDatabase::enqueueEvent(Event* event) {
436 DCHECK(!m_contextStopped);
437 DCHECK(getExecutionContext()); 436 DCHECK(getExecutionContext());
438 EventQueue* eventQueue = getExecutionContext()->getEventQueue(); 437 EventQueue* eventQueue = getExecutionContext()->getEventQueue();
439 event->setTarget(this); 438 event->setTarget(this);
440 eventQueue->enqueueEvent(event); 439 eventQueue->enqueueEvent(event);
441 m_enqueuedEvents.append(event); 440 m_enqueuedEvents.append(event);
442 } 441 }
443 442
444 DispatchEventResult IDBDatabase::dispatchEventInternal(Event* event) { 443 DispatchEventResult IDBDatabase::dispatchEventInternal(Event* event) {
445 IDB_TRACE("IDBDatabase::dispatchEvent"); 444 IDB_TRACE("IDBDatabase::dispatchEvent");
446 if (m_contextStopped || !getExecutionContext()) 445 if (!getExecutionContext())
447 return DispatchEventResult::CanceledBeforeDispatch; 446 return DispatchEventResult::CanceledBeforeDispatch;
448 DCHECK(event->type() == EventTypeNames::versionchange || 447 DCHECK(event->type() == EventTypeNames::versionchange ||
449 event->type() == EventTypeNames::close); 448 event->type() == EventTypeNames::close);
450 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { 449 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) {
451 if (m_enqueuedEvents[i].get() == event) 450 if (m_enqueuedEvents[i].get() == event)
452 m_enqueuedEvents.remove(i); 451 m_enqueuedEvents.remove(i);
453 } 452 }
454 453
455 DispatchEventResult dispatchResult = 454 DispatchEventResult dispatchResult =
456 EventTarget::dispatchEventInternal(event); 455 EventTarget::dispatchEventInternal(event);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 << "Object store metadata reverted when versionchange transaction is " 508 << "Object store metadata reverted when versionchange transaction is "
510 "still active"; 509 "still active";
511 DCHECK(oldMetadata.get()); 510 DCHECK(oldMetadata.get());
512 m_metadata.objectStores.set(oldMetadata->id, std::move(oldMetadata)); 511 m_metadata.objectStores.set(oldMetadata->id, std::move(oldMetadata));
513 } 512 }
514 513
515 bool IDBDatabase::hasPendingActivity() const { 514 bool IDBDatabase::hasPendingActivity() const {
516 // The script wrapper must not be collected before the object is closed or 515 // The script wrapper must not be collected before the object is closed or
517 // we can't fire a "versionchange" event to let script manually close the 516 // we can't fire a "versionchange" event to let script manually close the
518 // connection. 517 // connection.
519 return !m_closePending && hasEventListeners() && !m_contextStopped; 518 return !m_closePending && hasEventListeners() && getExecutionContext();
520 } 519 }
521 520
522 void IDBDatabase::contextDestroyed() { 521 void IDBDatabase::contextDestroyed() {
523 m_contextStopped = true;
524
525 // Immediately close the connection to the back end. Don't attempt a 522 // Immediately close the connection to the back end. Don't attempt a
526 // normal close() since that may wait on transactions which require a 523 // normal close() since that may wait on transactions which require a
527 // round trip to the back-end to abort. 524 // round trip to the back-end to abort.
528 if (m_backend) { 525 if (m_backend) {
529 m_backend->close(); 526 m_backend->close();
530 m_backend.reset(); 527 m_backend.reset();
531 } 528 }
532 529
533 if (m_databaseCallbacks) 530 if (m_databaseCallbacks)
534 m_databaseCallbacks->detachWebCallbacks(); 531 m_databaseCallbacks->detachWebCallbacks();
535 } 532 }
536 533
537 const AtomicString& IDBDatabase::interfaceName() const { 534 const AtomicString& IDBDatabase::interfaceName() const {
538 return EventTargetNames::IDBDatabase; 535 return EventTargetNames::IDBDatabase;
539 } 536 }
540 537
541 ExecutionContext* IDBDatabase::getExecutionContext() const { 538 ExecutionContext* IDBDatabase::getExecutionContext() const {
542 return ActiveDOMObject::getExecutionContext(); 539 return ActiveDOMObject::getExecutionContext();
543 } 540 }
544 541
545 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method) { 542 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method) {
546 DEFINE_THREAD_SAFE_STATIC_LOCAL( 543 DEFINE_THREAD_SAFE_STATIC_LOCAL(
547 EnumerationHistogram, apiCallsHistogram, 544 EnumerationHistogram, apiCallsHistogram,
548 new EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls", 545 new EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls",
549 IDBMethodsMax)); 546 IDBMethodsMax));
550 apiCallsHistogram.count(method); 547 apiCallsHistogram.count(method);
551 } 548 }
552 549
553 } // namespace blink 550 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698