Changeset 158058 in webkit


Ignore:
Timestamp:
Oct 25, 2013 3:03:40 PM (10 years ago)
Author:
mark.lam@apple.com
Message:

DatabaseManager's ProposedDatabases need to be thread-safe.
https://bugs.webkit.org/show_bug.cgi?id=123313.

Reviewed by Geoffrey Garen.

No new tests.

  • Modules/webdatabase/DatabaseManager.cpp:

(WebCore::DatabaseManager::DatabaseManager):
(WebCore::DatabaseManager::existingDatabaseContextFor):
(WebCore::DatabaseManager::registerDatabaseContext):
(WebCore::DatabaseManager::unregisterDatabaseContext):
(WebCore::DatabaseManager::didConstructDatabaseContext):
(WebCore::DatabaseManager::didDestructDatabaseContext):
(WebCore::DatabaseManager::openDatabaseBackend):
(WebCore::DatabaseManager::addProposedDatabase):
(WebCore::DatabaseManager::removeProposedDatabase):
(WebCore::DatabaseManager::fullPathForDatabase):
(WebCore::DatabaseManager::detailsForNameAndOrigin):

  • Modules/webdatabase/DatabaseManager.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r158050 r158058  
     12013-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
    1242013-10-25  Joseph Pecoraro  <pecoraro@apple.com>
    225
  • trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.cpp

    r157885 r158058  
    5656    , m_details(name.isolatedCopy(), displayName.isolatedCopy(), estimatedSize, 0)
    5757{
    58     ASSERT(!m_manager.m_proposedDatabase);
    59     m_manager.m_proposedDatabase = this;
     58    m_manager.addProposedDatabase(this);
    6059}
    6160
    6261DatabaseManager::ProposedDatabase::~ProposedDatabase()
    6362{
    64     m_manager.m_proposedDatabase = 0;
     63    m_manager.removeProposedDatabase(this);
    6564}
    6665
     
    8483    , m_databaseContextInstanceCount(0)
    8584#endif
    86     , m_proposedDatabase(0)
    8785{
    8886    ASSERT(m_server); // We should always have a server to work with.
     
    145143PassRefPtr<DatabaseContext> DatabaseManager::existingDatabaseContextFor(ScriptExecutionContext* context)
    146144{
    147     MutexLocker locker(m_contextMapLock);
     145    MutexLocker locker(m_lock);
    148146
    149147    ASSERT(m_databaseContextRegisteredCount >= 0);
     
    176174void DatabaseManager::registerDatabaseContext(DatabaseContext* databaseContext)
    177175{
    178     MutexLocker locker(m_contextMapLock);
     176    MutexLocker locker(m_lock);
    179177    ScriptExecutionContext* context = databaseContext->scriptExecutionContext();
    180178    m_contextMap.set(context, databaseContext);
     
    186184void DatabaseManager::unregisterDatabaseContext(DatabaseContext* databaseContext)
    187185{
    188     MutexLocker locker(m_contextMapLock);
     186    MutexLocker locker(m_lock);
    189187    ScriptExecutionContext* context = databaseContext->scriptExecutionContext();
    190188    ASSERT(m_contextMap.get(context));
     
    198196void DatabaseManager::didConstructDatabaseContext()
    199197{
    200     MutexLocker lock(m_contextMapLock);
     198    MutexLocker lock(m_lock);
    201199    m_databaseContextInstanceCount++;
    202200}
     
    204202void DatabaseManager::didDestructDatabaseContext()
    205203{
    206     MutexLocker lock(m_contextMapLock);
     204    MutexLocker lock(m_lock);
    207205    m_databaseContextInstanceCount--;
    208206    ASSERT(m_databaseContextRegisteredCount <= m_databaseContextInstanceCount);
     
    297295}
    298296
     297void DatabaseManager::addProposedDatabase(ProposedDatabase* proposedDb)
     298{
     299    MutexLocker locker(m_lock);
     300    m_proposedDatabases.add(proposedDb);
     301}
     302
     303void DatabaseManager::removeProposedDatabase(ProposedDatabase* proposedDb)
     304{
     305    MutexLocker locker(m_lock);
     306    m_proposedDatabases.remove(proposedDb);
     307}
     308
    299309PassRefPtr<Database> DatabaseManager::openDatabase(ScriptExecutionContext* context,
    300310    const String& name, const String& expectedVersion, const String& displayName,
     
    370380String DatabaseManager::fullPathForDatabase(SecurityOrigin* origin, const String& name, bool createIfDoesNotExist)
    371381{
    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    }
    375388    return m_server->fullPathForDatabase(origin, name, createIfDoesNotExist);
    376389}
     
    393406DatabaseDetails DatabaseManager::detailsForNameAndOrigin(const String& name, SecurityOrigin* origin)
    394407{
    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            }
    399415    }
    400416    return m_server->detailsForNameAndOrigin(name, origin);
  • trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.h

    r157874 r158058  
    3434#include <wtf/Assertions.h>
    3535#include <wtf/HashMap.h>
     36#include <wtf/HashSet.h>
    3637#include <wtf/PassRefPtr.h>
    3738#include <wtf/Threading.h>
     
    133134        unsigned long estimatedSize, bool setVersionInNewDatabase, DatabaseError&, String& errorMessage);
    134135
     136    void addProposedDatabase(ProposedDatabase*);
     137    void removeProposedDatabase(ProposedDatabase*);
     138
    135139    static void logErrorMessage(ScriptExecutionContext*, const String& message);
    136140
     
    139143    bool m_databaseIsAvailable;
    140144
    141     // Access to the following fields require locking m_contextMapLock:
     145    // Access to the following fields require locking m_lock below:
    142146    typedef HashMap<ScriptExecutionContext*, DatabaseContext*> ContextMap;
    143147    ContextMap m_contextMap;
     
    146150    int m_databaseContextInstanceCount;
    147151#endif
    148     Mutex m_contextMapLock;
     152    HashSet<ProposedDatabase*> m_proposedDatabases;
    149153
    150     ProposedDatabase* m_proposedDatabase;
     154    // This lock protects m_contextMap, and m_proposedDatabases.
     155    Mutex m_lock;
    151156};
    152157
Note: See TracChangeset for help on using the changeset viewer.