Changeset 141431 in webkit


Ignore:
Timestamp:
Jan 31, 2013 10:12:23 AM (11 years ago)
Author:
mark.lam@apple.com
Message:

DatabaseContext needs to outlive the ScriptExecutionContext.
https://bugs.webkit.org/show_bug.cgi?id=108355.

Reviewed by Geoffrey Garen.

Added a RefPtr<DatabaseContext> in ScriptExecutionContext to keep the
DatabaseContext alive until after ScriptExecutionContext destructs.

No new tests.

  • Modules/webdatabase/DatabaseContext.cpp:

(WebCore::DatabaseContext::DatabaseContext):

  • dom/ScriptExecutionContext.cpp:

(WebCore::ScriptExecutionContext::setDatabaseContext):

  • dom/ScriptExecutionContext.h:

(ScriptExecutionContext):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r141429 r141431  
     12013-01-30  Mark Lam  <mark.lam@apple.com>
     2
     3        DatabaseContext needs to outlive the ScriptExecutionContext.
     4        https://bugs.webkit.org/show_bug.cgi?id=108355.
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Added a RefPtr<DatabaseContext> in ScriptExecutionContext to keep the
     9        DatabaseContext alive until after ScriptExecutionContext destructs.
     10
     11        No new tests.
     12
     13        * Modules/webdatabase/DatabaseContext.cpp:
     14        (WebCore::DatabaseContext::DatabaseContext):
     15        * dom/ScriptExecutionContext.cpp:
     16        (WebCore::ScriptExecutionContext::setDatabaseContext):
     17        * dom/ScriptExecutionContext.h:
     18        (ScriptExecutionContext):
     19
    1202013-01-31  Grzegorz Czajkowski  <g.czajkowski@samsung.com>
    221
  • trunk/Source/WebCore/Modules/webdatabase/DatabaseContext.cpp

    r141166 r141431  
    4040#include "Page.h"
    4141#include "SchemeRegistry.h"
     42#include "ScriptExecutionContext.h"
    4243#include "SecurityOrigin.h"
    4344#include "Settings.h"
    4445
    4546namespace WebCore {
     47
     48// How the DatabaseContext Life-Cycle works?
     49// ========================================
     50// ... in other words, who's keeping the DatabaseContext alive and how long does
     51// it need to stay alive?
     52//
     53// The DatabaseContext is referenced from RefPtrs in:
     54// 1. ScriptExecutionContext
     55// 2. Database
     56//
     57// At Birth:
     58// ========
     59// We create a DatabaseContext only when there is a need i.e. the script tries to
     60// open a Database via DatabaseManager::openDatabase().
     61//
     62// The DatabaseContext constructor will call setDatabaseContext() on the
     63// the ScriptExecutionContext. This sets the RefPtr in the ScriptExecutionContext
     64// for keeping the DatabaseContext alive. Since the DatabaseContext is only
     65// created from the script thread, it is safe for the constructor to call
     66// ScriptExecutionContext::setDatabaseContext().
     67//
     68// Once a DatabaseContext is associated with a ScriptExecutionContext, it will
     69// live until after the ScriptExecutionContext destructs. This is true even if
     70// we don't succeed in opening any Databases for that context. When we do
     71// succeed in opening Databases for this ScriptExecutionContext, the Database
     72// will re-use the same DatabaseContext.
     73//
     74// At Shutdown:
     75// ===========
     76// During shutdown, the DatabaseContext needs to:
     77// 1. "outlive" the ScriptExecutionContext.
     78//    - This is needed because the DatabaseContext needs to remove itself from the
     79//      ScriptExecutionContext's ActiveDOMObject list and ContextDestructionObserver
     80//      list. This removal needs to be executed on the script's thread. Hence, we
     81//      rely on the ScriptExecutionContext's shutdown process to call
     82//      stop() and contextDestroyed() to give us a chance to clean these up from
     83//      the script thread.
     84//
     85// 2. "outlive" the Databases.
     86//    - This is because they may make use of the DatabaseContext to execute a close
     87//      task and shutdown in an orderly manner. When the Databases are destructed,
     88//      they will deref the DatabaseContext from the DatabaseThread.
     89//
     90// During shutdown, the ScriptExecutionContext is shutting down on the script thread
     91// while the Databases are shutting down on the DatabaseThread. Hence, there can be
     92// a race condition as to whether the ScriptExecutionContext or the Databases
     93// destruct first.
     94//
     95// The RefPtrs in the Databases and ScriptExecutionContext will ensure that the
     96// DatabaseContext will outlive both regardless of which of the 2 destructs first.
     97
    4698
    4799DatabaseContext::DatabaseContext(ScriptExecutionContext* context)
     
    53105    // ActiveDOMObject expects this to be called to set internal flags.
    54106    suspendIfNeeded();
     107
     108    context->setDatabaseContext(this);
    55109
    56110    // For debug accounting only. We must do this before we register the
  • trunk/Source/WebCore/dom/ScriptExecutionContext.cpp

    r137318 r141431  
    5454#endif
    5555
     56#if ENABLE(SQL_DATABASE)
     57#include "DatabaseContext.h"
     58#endif
     59
    5660namespace WTF {
    5761
     
    443447#endif
    444448
     449#if ENABLE(SQL_DATABASE)
     450void ScriptExecutionContext::setDatabaseContext(DatabaseContext* databaseContext)
     451{
     452    ASSERT(!m_databaseContext);
     453    m_databaseContext = databaseContext;
     454}
     455#endif
     456
    445457} // namespace WebCore
  • trunk/Source/WebCore/dom/ScriptExecutionContext.h

    r141418 r141431  
    5252
    5353class CachedScript;
     54class DatabaseContext;
    5455class DOMTimer;
    5556class EventListener;
     
    171172
    172173    virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
     174
     175#if ENABLE(SQL_DATABASE)
     176    void setDatabaseContext(DatabaseContext*);
     177#endif
    173178
    174179protected:
     
    228233    RefPtr<FileThread> m_fileThread;
    229234#endif
     235
     236#if ENABLE(SQL_DATABASE)
     237    RefPtr<DatabaseContext> m_databaseContext;
     238#endif
    230239};
    231240
Note: See TracChangeset for help on using the changeset viewer.