Changeset 158058 in webkit
- Timestamp:
- Oct 25, 2013 3:03:40 PM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r158050 r158058 1 2013-10-25 Mark Lam <mark.lam@apple.com> 2 3 DatabaseManager's ProposedDatabases need to be thread-safe. 4 https://bugs.webkit.org/show_bug.cgi?id=123313. 5 6 Reviewed by Geoffrey Garen. 7 8 No new tests. 9 10 * Modules/webdatabase/DatabaseManager.cpp: 11 (WebCore::DatabaseManager::DatabaseManager): 12 (WebCore::DatabaseManager::existingDatabaseContextFor): 13 (WebCore::DatabaseManager::registerDatabaseContext): 14 (WebCore::DatabaseManager::unregisterDatabaseContext): 15 (WebCore::DatabaseManager::didConstructDatabaseContext): 16 (WebCore::DatabaseManager::didDestructDatabaseContext): 17 (WebCore::DatabaseManager::openDatabaseBackend): 18 (WebCore::DatabaseManager::addProposedDatabase): 19 (WebCore::DatabaseManager::removeProposedDatabase): 20 (WebCore::DatabaseManager::fullPathForDatabase): 21 (WebCore::DatabaseManager::detailsForNameAndOrigin): 22 * Modules/webdatabase/DatabaseManager.h: 23 1 24 2013-10-25 Joseph Pecoraro <pecoraro@apple.com> 2 25 -
trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.cpp
r157885 r158058 56 56 , m_details(name.isolatedCopy(), displayName.isolatedCopy(), estimatedSize, 0) 57 57 { 58 ASSERT(!m_manager.m_proposedDatabase); 59 m_manager.m_proposedDatabase = this; 58 m_manager.addProposedDatabase(this); 60 59 } 61 60 62 61 DatabaseManager::ProposedDatabase::~ProposedDatabase() 63 62 { 64 m_manager. m_proposedDatabase = 0;63 m_manager.removeProposedDatabase(this); 65 64 } 66 65 … … 84 83 , m_databaseContextInstanceCount(0) 85 84 #endif 86 , m_proposedDatabase(0)87 85 { 88 86 ASSERT(m_server); // We should always have a server to work with. … … 145 143 PassRefPtr<DatabaseContext> DatabaseManager::existingDatabaseContextFor(ScriptExecutionContext* context) 146 144 { 147 MutexLocker locker(m_ contextMapLock);145 MutexLocker locker(m_lock); 148 146 149 147 ASSERT(m_databaseContextRegisteredCount >= 0); … … 176 174 void DatabaseManager::registerDatabaseContext(DatabaseContext* databaseContext) 177 175 { 178 MutexLocker locker(m_ contextMapLock);176 MutexLocker locker(m_lock); 179 177 ScriptExecutionContext* context = databaseContext->scriptExecutionContext(); 180 178 m_contextMap.set(context, databaseContext); … … 186 184 void DatabaseManager::unregisterDatabaseContext(DatabaseContext* databaseContext) 187 185 { 188 MutexLocker locker(m_ contextMapLock);186 MutexLocker locker(m_lock); 189 187 ScriptExecutionContext* context = databaseContext->scriptExecutionContext(); 190 188 ASSERT(m_contextMap.get(context)); … … 198 196 void DatabaseManager::didConstructDatabaseContext() 199 197 { 200 MutexLocker lock(m_ contextMapLock);198 MutexLocker lock(m_lock); 201 199 m_databaseContextInstanceCount++; 202 200 } … … 204 202 void DatabaseManager::didDestructDatabaseContext() 205 203 { 206 MutexLocker lock(m_ contextMapLock);204 MutexLocker lock(m_lock); 207 205 m_databaseContextInstanceCount--; 208 206 ASSERT(m_databaseContextRegisteredCount <= m_databaseContextInstanceCount); … … 297 295 } 298 296 297 void DatabaseManager::addProposedDatabase(ProposedDatabase* proposedDb) 298 { 299 MutexLocker locker(m_lock); 300 m_proposedDatabases.add(proposedDb); 301 } 302 303 void DatabaseManager::removeProposedDatabase(ProposedDatabase* proposedDb) 304 { 305 MutexLocker locker(m_lock); 306 m_proposedDatabases.remove(proposedDb); 307 } 308 299 309 PassRefPtr<Database> DatabaseManager::openDatabase(ScriptExecutionContext* context, 300 310 const String& name, const String& expectedVersion, const String& displayName, … … 370 380 String DatabaseManager::fullPathForDatabase(SecurityOrigin* origin, const String& name, bool createIfDoesNotExist) 371 381 { 372 ProposedDatabase* db = m_proposedDatabase; 373 if (db && db->details().name() == name && db->origin()->equal(origin)) 374 return String(); 382 { 383 MutexLocker locker(m_lock); 384 for (HashSet<ProposedDatabase*>::iterator iter = m_proposedDatabases.begin(); iter != m_proposedDatabases.end(); ++iter) 385 if ((*iter)->details().name() == name && (*iter)->origin()->equal(origin)) 386 return String(); 387 } 375 388 return m_server->fullPathForDatabase(origin, name, createIfDoesNotExist); 376 389 } … … 393 406 DatabaseDetails DatabaseManager::detailsForNameAndOrigin(const String& name, SecurityOrigin* origin) 394 407 { 395 ProposedDatabase* db = m_proposedDatabase; 396 if (db && db->details().name() == name && db->origin()->equal(origin)) { 397 ASSERT(db->details().thread() == currentThread() || isMainThread()); 398 return db->details(); 408 { 409 MutexLocker locker(m_lock); 410 for (HashSet<ProposedDatabase*>::iterator iter = m_proposedDatabases.begin(); iter != m_proposedDatabases.end(); ++iter) 411 if ((*iter)->details().name() == name && (*iter)->origin()->equal(origin)) { 412 ASSERT((*iter)->details().thread() == currentThread() || isMainThread()); 413 return (*iter)->details(); 414 } 399 415 } 400 416 return m_server->detailsForNameAndOrigin(name, origin); -
trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.h
r157874 r158058 34 34 #include <wtf/Assertions.h> 35 35 #include <wtf/HashMap.h> 36 #include <wtf/HashSet.h> 36 37 #include <wtf/PassRefPtr.h> 37 38 #include <wtf/Threading.h> … … 133 134 unsigned long estimatedSize, bool setVersionInNewDatabase, DatabaseError&, String& errorMessage); 134 135 136 void addProposedDatabase(ProposedDatabase*); 137 void removeProposedDatabase(ProposedDatabase*); 138 135 139 static void logErrorMessage(ScriptExecutionContext*, const String& message); 136 140 … … 139 143 bool m_databaseIsAvailable; 140 144 141 // Access to the following fields require locking m_ contextMapLock:145 // Access to the following fields require locking m_lock below: 142 146 typedef HashMap<ScriptExecutionContext*, DatabaseContext*> ContextMap; 143 147 ContextMap m_contextMap; … … 146 150 int m_databaseContextInstanceCount; 147 151 #endif 148 Mutex m_contextMapLock;152 HashSet<ProposedDatabase*> m_proposedDatabases; 149 153 150 ProposedDatabase* m_proposedDatabase; 154 // This lock protects m_contextMap, and m_proposedDatabases. 155 Mutex m_lock; 151 156 }; 152 157
Note: See TracChangeset
for help on using the changeset viewer.