Changeset 113473 in webkit


Ignore:
Timestamp:
Apr 6, 2012 12:06:47 PM (12 years ago)
Author:
jsbell@chromium.org
Message:

IndexedDB: ObjectStore/Index shouldn't hold reference to backing store
https://bugs.webkit.org/show_bug.cgi?id=83074

Source/WebCore:

We should be able to collect and close the leveldb backing store as soon as the database
connection is closed, but the IDBObjectStoreBackendImpl and IDBIndexBackendImpl were
holding RefPtrs, and those objects are kept alive by script references.

Replaced RefPtrs to the IDBBackingStore with pointers to the IDBDatabase. On the back end,
IDBDatabaseBackendImpl maintains a RefPtr to the IDBObjectStoreBackendImpl object, so
a raw pointer back is safe. On the front end, the IDBObjectStore maintains a RefPtr to
the IDBDatabase so script can navigate upwards. Ditto on both ends for the ObjectStore/Index
relationship. The frontend objects maintain RefPtrs to the backend objects, so the backend
objects and their owners are maintained as long as there's a script reference.

Also made IDBDatabaseBackendImpl handle a null IDBFactoryBackendImpl pointer, for testing.

Reviewed by Tony Chang.

Tests: webkit_unit_tests --gtest_filter="IDBDatabaseBackendTest.*"

  • Modules/indexeddb/IDBDatabaseBackendImpl.cpp:

(WebCore::IDBDatabaseBackendImpl::~IDBDatabaseBackendImpl):
(WebCore::IDBDatabaseBackendImpl::createObjectStore):
(WebCore::IDBDatabaseBackendImpl::loadObjectStores):

  • Modules/indexeddb/IDBIndexBackendImpl.cpp:

(WebCore::IDBIndexBackendImpl::IDBIndexBackendImpl):
(WebCore::IDBIndexBackendImpl::openCursorInternal):
(WebCore::IDBIndexBackendImpl::countInternal):
(WebCore::IDBIndexBackendImpl::getInternal):
(WebCore::IDBIndexBackendImpl::addingKeyAllowed):

  • Modules/indexeddb/IDBIndexBackendImpl.h:

(WebCore::IDBIndexBackendImpl::create):
(IDBIndexBackendImpl):
(WebCore::IDBIndexBackendImpl::backingStore):
(WebCore::IDBIndexBackendImpl::databaseId):

  • Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:

(WebCore::IDBObjectStoreBackendImpl::IDBObjectStoreBackendImpl):
(WebCore::IDBObjectStoreBackendImpl::getInternal):
(WebCore::IDBObjectStoreBackendImpl::putInternal):
(WebCore::IDBObjectStoreBackendImpl::deleteInternal):
(WebCore::IDBObjectStoreBackendImpl::clearInternal):
(WebCore):
(WebCore::IDBObjectStoreBackendImpl::createIndex):
(WebCore::IDBObjectStoreBackendImpl::createIndexInternal):
(WebCore::IDBObjectStoreBackendImpl::deleteIndexInternal):
(WebCore::IDBObjectStoreBackendImpl::openCursorInternal):
(WebCore::IDBObjectStoreBackendImpl::countInternal):
(WebCore::IDBObjectStoreBackendImpl::loadIndexes):
(WebCore::IDBObjectStoreBackendImpl::genAutoIncrementKey):

  • Modules/indexeddb/IDBObjectStoreBackendImpl.h:

(WebCore::IDBObjectStoreBackendImpl::create):
(IDBObjectStoreBackendImpl):
(WebCore::IDBObjectStoreBackendImpl::backingStore):
(WebCore::IDBObjectStoreBackendImpl::databaseId):

Source/WebKit/chromium:

Reviewed by Tony Chang.

  • WebKit.gypi:
  • tests/IDBDatabaseBackendTest.cpp: Added.

(WebCore):
(MockIDBBackingStore):
(WebCore::TEST):

Location:
trunk/Source
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r113472 r113473  
     12012-04-06  Joshua Bell  <jsbell@chromium.org>
     2
     3        IndexedDB: ObjectStore/Index shouldn't hold reference to backing store
     4        https://bugs.webkit.org/show_bug.cgi?id=83074
     5
     6        We should be able to collect and close the leveldb backing store as soon as the database
     7        connection is closed, but the IDBObjectStoreBackendImpl and IDBIndexBackendImpl were
     8        holding RefPtrs, and those objects are kept alive by script references.
     9
     10        Replaced RefPtrs to the IDBBackingStore with pointers to the IDBDatabase. On the back end,
     11        IDBDatabaseBackendImpl maintains a RefPtr to the IDBObjectStoreBackendImpl object, so
     12        a raw pointer back is safe. On the front end, the IDBObjectStore maintains a RefPtr to
     13        the IDBDatabase so script can navigate upwards. Ditto on both ends for the ObjectStore/Index
     14        relationship. The frontend objects maintain RefPtrs to the backend objects, so the backend
     15        objects and their owners are maintained as long as there's a script reference.
     16
     17        Also made IDBDatabaseBackendImpl handle a null IDBFactoryBackendImpl pointer, for testing.
     18
     19        Reviewed by Tony Chang.
     20
     21        Tests: webkit_unit_tests --gtest_filter="IDBDatabaseBackendTest.*"
     22
     23        * Modules/indexeddb/IDBDatabaseBackendImpl.cpp:
     24        (WebCore::IDBDatabaseBackendImpl::~IDBDatabaseBackendImpl):
     25        (WebCore::IDBDatabaseBackendImpl::createObjectStore):
     26        (WebCore::IDBDatabaseBackendImpl::loadObjectStores):
     27        * Modules/indexeddb/IDBIndexBackendImpl.cpp:
     28        (WebCore::IDBIndexBackendImpl::IDBIndexBackendImpl):
     29        (WebCore::IDBIndexBackendImpl::openCursorInternal):
     30        (WebCore::IDBIndexBackendImpl::countInternal):
     31        (WebCore::IDBIndexBackendImpl::getInternal):
     32        (WebCore::IDBIndexBackendImpl::addingKeyAllowed):
     33        * Modules/indexeddb/IDBIndexBackendImpl.h:
     34        (WebCore::IDBIndexBackendImpl::create):
     35        (IDBIndexBackendImpl):
     36        (WebCore::IDBIndexBackendImpl::backingStore):
     37        (WebCore::IDBIndexBackendImpl::databaseId):
     38        * Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:
     39        (WebCore::IDBObjectStoreBackendImpl::IDBObjectStoreBackendImpl):
     40        (WebCore::IDBObjectStoreBackendImpl::getInternal):
     41        (WebCore::IDBObjectStoreBackendImpl::putInternal):
     42        (WebCore::IDBObjectStoreBackendImpl::deleteInternal):
     43        (WebCore::IDBObjectStoreBackendImpl::clearInternal):
     44        (WebCore):
     45        (WebCore::IDBObjectStoreBackendImpl::createIndex):
     46        (WebCore::IDBObjectStoreBackendImpl::createIndexInternal):
     47        (WebCore::IDBObjectStoreBackendImpl::deleteIndexInternal):
     48        (WebCore::IDBObjectStoreBackendImpl::openCursorInternal):
     49        (WebCore::IDBObjectStoreBackendImpl::countInternal):
     50        (WebCore::IDBObjectStoreBackendImpl::loadIndexes):
     51        (WebCore::IDBObjectStoreBackendImpl::genAutoIncrementKey):
     52        * Modules/indexeddb/IDBObjectStoreBackendImpl.h:
     53        (WebCore::IDBObjectStoreBackendImpl::create):
     54        (IDBObjectStoreBackendImpl):
     55        (WebCore::IDBObjectStoreBackendImpl::backingStore):
     56        (WebCore::IDBObjectStoreBackendImpl::databaseId):
     57
    1582012-04-06  Jon Lee  <jonlee@apple.com>
    259
  • trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.cpp

    r109493 r113473  
    121121IDBDatabaseBackendImpl::~IDBDatabaseBackendImpl()
    122122{
    123     m_factory->removeIDBDatabaseBackend(m_identifier);
     123    // This check should only be false in tests.
     124    if (m_factory)
     125        m_factory->removeIDBDatabaseBackend(m_identifier);
    124126}
    125127
     
    147149    }
    148150
    149     RefPtr<IDBObjectStoreBackendImpl> objectStore = IDBObjectStoreBackendImpl::create(m_backingStore.get(), m_id, name, keyPath, autoIncrement);
     151    RefPtr<IDBObjectStoreBackendImpl> objectStore = IDBObjectStoreBackendImpl::create(this, name, keyPath, autoIncrement);
    150152    ASSERT(objectStore->name() == name);
    151153
     
    386388
    387389    for (size_t i = 0; i < ids.size(); i++)
    388         m_objectStores.set(names[i], IDBObjectStoreBackendImpl::create(m_backingStore.get(), m_id, ids[i], names[i], keyPaths[i], autoIncrementFlags[i]));
     390        m_objectStores.set(names[i], IDBObjectStoreBackendImpl::create(this, ids[i], names[i], keyPaths[i], autoIncrementFlags[i]));
    389391}
    390392
  • trunk/Source/WebCore/Modules/indexeddb/IDBIndexBackendImpl.cpp

    r110539 r113473  
    4242namespace WebCore {
    4343
    44 IDBIndexBackendImpl::IDBIndexBackendImpl(IDBBackingStore* backingStore, int64_t databaseId, const IDBObjectStoreBackendImpl* objectStoreBackend, int64_t id, const String& name, const String& storeName, const String& keyPath, bool unique, bool multiEntry)
    45     : m_backingStore(backingStore)
    46     , m_databaseId(databaseId)
     44IDBIndexBackendImpl::IDBIndexBackendImpl(const IDBDatabaseBackendImpl* database, const IDBObjectStoreBackendImpl* objectStoreBackend, int64_t id, const String& name, const String& storeName, const String& keyPath, bool unique, bool multiEntry)
     45    : m_database(database)
    4746    , m_objectStoreBackend(objectStoreBackend)
    4847    , m_id(id)
     
    5554}
    5655
    57 IDBIndexBackendImpl::IDBIndexBackendImpl(IDBBackingStore* backingStore, int64_t databaseId, const IDBObjectStoreBackendImpl* objectStoreBackend, const String& name, const String& storeName, const String& keyPath, bool unique, bool multiEntry)
    58     : m_backingStore(backingStore)
    59     , m_databaseId(databaseId)
     56IDBIndexBackendImpl::IDBIndexBackendImpl(const IDBDatabaseBackendImpl* database, const IDBObjectStoreBackendImpl* objectStoreBackend, const String& name, const String& storeName, const String& keyPath, bool unique, bool multiEntry)
     57    : m_database(database)
    6058    , m_objectStoreBackend(objectStoreBackend)
    6159    , m_id(InvalidId)
     
    8179    switch (cursorType) {
    8280    case IDBCursorBackendInterface::IndexKeyCursor:
    83         backingStoreCursor = index->m_backingStore->openIndexKeyCursor(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), range.get(), direction);
     81        backingStoreCursor = index->backingStore()->openIndexKeyCursor(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), range.get(), direction);
    8482        break;
    8583    case IDBCursorBackendInterface::IndexCursor:
    86         backingStoreCursor = index->m_backingStore->openIndexCursor(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), range.get(), direction);
     84        backingStoreCursor = index->backingStore()->openIndexCursor(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), range.get(), direction);
    8785        break;
    8886    case IDBCursorBackendInterface::ObjectStoreCursor:
     
    132130    uint32_t count = 0;
    133131
    134     RefPtr<IDBBackingStore::Cursor> backingStoreCursor = index->m_backingStore->openIndexKeyCursor(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), range.get(), IDBCursor::NEXT);
     132    RefPtr<IDBBackingStore::Cursor> backingStoreCursor = index->backingStore()->openIndexKeyCursor(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), range.get(), IDBCursor::NEXT);
    135133    if (!backingStoreCursor) {
    136134        callbacks->onSuccess(SerializedScriptValue::numberValue(count));
     
    157155    // FIXME: Split getInternal into two functions, getting rid off |getObject|.
    158156    if (getObject) {
    159         String value = index->m_backingStore->getObjectViaIndex(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), *key);
     157        String value = index->backingStore()->getObjectViaIndex(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), *key);
    160158        if (value.isNull()) {
    161159            callbacks->onSuccess(SerializedScriptValue::undefinedValue());
     
    164162        callbacks->onSuccess(SerializedScriptValue::createFromWire(value));
    165163    } else {
    166         RefPtr<IDBKey> keyResult = index->m_backingStore->getPrimaryKeyViaIndex(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), *key);
     164        RefPtr<IDBKey> keyResult = index->backingStore()->getPrimaryKeyViaIndex(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), *key);
    167165        if (!keyResult) {
    168166            callbacks->onSuccess(static_cast<IDBKey*>(0));
     
    199197
    200198    RefPtr<IDBKey> foundPrimaryKey;
    201     bool found = m_backingStore->keyExistsInIndex(m_databaseId, m_objectStoreBackend->id(), m_id, *indexKey, foundPrimaryKey);
     199    bool found = backingStore()->keyExistsInIndex(databaseId(), m_objectStoreBackend->id(), m_id, *indexKey, foundPrimaryKey);
    202200    if (!found)
    203201        return true;
  • trunk/Source/WebCore/Modules/indexeddb/IDBIndexBackendImpl.h

    r109493 r113473  
    3030
    3131#include "IDBCursorBackendInterface.h"
     32#include "IDBDatabaseBackendImpl.h"
    3233#include "IDBIndexBackendInterface.h"
    3334
     
    4142class IDBIndexBackendImpl : public IDBIndexBackendInterface {
    4243public:
    43     static PassRefPtr<IDBIndexBackendImpl> create(IDBBackingStore* backingStore, int64_t databaseId, const IDBObjectStoreBackendImpl* objectStoreBackend, int64_t id, const String& name, const String& storeName, const String& keyPath, bool unique, bool multiEntry)
     44    static PassRefPtr<IDBIndexBackendImpl> create(const IDBDatabaseBackendImpl* database, const IDBObjectStoreBackendImpl* objectStoreBackend, int64_t id, const String& name, const String& storeName, const String& keyPath, bool unique, bool multiEntry)
    4445    {
    45         return adoptRef(new IDBIndexBackendImpl(backingStore, databaseId, objectStoreBackend, id, name, storeName, keyPath, unique, multiEntry));
     46        return adoptRef(new IDBIndexBackendImpl(database, objectStoreBackend, id, name, storeName, keyPath, unique, multiEntry));
    4647    }
    47     static PassRefPtr<IDBIndexBackendImpl> create(IDBBackingStore* backingStore, int64_t databaseId, const IDBObjectStoreBackendImpl* objectStoreBackend, const String& name, const String& storeName, const String& keyPath, bool unique, bool multiEntry)
     48    static PassRefPtr<IDBIndexBackendImpl> create(const IDBDatabaseBackendImpl* database, const IDBObjectStoreBackendImpl* objectStoreBackend, const String& name, const String& storeName, const String& keyPath, bool unique, bool multiEntry)
    4849    {
    49         return adoptRef(new IDBIndexBackendImpl(backingStore, databaseId, objectStoreBackend, name, storeName, keyPath, unique, multiEntry));
     50        return adoptRef(new IDBIndexBackendImpl(database, objectStoreBackend, name, storeName, keyPath, unique, multiEntry));
    5051    }
    5152    virtual ~IDBIndexBackendImpl();
     
    7576
    7677private:
    77     IDBIndexBackendImpl(IDBBackingStore*, int64_t databaseId, const IDBObjectStoreBackendImpl*, int64_t id, const String& name, const String& storeName, const String& keyPath, bool unique, bool multiEntry);
    78     IDBIndexBackendImpl(IDBBackingStore*, int64_t databaseId, const IDBObjectStoreBackendImpl*, const String& name, const String& storeName, const String& keyPath, bool unique, bool multiEntry);
     78    IDBIndexBackendImpl(const IDBDatabaseBackendImpl*, const IDBObjectStoreBackendImpl*, int64_t, const String&, const String&, const String&, bool, bool);
     79    IDBIndexBackendImpl(const IDBDatabaseBackendImpl*, const IDBObjectStoreBackendImpl*, const String&, const String&, const String&, bool, bool);
    7980
    8081    static void openCursorInternal(ScriptExecutionContext*, PassRefPtr<IDBIndexBackendImpl>, PassRefPtr<IDBKeyRange>, unsigned short direction, IDBCursorBackendInterface::CursorType, PassRefPtr<IDBCallbacks>, PassRefPtr<IDBTransactionBackendInterface>);
     
    8485    static const int64_t InvalidId = 0;
    8586
    86     RefPtr<IDBBackingStore> m_backingStore;
     87    PassRefPtr<IDBBackingStore> backingStore() const { return m_database->backingStore(); }
     88    int64_t databaseId() const { return m_database->id(); }
    8789
    88     int64_t m_databaseId;
     90    const IDBDatabaseBackendImpl* m_database;
     91
    8992    const IDBObjectStoreBackendImpl* m_objectStoreBackend;
    9093    int64_t m_id;
  • trunk/Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp

    r110539 r113473  
    5252}
    5353
    54 IDBObjectStoreBackendImpl::IDBObjectStoreBackendImpl(IDBBackingStore* backingStore, int64_t databaseId, int64_t id, const String& name, const String& keyPath, bool autoIncrement)
    55     : m_backingStore(backingStore)
    56     , m_databaseId(databaseId)
     54IDBObjectStoreBackendImpl::IDBObjectStoreBackendImpl(const IDBDatabaseBackendImpl* database, int64_t id, const String& name, const String& keyPath, bool autoIncrement)
     55    : m_database(database)
    5756    , m_id(id)
    5857    , m_name(name)
     
    6463}
    6564
    66 IDBObjectStoreBackendImpl::IDBObjectStoreBackendImpl(IDBBackingStore* backingStore, int64_t databaseId, const String& name, const String& keyPath, bool autoIncrement)
    67     : m_backingStore(backingStore)
    68     , m_databaseId(databaseId)
     65IDBObjectStoreBackendImpl::IDBObjectStoreBackendImpl(const IDBDatabaseBackendImpl* database, const String& name, const String& keyPath, bool autoIncrement)
     66    : m_database(database)
    6967    , m_id(InvalidId)
    7068    , m_name(name)
     
    9795{
    9896    IDB_TRACE("IDBObjectStoreBackendImpl::getInternal");
    99     String wireData = objectStore->m_backingStore->getObjectStoreRecord(objectStore->m_databaseId, objectStore->id(), *key);
     97    String wireData = objectStore->backingStore()->getObjectStoreRecord(objectStore->databaseId(), objectStore->id(), *key);
    10098    if (wireData.isNull()) {
    10199        callbacks->onSuccess(SerializedScriptValue::undefinedValue());
     
    246244    ASSERT(key && key->valid());
    247245
    248     RefPtr<IDBBackingStore::ObjectStoreRecordIdentifier> recordIdentifier = objectStore->m_backingStore->createInvalidRecordIdentifier();
    249     if (putMode == AddOnly && objectStore->m_backingStore->keyExistsInObjectStore(objectStore->m_databaseId, objectStore->id(), *key, recordIdentifier.get())) {
     246    RefPtr<IDBBackingStore::ObjectStoreRecordIdentifier> recordIdentifier = objectStore->backingStore()->createInvalidRecordIdentifier();
     247    if (putMode == AddOnly && objectStore->backingStore()->keyExistsInObjectStore(objectStore->databaseId(), objectStore->id(), *key, recordIdentifier.get())) {
    250248        objectStore->resetAutoIncrementKeyCache();
    251249        callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::CONSTRAINT_ERR, "Key already exists in the object store."));
     
    285283    // Before this point, don't do any mutation.  After this point, rollback the transaction in case of error.
    286284
    287     if (!objectStore->m_backingStore->putObjectStoreRecord(objectStore->m_databaseId, objectStore->id(), *key, value->toWireString(), recordIdentifier.get())) {
     285    if (!objectStore->backingStore()->putObjectStoreRecord(objectStore->databaseId(), objectStore->id(), *key, value->toWireString(), recordIdentifier.get())) {
    288286        // FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
    289287        callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Error writing data to stable storage."));
     
    298296            continue; // The index object has been created, but does not exist in the database yet.
    299297
    300         if (!objectStore->m_backingStore->deleteIndexDataForRecord(objectStore->m_databaseId, objectStore->id(), index->id(), recordIdentifier.get())) {
     298        if (!objectStore->backingStore()->deleteIndexDataForRecord(objectStore->databaseId(), objectStore->id(), index->id(), recordIdentifier.get())) {
    301299            // FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
    302300            callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Error writing data to stable storage."));
     
    310308
    311309        if (!index->multiEntry() || indexKey->type() != IDBKey::ArrayType) {
    312             if (!objectStore->m_backingStore->putIndexDataForRecord(objectStore->m_databaseId, objectStore->id(), index->id(), *indexKey, recordIdentifier.get())) {
     310            if (!objectStore->backingStore()->putIndexDataForRecord(objectStore->databaseId(), objectStore->id(), index->id(), *indexKey, recordIdentifier.get())) {
    313311                // FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
    314312                callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Error writing data to stable storage."));
     
    320318            ASSERT(indexKey->type() == IDBKey::ArrayType);
    321319            for (size_t j = 0; j < indexKey->array().size(); ++j) {
    322                 if (!objectStore->m_backingStore->putIndexDataForRecord(objectStore->m_databaseId, objectStore->id(), index->id(), *indexKey->array()[j], recordIdentifier.get())) {
     320                if (!objectStore->backingStore()->putIndexDataForRecord(objectStore->databaseId(), objectStore->id(), index->id(), *indexKey->array()[j], recordIdentifier.get())) {
    323321                    // FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
    324322                    callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Error writing data to stable storage."));
     
    370368    RefPtr<IDBBackingStore::ObjectStoreRecordIdentifier> recordIdentifier;
    371369
    372     RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->m_backingStore->openObjectStoreCursor(objectStore->m_databaseId, objectStore->id(), keyRange.get(), IDBCursor::NEXT);
     370    RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->backingStore()->openObjectStoreCursor(objectStore->databaseId(), objectStore->id(), keyRange.get(), IDBCursor::NEXT);
    373371    if (backingStoreCursor) {
    374372
     
    380378                    continue; // The index object has been created, but does not exist in the database yet.
    381379
    382                 bool success = objectStore->m_backingStore->deleteIndexDataForRecord(objectStore->m_databaseId, objectStore->id(), it->second->id(), recordIdentifier.get());
     380                bool success = objectStore->backingStore()->deleteIndexDataForRecord(objectStore->databaseId(), objectStore->id(), it->second->id(), recordIdentifier.get());
    383381                ASSERT_UNUSED(success, success);
    384382            }
    385383
    386             objectStore->m_backingStore->deleteObjectStoreRecord(objectStore->m_databaseId, objectStore->id(), recordIdentifier.get());
     384            objectStore->backingStore()->deleteObjectStoreRecord(objectStore->databaseId(), objectStore->id(), recordIdentifier.get());
    387385
    388386        } while (backingStoreCursor->continueFunction(0));
     
    411409void IDBObjectStoreBackendImpl::clearInternal(ScriptExecutionContext*, PassRefPtr<IDBObjectStoreBackendImpl> objectStore, PassRefPtr<IDBCallbacks> callbacks)
    412410{
    413     objectStore->m_backingStore->clearObjectStore(objectStore->m_databaseId, objectStore->id());
     411    objectStore->backingStore()->clearObjectStore(objectStore->databaseId(), objectStore->id());
    414412    callbacks->onSuccess(SerializedScriptValue::undefinedValue());
    415413}
     
    483481    }
    484482
    485     RefPtr<IDBIndexBackendImpl> index = IDBIndexBackendImpl::create(m_backingStore.get(), m_databaseId, this, name, m_name, keyPath, unique, multiEntry);
     483    RefPtr<IDBIndexBackendImpl> index = IDBIndexBackendImpl::create(m_database, this, name, m_name, keyPath, unique, multiEntry);
    486484    ASSERT(index->name() == name);
    487485
     
    504502{
    505503    int64_t id;
    506     if (!objectStore->m_backingStore->createIndex(objectStore->m_databaseId, objectStore->id(), index->name(), index->keyPath(), index->unique(), index->multiEntry(), id)) {
     504    if (!objectStore->backingStore()->createIndex(objectStore->databaseId(), objectStore->id(), index->name(), index->keyPath(), index->unique(), index->multiEntry(), id)) {
    507505        transaction->abort();
    508506        return;
     
    511509    index->setId(id);
    512510
    513     if (!populateIndex(*objectStore->m_backingStore, objectStore->m_databaseId, objectStore->m_id, index)) {
     511    if (!populateIndex(*objectStore->backingStore(), objectStore->databaseId(), objectStore->m_id, index)) {
    514512        transaction->abort();
    515513        return;
     
    557555void IDBObjectStoreBackendImpl::deleteIndexInternal(ScriptExecutionContext*, PassRefPtr<IDBObjectStoreBackendImpl> objectStore, PassRefPtr<IDBIndexBackendImpl> index, PassRefPtr<IDBTransactionBackendInterface> transaction)
    558556{
    559     objectStore->m_backingStore->deleteIndex(objectStore->m_databaseId, objectStore->id(), index->id());
     557    objectStore->backingStore()->deleteIndex(objectStore->databaseId(), objectStore->id(), index->id());
    560558    transaction->didCompleteTaskEvents();
    561559}
     
    580578    IDBCursor::Direction direction = static_cast<IDBCursor::Direction>(tmpDirection);
    581579
    582     RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->m_backingStore->openObjectStoreCursor(objectStore->m_databaseId, objectStore->id(), range.get(), direction);
     580    RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->backingStore()->openObjectStoreCursor(objectStore->databaseId(), objectStore->id(), range.get(), direction);
    583581    if (!backingStoreCursor) {
    584582        callbacks->onSuccess(SerializedScriptValue::nullValue());
     
    601599    IDB_TRACE("IDBObjectStoreBackendImpl::countInternal");
    602600    uint32_t count = 0;
    603     RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->m_backingStore->openObjectStoreCursor(objectStore->m_databaseId, objectStore->id(), range.get(), IDBCursor::NEXT);
     601    RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->backingStore()->openObjectStoreCursor(objectStore->databaseId(), objectStore->id(), range.get(), IDBCursor::NEXT);
    604602    if (!backingStoreCursor) {
    605603        callbacks->onSuccess(SerializedScriptValue::numberValue(count));
     
    622620    Vector<bool> uniqueFlags;
    623621    Vector<bool> multiEntryFlags;
    624     m_backingStore->getIndexes(m_databaseId, m_id, ids, names, keyPaths, uniqueFlags, multiEntryFlags);
     622    backingStore()->getIndexes(databaseId(), m_id, ids, names, keyPaths, uniqueFlags, multiEntryFlags);
    625623
    626624    ASSERT(names.size() == ids.size());
     
    630628
    631629    for (size_t i = 0; i < ids.size(); i++)
    632         m_indexes.set(names[i], IDBIndexBackendImpl::create(m_backingStore.get(), m_databaseId, this, ids[i], names[i], m_name, keyPaths[i], uniqueFlags[i], multiEntryFlags[i]));
     630        m_indexes.set(names[i], IDBIndexBackendImpl::create(m_database, this, ids[i], names[i], m_name, keyPaths[i], uniqueFlags[i], multiEntryFlags[i]));
    633631}
    634632
     
    651649        return IDBKey::createNumber(m_autoIncrementNumber++);
    652650
    653     m_autoIncrementNumber = static_cast<int>(m_backingStore->nextAutoIncrementNumber(m_databaseId, id()));
     651    m_autoIncrementNumber = static_cast<int>(backingStore()->nextAutoIncrementNumber(databaseId(), id()));
    654652    return IDBKey::createNumber(m_autoIncrementNumber++);
    655653}
  • trunk/Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.h

    r109493 r113473  
    2727#define IDBObjectStoreBackendImpl_h
    2828
     29#include "IDBDatabaseBackendImpl.h"
    2930#include "IDBObjectStoreBackendInterface.h"
    3031#include <wtf/HashMap.h>
     
    3536namespace WebCore {
    3637
    37 class IDBBackingStore;
    3838class IDBDatabaseBackendImpl;
    3939class IDBIndexBackendImpl;
     
    4343class IDBObjectStoreBackendImpl : public IDBObjectStoreBackendInterface {
    4444public:
    45     static PassRefPtr<IDBObjectStoreBackendImpl> create(IDBBackingStore* backingStore, int64_t databaseId, int64_t id, const String& name, const String& keyPath, bool autoIncrement)
     45    static PassRefPtr<IDBObjectStoreBackendImpl> create(const IDBDatabaseBackendImpl* database, int64_t id, const String& name, const String& keyPath, bool autoIncrement)
    4646    {
    47         return adoptRef(new IDBObjectStoreBackendImpl(backingStore, databaseId, id, name, keyPath, autoIncrement));
     47        return adoptRef(new IDBObjectStoreBackendImpl(database, id, name, keyPath, autoIncrement));
    4848    }
    49     static PassRefPtr<IDBObjectStoreBackendImpl> create(IDBBackingStore* backingStore, int64_t databaseId, const String& name, const String& keyPath, bool autoIncrement)
     49    static PassRefPtr<IDBObjectStoreBackendImpl> create(const IDBDatabaseBackendImpl* database, const String& name, const String& keyPath, bool autoIncrement)
    5050    {
    51         return adoptRef(new IDBObjectStoreBackendImpl(backingStore, databaseId, name, keyPath, autoIncrement));
     51        return adoptRef(new IDBObjectStoreBackendImpl(database, name, keyPath, autoIncrement));
    5252    }
    5353    virtual ~IDBObjectStoreBackendImpl();
     
    6060    }
    6161    void setId(int64_t id) { m_id = id; }
    62     int64_t databaseId() const { return m_databaseId; }
    6362
    6463    virtual String name() const { return m_name; }
     
    8382
    8483private:
    85     IDBObjectStoreBackendImpl(IDBBackingStore*, int64_t databaseId, int64_t id, const String& name, const String& keyPath, bool autoIncrement);
    86     IDBObjectStoreBackendImpl(IDBBackingStore*, int64_t databaseId, const String& name, const String& keyPath, bool autoIncrement);
     84    IDBObjectStoreBackendImpl(const IDBDatabaseBackendImpl*, int64_t, const String&, const String&, bool);
     85    IDBObjectStoreBackendImpl(const IDBDatabaseBackendImpl*, const String&, const String&, bool);
    8786
    8887    void loadIndexes();
     
    104103    static void revertAutoIncrementKeyCache(ScriptExecutionContext*, PassRefPtr<IDBObjectStoreBackendImpl>);
    105104
    106     RefPtr<IDBBackingStore> m_backingStore;
     105    PassRefPtr<IDBBackingStore> backingStore() const { return m_database->backingStore(); }
     106    int64_t databaseId() const { return m_database->id(); }
    107107
    108     int64_t m_databaseId;
     108    const IDBDatabaseBackendImpl* m_database;
    109109    int64_t m_id;
    110110    String m_name;
  • trunk/Source/WebKit/chromium/ChangeLog

    r113416 r113473  
     12012-04-06  Joshua Bell  <jsbell@chromium.org>
     2
     3        IndexedDB: ObjectStore/Index shouldn't hold reference to backing store
     4        https://bugs.webkit.org/show_bug.cgi?id=83074
     5
     6        Reviewed by Tony Chang.
     7
     8        * WebKit.gypi:
     9        * tests/IDBDatabaseBackendTest.cpp: Added.
     10        (WebCore):
     11        (MockIDBBackingStore):
     12        (WebCore::TEST):
     13
    1142012-04-06  Kent Tamura  <tkent@chromium.org>
    215
  • trunk/Source/WebKit/chromium/WebKit.gypi

    r112550 r113473  
    103103            'tests/FrameTestHelpers.h',
    104104            'tests/IDBBindingUtilitiesTest.cpp',
     105            'tests/IDBDatabaseBackendTest.cpp',
    105106            'tests/IDBKeyPathTest.cpp',
    106107            'tests/IDBLevelDBCodingTest.cpp',
Note: See TracChangeset for help on using the changeset viewer.