Changeset 89130 in webkit


Ignore:
Timestamp:
Jun 17, 2011 2:43:59 AM (13 years ago)
Author:
hans@chromium.org
Message:

2011-06-09 Hans Wennborg <hans@chromium.org>

Reviewed by Tony Gentilcore.

IndexedDB: backingStoreMap is per backing store, not per database
https://bugs.webkit.org/show_bug.cgi?id=62382

IDBFactoryBackendImpl::m_backingStoreMap should contain an entry per
backing store, not per database. Otherwise, we might accidentally open
the same backing store more than once, which is dangerous.

Also tweak the code that chooses backing store type. It should be
simple: we default to SQLite; if LevelDB is specifically requested, we
use that. If LevelDB is requested and there is a SQLite database, we
migrate.

No new tests, just cleaning up the code.

  • storage/IDBFactoryBackendImpl.cpp: (WebCore::IDBFactoryBackendImpl::addIDBBackingStore): (WebCore::IDBFactoryBackendImpl::removeIDBBackingStore): (WebCore::IDBFactoryBackendImpl::open): (WebCore::IDBFactoryBackendImpl::migrateFromSQLiteToLevelDB):
  • storage/IDBFactoryBackendImpl.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r89128 r89130  
     12011-06-09  Hans Wennborg  <hans@chromium.org>
     2
     3        Reviewed by Tony Gentilcore.
     4
     5        IndexedDB: backingStoreMap is per backing store, not per database
     6        https://bugs.webkit.org/show_bug.cgi?id=62382
     7
     8        IDBFactoryBackendImpl::m_backingStoreMap should contain an entry per
     9        backing store, not per database. Otherwise, we might accidentally open
     10        the same backing store more than once, which is dangerous.
     11
     12        Also tweak the code that chooses backing store type. It should be
     13        simple: we default to SQLite; if LevelDB is specifically requested, we
     14        use that. If LevelDB is requested and there is a SQLite database, we
     15        migrate.
     16
     17        No new tests, just cleaning up the code.
     18
     19        * storage/IDBFactoryBackendImpl.cpp:
     20        (WebCore::IDBFactoryBackendImpl::addIDBBackingStore):
     21        (WebCore::IDBFactoryBackendImpl::removeIDBBackingStore):
     22        (WebCore::IDBFactoryBackendImpl::open):
     23        (WebCore::IDBFactoryBackendImpl::migrateFromSQLiteToLevelDB):
     24        * storage/IDBFactoryBackendImpl.h:
     25
    1262011-06-17  Andrey Adaikin  <aandrey@google.com>
    227
  • trunk/Source/WebCore/storage/IDBFactoryBackendImpl.cpp

    r88358 r89130  
    5959}
    6060
    61 void IDBFactoryBackendImpl::addIDBBackingStore(const String& uniqueIdentifier, IDBBackingStore* backingStore)
     61void IDBFactoryBackendImpl::addIDBBackingStore(const String& fileIdentifier, IDBBackingStore* backingStore)
    6262{
    63     ASSERT(!m_backingStoreMap.contains(uniqueIdentifier));
    64     m_backingStoreMap.set(uniqueIdentifier, backingStore);
     63    ASSERT(!m_backingStoreMap.contains(fileIdentifier));
     64    m_backingStoreMap.set(fileIdentifier, backingStore);
    6565}
    6666
    67 void IDBFactoryBackendImpl::removeIDBBackingStore(const String& uniqueIdentifier)
     67void IDBFactoryBackendImpl::removeIDBBackingStore(const String& fileIdentifier)
    6868{
    69     ASSERT(m_backingStoreMap.contains(uniqueIdentifier));
    70     m_backingStoreMap.remove(uniqueIdentifier);
     69    ASSERT(m_backingStoreMap.contains(fileIdentifier));
     70    m_backingStoreMap.remove(fileIdentifier);
    7171}
    7272
    7373void IDBFactoryBackendImpl::open(const String& name, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<SecurityOrigin> securityOrigin, Frame*, const String& dataDir, int64_t maximumSize, BackingStoreType backingStoreType)
    7474{
    75     String uniqueIdentifier = securityOrigin->databaseIdentifier() + "@" + name + String::format("@%d", (int)backingStoreType);
     75    if (backingStoreType == DefaultBackingStore)
     76        backingStoreType = SQLiteBackingStore; // FIXME: DefaultBackingStore is confusing; get rid of it.
     77
     78    const String fileIdentifier = securityOrigin->databaseIdentifier() + String::format("@%d", static_cast<int>(backingStoreType));
     79    const String uniqueIdentifier = fileIdentifier + "@" + name;
     80
    7681    IDBDatabaseBackendMap::iterator it = m_databaseBackendMap.find(uniqueIdentifier);
    7782    if (it != m_databaseBackendMap.end()) {
     
    8388
    8489    RefPtr<IDBBackingStore> backingStore;
    85     IDBBackingStoreMap::iterator it2 = m_backingStoreMap.find(uniqueIdentifier);
     90    IDBBackingStoreMap::iterator it2 = m_backingStoreMap.find(fileIdentifier);
    8691    if (it2 != m_backingStoreMap.end() && (backingStoreType == it2->second->backingStoreType()))
    8792        backingStore = it2->second;
    8893    else {
     94
    8995#if ENABLE(LEVELDB)
    90         // Should we migrate this backing store?
    91         bool hasSQLBackingStore = IDBSQLiteBackingStore::backingStoreExists(securityOrigin.get(), dataDir);
    92         bool hasLevelDBBackingStore = IDBLevelDBBackingStore::backingStoreExists(securityOrigin.get(), dataDir);
     96        if (backingStoreType == LevelDBBackingStore) {
     97            const bool hasSQLBackingStore = IDBSQLiteBackingStore::backingStoreExists(securityOrigin.get(), dataDir);
    9398
    94         if (hasSQLBackingStore && hasLevelDBBackingStore)
    95             backingStoreType = LevelDBBackingStore;
    96 
    97         // Migration: if the database exists and is SQLite we want to migrate it to LevelDB.
    98         if (hasSQLBackingStore && !hasLevelDBBackingStore) {
    99             if (migrate(name, securityOrigin.get(), dataDir, maximumSize))
    100                 backingStoreType = LevelDBBackingStore;
     99            if (hasSQLBackingStore) {
     100                bool migrationSucceeded = migrateFromSQLiteToLevelDB(name, securityOrigin.get(), dataDir, maximumSize);
     101                (void)migrationSucceeded; // FIXME: When migration is actually implemented, we need error handling here.
     102            }
    101103        }
    102104#endif
    103105
    104         if (backingStoreType == DefaultBackingStore || backingStoreType == SQLiteBackingStore)
    105             backingStore = IDBSQLiteBackingStore::open(securityOrigin.get(), dataDir, maximumSize, uniqueIdentifier, this);
     106        if (backingStoreType == SQLiteBackingStore)
     107            backingStore = IDBSQLiteBackingStore::open(securityOrigin.get(), dataDir, maximumSize, fileIdentifier, this);
    106108#if ENABLE(LEVELDB)
    107109        else if (backingStoreType == LevelDBBackingStore)
    108             backingStore = IDBLevelDBBackingStore::open(securityOrigin.get(), dataDir, maximumSize, uniqueIdentifier, this);
     110            backingStore = IDBLevelDBBackingStore::open(securityOrigin.get(), dataDir, maximumSize, fileIdentifier, this);
    109111#endif
    110112        if (!backingStore) {
     
    119121}
    120122
    121 bool IDBFactoryBackendImpl::migrate(const String& name, SecurityOrigin* securityOrigin, const String& dataDir, int64_t maximumSize)
     123bool IDBFactoryBackendImpl::migrateFromSQLiteToLevelDB(const String& name, SecurityOrigin* securityOrigin, const String& dataDir, int64_t maximumSize)
    122124{
    123     return false;
     125    return false; // FIXME: To be implemented.
    124126}
    125127
  • trunk/Source/WebCore/storage/IDBFactoryBackendImpl.h

    r88358 r89130  
    5353    // Notifications from weak pointers.
    5454    void removeIDBDatabaseBackend(const String& uniqueIdentifier);
    55     void addIDBBackingStore(const String& uniqueIdentifier, IDBBackingStore*);
    56     void removeIDBBackingStore(const String& uniqueIdentifier);
     55    void addIDBBackingStore(const String& fileIdentifier, IDBBackingStore*);
     56    void removeIDBBackingStore(const String& fileIdentifier);
    5757
    5858    virtual void open(const String& name, PassRefPtr<IDBCallbacks>, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir, int64_t maximumSize, BackingStoreType);
     
    6060private:
    6161    IDBFactoryBackendImpl();
    62     bool migrate(const String& name, SecurityOrigin*, const String& dataDir, int64_t maximumSize);
     62    bool migrateFromSQLiteToLevelDB(const String& name, SecurityOrigin*, const String& dataDir, int64_t maximumSize);
    6363
    6464    typedef HashMap<String, IDBDatabaseBackendImpl*> IDBDatabaseBackendMap;
Note: See TracChangeset for help on using the changeset viewer.