Changeset 141431 in webkit
- Timestamp:
- Jan 31, 2013 10:12:23 AM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r141429 r141431 1 2013-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 1 20 2013-01-31 Grzegorz Czajkowski <g.czajkowski@samsung.com> 2 21 -
trunk/Source/WebCore/Modules/webdatabase/DatabaseContext.cpp
r141166 r141431 40 40 #include "Page.h" 41 41 #include "SchemeRegistry.h" 42 #include "ScriptExecutionContext.h" 42 43 #include "SecurityOrigin.h" 43 44 #include "Settings.h" 44 45 45 46 namespace 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 46 98 47 99 DatabaseContext::DatabaseContext(ScriptExecutionContext* context) … … 53 105 // ActiveDOMObject expects this to be called to set internal flags. 54 106 suspendIfNeeded(); 107 108 context->setDatabaseContext(this); 55 109 56 110 // For debug accounting only. We must do this before we register the -
trunk/Source/WebCore/dom/ScriptExecutionContext.cpp
r137318 r141431 54 54 #endif 55 55 56 #if ENABLE(SQL_DATABASE) 57 #include "DatabaseContext.h" 58 #endif 59 56 60 namespace WTF { 57 61 … … 443 447 #endif 444 448 449 #if ENABLE(SQL_DATABASE) 450 void ScriptExecutionContext::setDatabaseContext(DatabaseContext* databaseContext) 451 { 452 ASSERT(!m_databaseContext); 453 m_databaseContext = databaseContext; 454 } 455 #endif 456 445 457 } // namespace WebCore -
trunk/Source/WebCore/dom/ScriptExecutionContext.h
r141418 r141431 52 52 53 53 class CachedScript; 54 class DatabaseContext; 54 55 class DOMTimer; 55 56 class EventListener; … … 171 172 172 173 virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE; 174 175 #if ENABLE(SQL_DATABASE) 176 void setDatabaseContext(DatabaseContext*); 177 #endif 173 178 174 179 protected: … … 228 233 RefPtr<FileThread> m_fileThread; 229 234 #endif 235 236 #if ENABLE(SQL_DATABASE) 237 RefPtr<DatabaseContext> m_databaseContext; 238 #endif 230 239 }; 231 240
Note: See TracChangeset
for help on using the changeset viewer.