Modern IDB: Make MemoryIndex and MemoryObjectStore RefCounted.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jan 2016 17:39:25 +0000 (17:39 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jan 2016 17:39:25 +0000 (17:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=152966

Reviewed by Alex Christensen.

No new tests (Refactor, no change in behavior)

* Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp:
(WebCore::IDBServer::MemoryBackingStoreTransaction::indexDeleted):
(WebCore::IDBServer::MemoryBackingStoreTransaction::objectStoreDeleted):
(WebCore::IDBServer::MemoryBackingStoreTransaction::abort):
* Modules/indexeddb/server/MemoryBackingStoreTransaction.h:

* Modules/indexeddb/server/MemoryIDBBackingStore.cpp:
(WebCore::IDBServer::MemoryIDBBackingStore::createObjectStore):
(WebCore::IDBServer::MemoryIDBBackingStore::deleteObjectStore):
(WebCore::IDBServer::MemoryIDBBackingStore::restoreObjectStoreForVersionChangeAbort):
(WebCore::IDBServer::MemoryIDBBackingStore::registerObjectStore):
(WebCore::IDBServer::MemoryIDBBackingStore::takeObjectStoreByName):
* Modules/indexeddb/server/MemoryIDBBackingStore.h:

* Modules/indexeddb/server/MemoryIndex.cpp:
(WebCore::IDBServer::MemoryIndex::create):
* Modules/indexeddb/server/MemoryIndex.h:

* Modules/indexeddb/server/MemoryObjectStore.cpp:
(WebCore::IDBServer::MemoryObjectStore::create):
(WebCore::IDBServer::MemoryObjectStore::createIndex):
(WebCore::IDBServer::MemoryObjectStore::maybeRestoreDeletedIndex):
(WebCore::IDBServer::MemoryObjectStore::takeIndexByName):
(WebCore::IDBServer::MemoryObjectStore::deleteIndex):
(WebCore::IDBServer::MemoryObjectStore::updateIndexesForDeleteRecord):
(WebCore::IDBServer::MemoryObjectStore::updateIndexesForPutRecord):
(WebCore::IDBServer::MemoryObjectStore::registerIndex):
* Modules/indexeddb/server/MemoryObjectStore.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@194857 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp
Source/WebCore/Modules/indexeddb/server/MemoryBackingStoreTransaction.h
Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp
Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h
Source/WebCore/Modules/indexeddb/server/MemoryIndex.cpp
Source/WebCore/Modules/indexeddb/server/MemoryIndex.h
Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp
Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h

index 436b3cc..de45a35 100644 (file)
@@ -1,3 +1,41 @@
+2016-01-11  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Make MemoryIndex and MemoryObjectStore RefCounted.
+        https://bugs.webkit.org/show_bug.cgi?id=152966
+
+        Reviewed by Alex Christensen.
+
+        No new tests (Refactor, no change in behavior)
+
+        * Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp:
+        (WebCore::IDBServer::MemoryBackingStoreTransaction::indexDeleted):
+        (WebCore::IDBServer::MemoryBackingStoreTransaction::objectStoreDeleted):
+        (WebCore::IDBServer::MemoryBackingStoreTransaction::abort):
+        * Modules/indexeddb/server/MemoryBackingStoreTransaction.h:
+        
+        * Modules/indexeddb/server/MemoryIDBBackingStore.cpp:
+        (WebCore::IDBServer::MemoryIDBBackingStore::createObjectStore):
+        (WebCore::IDBServer::MemoryIDBBackingStore::deleteObjectStore):
+        (WebCore::IDBServer::MemoryIDBBackingStore::restoreObjectStoreForVersionChangeAbort):
+        (WebCore::IDBServer::MemoryIDBBackingStore::registerObjectStore):
+        (WebCore::IDBServer::MemoryIDBBackingStore::takeObjectStoreByName):
+        * Modules/indexeddb/server/MemoryIDBBackingStore.h:
+        
+        * Modules/indexeddb/server/MemoryIndex.cpp:
+        (WebCore::IDBServer::MemoryIndex::create):
+        * Modules/indexeddb/server/MemoryIndex.h:
+        
+        * Modules/indexeddb/server/MemoryObjectStore.cpp:
+        (WebCore::IDBServer::MemoryObjectStore::create):
+        (WebCore::IDBServer::MemoryObjectStore::createIndex):
+        (WebCore::IDBServer::MemoryObjectStore::maybeRestoreDeletedIndex):
+        (WebCore::IDBServer::MemoryObjectStore::takeIndexByName):
+        (WebCore::IDBServer::MemoryObjectStore::deleteIndex):
+        (WebCore::IDBServer::MemoryObjectStore::updateIndexesForDeleteRecord):
+        (WebCore::IDBServer::MemoryObjectStore::updateIndexesForPutRecord):
+        (WebCore::IDBServer::MemoryObjectStore::registerIndex):
+        * Modules/indexeddb/server/MemoryObjectStore.h:
+
 2016-01-11  Andreas Kling  <akling@apple.com>
 
         Fix other builds after my MSVC build fix. :-|
index 8e0c767..178cd99 100644 (file)
@@ -86,10 +86,9 @@ void MemoryBackingStoreTransaction::addExistingIndex(MemoryIndex& index)
     m_indexes.add(&index);
 }
 
-void MemoryBackingStoreTransaction::indexDeleted(std::unique_ptr<MemoryIndex> index)
+void MemoryBackingStoreTransaction::indexDeleted(Ref<MemoryIndex>&& index)
 {
-    ASSERT(index);
-    m_indexes.remove(index.get());
+    m_indexes.remove(&index.get());
 
     auto addResult = m_deletedIndexes.add(index->info().name(), nullptr);
     if (addResult.isNewEntry)
@@ -110,11 +109,10 @@ void MemoryBackingStoreTransaction::addExistingObjectStore(MemoryObjectStore& ob
     m_originalKeyGenerators.add(&objectStore, objectStore.currentKeyGeneratorValue());
 }
 
-void MemoryBackingStoreTransaction::objectStoreDeleted(std::unique_ptr<MemoryObjectStore> objectStore)
+void MemoryBackingStoreTransaction::objectStoreDeleted(Ref<MemoryObjectStore>&& objectStore)
 {
-    ASSERT(objectStore);
-    ASSERT(m_objectStores.contains(objectStore.get()));
-    m_objectStores.remove(objectStore.get());
+    ASSERT(m_objectStores.contains(&objectStore.get()));
+    m_objectStores.remove(&objectStore.get());
 
     objectStore->deleteAllIndexes(*this);
 
@@ -182,17 +180,11 @@ void MemoryBackingStoreTransaction::abort()
 
     TemporaryChange<bool> change(m_isAborting, true);
 
-    // This loop moves the underlying unique_ptrs from out of the m_deletedObjectStores map,
-    // but the entries in the map still remain.
     for (auto& objectStore : m_deletedObjectStores.values()) {
-        MemoryObjectStore* rawObjectStore = objectStore.get();
-        m_backingStore.restoreObjectStoreForVersionChangeAbort(WTFMove(objectStore));
-
-        ASSERT(!m_objectStores.contains(rawObjectStore));
-        m_objectStores.add(rawObjectStore);
+        m_backingStore.restoreObjectStoreForVersionChangeAbort(*objectStore);
+        ASSERT(!m_objectStores.contains(objectStore.get()));
+        m_objectStores.add(objectStore);
     }
-
-    // This clears the entries from the map.
     m_deletedObjectStores.clear();
 
     if (m_originalDatabaseInfo) {
@@ -206,17 +198,17 @@ void MemoryBackingStoreTransaction::abort()
         iterator.key->replaceIndexValueStore(WTFMove(iterator.value));
     m_clearedIndexValueStores.clear();
     
-    for (auto objectStore : m_objectStores) {
-        ASSERT(m_originalKeyGenerators.contains(objectStore));
-        objectStore->setKeyGeneratorValue(m_originalKeyGenerators.get(objectStore));
+    for (auto& objectStore : m_objectStores) {
+        ASSERT(m_originalKeyGenerators.contains(objectStore.get()));
+        objectStore->setKeyGeneratorValue(m_originalKeyGenerators.get(objectStore.get()));
 
-        auto clearedKeyValueMap = m_clearedKeyValueMaps.take(objectStore);
+        auto clearedKeyValueMap = m_clearedKeyValueMaps.take(objectStore.get());
         if (clearedKeyValueMap) {
-            ASSERT(m_clearedOrderedKeys.contains(objectStore));
-            objectStore->replaceKeyValueStore(WTFMove(clearedKeyValueMap), m_clearedOrderedKeys.take(objectStore));
+            ASSERT(m_clearedOrderedKeys.contains(objectStore.get()));
+            objectStore->replaceKeyValueStore(WTFMove(clearedKeyValueMap), m_clearedOrderedKeys.take(objectStore.get()));
         }
 
-        auto keyValueMap = m_originalValues.take(objectStore);
+        auto keyValueMap = m_originalValues.take(objectStore.get());
         if (!keyValueMap)
             continue;
 
@@ -226,14 +218,8 @@ void MemoryBackingStoreTransaction::abort()
         }
     }
 
-    // This loop moves the underlying unique_ptrs from out of the m_deletedIndexes map,
-    // but the entries in the map still remain.
-    for (auto& index : m_deletedIndexes.values()) {
-        MemoryObjectStore& objectStore = index->objectStore();
-        objectStore.maybeRestoreDeletedIndex(WTFMove(index));
-    }
-
-    // This clears the entries from the map.
+    for (auto& index : m_deletedIndexes.values())
+        index->objectStore().maybeRestoreDeletedIndex(*index);
     m_deletedIndexes.clear();
 
     finish();
index 4c2cf7e..21c97b5 100644 (file)
@@ -62,13 +62,13 @@ public:
     void addExistingObjectStore(MemoryObjectStore&);
     
     void recordValueChanged(MemoryObjectStore&, const IDBKeyData&, ThreadSafeDataBuffer*);
-    void objectStoreDeleted(std::unique_ptr<MemoryObjectStore>);
+    void objectStoreDeleted(Ref<MemoryObjectStore>&&);
     void objectStoreCleared(MemoryObjectStore&, std::unique_ptr<KeyValueMap>&&, std::unique_ptr<std::set<IDBKeyData>>&&);
     void indexCleared(MemoryIndex&, std::unique_ptr<IndexValueStore>&&);
 
     void addNewIndex(MemoryIndex&);
     void addExistingIndex(MemoryIndex&);
-    void indexDeleted(std::unique_ptr<MemoryIndex>);
+    void indexDeleted(Ref<MemoryIndex>&&);
 
     void abort();
     void commit();
@@ -86,14 +86,14 @@ private:
     bool m_inProgress { true };
     bool m_isAborting { false };
 
-    HashSet<MemoryObjectStore*> m_objectStores;
-    HashSet<MemoryObjectStore*> m_versionChangeAddedObjectStores;
-    HashSet<MemoryIndex*> m_indexes;
-    HashSet<MemoryIndex*> m_versionChangeAddedIndexes;
+    HashSet<RefPtr<MemoryObjectStore>> m_objectStores;
+    HashSet<RefPtr<MemoryObjectStore>> m_versionChangeAddedObjectStores;
+    HashSet<RefPtr<MemoryIndex>> m_indexes;
+    HashSet<RefPtr<MemoryIndex>> m_versionChangeAddedIndexes;
 
     HashMap<MemoryObjectStore*, uint64_t> m_originalKeyGenerators;
-    HashMap<String, std::unique_ptr<MemoryObjectStore>> m_deletedObjectStores;
-    HashMap<String, std::unique_ptr<MemoryIndex>> m_deletedIndexes;
+    HashMap<String, RefPtr<MemoryObjectStore>> m_deletedObjectStores;
+    HashMap<String, RefPtr<MemoryIndex>> m_deletedIndexes;
     HashMap<MemoryObjectStore*, std::unique_ptr<KeyValueMap>> m_originalValues;
     HashMap<MemoryObjectStore*, std::unique_ptr<KeyValueMap>> m_clearedKeyValueMaps;
     HashMap<MemoryObjectStore*, std::unique_ptr<std::set<IDBKeyData>>> m_clearedOrderedKeys;
index 1999709..4a09076 100644 (file)
@@ -136,7 +136,7 @@ IDBError MemoryIDBBackingStore::createObjectStore(const IDBResourceIdentifier& t
     ASSERT(rawTransaction);
     ASSERT(rawTransaction->isVersionChange());
 
-    rawTransaction->addNewObjectStore(*objectStore);
+    rawTransaction->addNewObjectStore(objectStore.get());
     registerObjectStore(WTFMove(objectStore));
 
     return IDBError();
@@ -160,7 +160,7 @@ IDBError MemoryIDBBackingStore::deleteObjectStore(const IDBResourceIdentifier& t
         return IDBError(IDBDatabaseException::ConstraintError);
 
     m_databaseInfo->deleteObjectStore(objectStoreName);
-    transaction->objectStoreDeleted(WTFMove(objectStore));
+    transaction->objectStoreDeleted(*objectStore);
 
     return IDBError();
 }
@@ -226,7 +226,7 @@ void MemoryIDBBackingStore::removeObjectStoreForVersionChangeAbort(MemoryObjectS
     unregisterObjectStore(objectStore);
 }
 
-void MemoryIDBBackingStore::restoreObjectStoreForVersionChangeAbort(std::unique_ptr<MemoryObjectStore>&& objectStore)
+void MemoryIDBBackingStore::restoreObjectStoreForVersionChangeAbort(Ref<MemoryObjectStore>&& objectStore)
 {
     registerObjectStore(WTFMove(objectStore));
 }
@@ -428,13 +428,12 @@ IDBError MemoryIDBBackingStore::iterateCursor(const IDBResourceIdentifier& trans
     return { };
 }
 
-void MemoryIDBBackingStore::registerObjectStore(std::unique_ptr<MemoryObjectStore>&& objectStore)
+void MemoryIDBBackingStore::registerObjectStore(Ref<MemoryObjectStore>&& objectStore)
 {
-    ASSERT(objectStore);
     ASSERT(!m_objectStoresByIdentifier.contains(objectStore->info().identifier()));
     ASSERT(!m_objectStoresByName.contains(objectStore->info().name()));
 
-    m_objectStoresByName.set(objectStore->info().name(), objectStore.get());
+    m_objectStoresByName.set(objectStore->info().name(), &objectStore.get());
     m_objectStoresByIdentifier.set(objectStore->info().identifier(), WTFMove(objectStore));
 }
 
@@ -447,13 +446,13 @@ void MemoryIDBBackingStore::unregisterObjectStore(MemoryObjectStore& objectStore
     m_objectStoresByIdentifier.remove(objectStore.info().identifier());
 }
 
-std::unique_ptr<MemoryObjectStore> MemoryIDBBackingStore::takeObjectStoreByName(const String& name)
+RefPtr<MemoryObjectStore> MemoryIDBBackingStore::takeObjectStoreByName(const String& name)
 {
-    auto rawObjectStore = m_objectStoresByName.take(name);
-    if (!rawObjectStore)
+    auto objectStoreByName = m_objectStoresByName.take(name);
+    if (!objectStoreByName)
         return nullptr;
 
-    auto objectStore = m_objectStoresByIdentifier.take(rawObjectStore->info().identifier());
+    auto objectStore = m_objectStoresByIdentifier.take(objectStoreByName->info().identifier());
     ASSERT(objectStore);
 
     return objectStore;
index b14be4f..3cc239b 100644 (file)
@@ -71,21 +71,21 @@ public:
     virtual void deleteBackingStore() override final;
 
     void removeObjectStoreForVersionChangeAbort(MemoryObjectStore&);
-    void restoreObjectStoreForVersionChangeAbort(std::unique_ptr<MemoryObjectStore>&&);
+    void restoreObjectStoreForVersionChangeAbort(Ref<MemoryObjectStore>&&);
 
 private:
     MemoryIDBBackingStore(const IDBDatabaseIdentifier&);
 
-    std::unique_ptr<MemoryObjectStore> takeObjectStoreByName(const String& name);
+    RefPtr<MemoryObjectStore> takeObjectStoreByName(const String& name);
 
     IDBDatabaseIdentifier m_identifier;
     std::unique_ptr<IDBDatabaseInfo> m_databaseInfo;
 
     HashMap<IDBResourceIdentifier, std::unique_ptr<MemoryBackingStoreTransaction>> m_transactions;
 
-    void registerObjectStore(std::unique_ptr<MemoryObjectStore>&&);
+    void registerObjectStore(Ref<MemoryObjectStore>&&);
     void unregisterObjectStore(MemoryObjectStore&);
-    HashMap<uint64_t, std::unique_ptr<MemoryObjectStore>> m_objectStoresByIdentifier;
+    HashMap<uint64_t, RefPtr<MemoryObjectStore>> m_objectStoresByIdentifier;
     HashMap<String, MemoryObjectStore*> m_objectStoresByName;
 };
 
index 9f26df8..cf791c8 100644 (file)
@@ -40,9 +40,9 @@
 namespace WebCore {
 namespace IDBServer {
 
-std::unique_ptr<MemoryIndex> MemoryIndex::create(const IDBIndexInfo& info, MemoryObjectStore& objectStore)
+Ref<MemoryIndex> MemoryIndex::create(const IDBIndexInfo& info, MemoryObjectStore& objectStore)
 {
-    return std::make_unique<MemoryIndex>(info, objectStore);
+    return adoptRef(*new MemoryIndex(info, objectStore));
 }
 
 MemoryIndex::MemoryIndex(const IDBIndexInfo& info, MemoryObjectStore& objectStore)
index f045bcc..7979f23 100644 (file)
@@ -35,6 +35,7 @@
 #include "MemoryIndexCursor.h"
 #include <set>
 #include <wtf/HashMap.h>
+#include <wtf/RefCounted.h>
 
 namespace WebCore {
 
@@ -53,10 +54,9 @@ namespace IDBServer {
 class MemoryBackingStoreTransaction;
 class MemoryObjectStore;
 
-class MemoryIndex {
-    friend std::unique_ptr<MemoryIndex> std::make_unique<MemoryIndex>(const WebCore::IDBIndexInfo&, WebCore::IDBServer::MemoryObjectStore&);
+class MemoryIndex : public RefCounted<MemoryIndex> {
 public:
-    static std::unique_ptr<MemoryIndex> create(const IDBIndexInfo&, MemoryObjectStore&);
+    static Ref<MemoryIndex> create(const IDBIndexInfo&, MemoryObjectStore&);
 
     ~MemoryIndex();
 
index 38ea578..000216c 100644 (file)
@@ -44,9 +44,9 @@ using namespace JSC;
 namespace WebCore {
 namespace IDBServer {
 
-std::unique_ptr<MemoryObjectStore> MemoryObjectStore::create(const IDBObjectStoreInfo& info)
+Ref<MemoryObjectStore> MemoryObjectStore::create(const IDBObjectStoreInfo& info)
 {
-    return std::make_unique<MemoryObjectStore>(info);
+    return adoptRef(*new MemoryObjectStore(info));
 }
 
 MemoryObjectStore::MemoryObjectStore(const IDBObjectStoreInfo& info)
@@ -92,23 +92,21 @@ IDBError MemoryObjectStore::createIndex(MemoryBackingStoreTransaction& transacti
     auto index = MemoryIndex::create(info, *this);
 
     // If there was an error populating the new index, then the current records in the object store violate its contraints
-    auto error = populateIndexWithExistingRecords(*index);
+    auto error = populateIndexWithExistingRecords(index.get());
     if (!error.isNull())
         return error;
 
     m_info.addExistingIndex(info);
-    transaction.addNewIndex(*index);
+    transaction.addNewIndex(index.get());
     registerIndex(WTFMove(index));
 
     return { };
 }
 
-void MemoryObjectStore::maybeRestoreDeletedIndex(std::unique_ptr<MemoryIndex> index)
+void MemoryObjectStore::maybeRestoreDeletedIndex(Ref<MemoryIndex>&& index)
 {
     LOG(IndexedDB, "MemoryObjectStore::maybeRestoreDeletedIndex");
 
-    ASSERT(index);
-
     if (m_info.hasIndex(index->info().name()))
         return;
 
@@ -116,7 +114,7 @@ void MemoryObjectStore::maybeRestoreDeletedIndex(std::unique_ptr<MemoryIndex> in
 
     ASSERT(!m_indexesByIdentifier.contains(index->info().identifier()));
     index->clearIndexValueStore();
-    auto error = populateIndexWithExistingRecords(*index);
+    auto error = populateIndexWithExistingRecords(index.get());
 
     // Since this index was installed in the object store before this transaction started,
     // assuming things were in a valid state then, we should definitely be able to successfully
@@ -126,13 +124,13 @@ void MemoryObjectStore::maybeRestoreDeletedIndex(std::unique_ptr<MemoryIndex> in
     registerIndex(WTFMove(index));
 }
 
-std::unique_ptr<MemoryIndex> MemoryObjectStore::takeIndexByName(const String& name)
+RefPtr<MemoryIndex> MemoryObjectStore::takeIndexByName(const String& name)
 {
-    auto rawIndex = m_indexesByName.take(name);
-    if (!rawIndex)
+    auto indexByName = m_indexesByName.take(name);
+    if (!indexByName)
         return nullptr;
 
-    auto index = m_indexesByIdentifier.take(rawIndex->info().identifier());
+    auto index = m_indexesByIdentifier.take(indexByName->info().identifier());
     ASSERT(index);
 
     return index;
@@ -151,7 +149,7 @@ IDBError MemoryObjectStore::deleteIndex(MemoryBackingStoreTransaction& transacti
         return IDBError(IDBDatabaseException::ConstraintError);
 
     m_info.deleteIndex(indexName);
-    transaction.indexDeleted(WTFMove(index));
+    transaction.indexDeleted(*index);
 
     return { };
 }
@@ -294,7 +292,7 @@ void MemoryObjectStore::updateCursorsForDeleteRecord(const IDBKeyData& key)
 
 void MemoryObjectStore::updateIndexesForDeleteRecord(const IDBKeyData& value)
 {
-    for (auto* index : m_indexesByName.values())
+    for (auto& index : m_indexesByName.values())
         index->removeEntriesWithValueKey(value);
 }
 
@@ -309,7 +307,7 @@ IDBError MemoryObjectStore::updateIndexesForPutRecord(const IDBKeyData& key, con
     IDBError error;
     Vector<std::pair<MemoryIndex*, IndexKey>> changedIndexRecords;
 
-    for (auto* index : m_indexesByName.values()) {
+    for (auto& index : m_indexesByName.values()) {
         IndexKey indexKey;
         generateIndexKeyForValue(UniqueIDBDatabase::databaseThreadExecState(), index->info(), jsValue, indexKey);
 
@@ -320,7 +318,7 @@ IDBError MemoryObjectStore::updateIndexesForPutRecord(const IDBKeyData& key, con
         if (!error.isNull())
             break;
 
-        changedIndexRecords.append(std::make_pair(index, indexKey));
+        changedIndexRecords.append(std::make_pair(index.get(), indexKey));
     }
 
     // If any of the index puts failed, revert all of the ones that went through.
@@ -446,13 +444,12 @@ IDBKeyData MemoryObjectStore::lowestKeyWithRecordInRange(const IDBKeyRangeData&
     return *lowestInRange;
 }
 
-void MemoryObjectStore::registerIndex(std::unique_ptr<MemoryIndex>&& index)
+void MemoryObjectStore::registerIndex(Ref<MemoryIndex>&& index)
 {
-    ASSERT(index);
     ASSERT(!m_indexesByIdentifier.contains(index->info().identifier()));
     ASSERT(!m_indexesByName.contains(index->info().name()));
 
-    m_indexesByName.set(index->info().name(), index.get());
+    m_indexesByName.set(index->info().name(), &index.get());
     m_indexesByIdentifier.set(index->info().identifier(), WTFMove(index));
 }
 
index 8b6e1ab..e806680 100644 (file)
@@ -35,6 +35,7 @@
 #include "ThreadSafeDataBuffer.h"
 #include <set>
 #include <wtf/HashMap.h>
+#include <wtf/RefCounted.h>
 
 namespace WebCore {
 
@@ -54,10 +55,9 @@ class MemoryBackingStoreTransaction;
 
 typedef HashMap<IDBKeyData, ThreadSafeDataBuffer, IDBKeyDataHash, IDBKeyDataHashTraits> KeyValueMap;
 
-class MemoryObjectStore {
-    friend std::unique_ptr<MemoryObjectStore> std::make_unique<MemoryObjectStore>(const WebCore::IDBObjectStoreInfo&);
+class MemoryObjectStore : public RefCounted<MemoryObjectStore> {
 public:
-    static std::unique_ptr<MemoryObjectStore> create(const IDBObjectStoreInfo&);
+    static Ref<MemoryObjectStore> create(const IDBObjectStoreInfo&);
 
     ~MemoryObjectStore();
 
@@ -68,7 +68,7 @@ public:
     IDBError createIndex(MemoryBackingStoreTransaction&, const IDBIndexInfo&);
     IDBError deleteIndex(MemoryBackingStoreTransaction&, const String& indexName);
     void deleteAllIndexes(MemoryBackingStoreTransaction&);
-    void registerIndex(std::unique_ptr<MemoryIndex>&&);
+    void registerIndex(Ref<MemoryIndex>&&);
 
     bool containsRecord(const IDBKeyData&);
     void deleteRecord(const IDBKeyData&);
@@ -94,7 +94,7 @@ public:
 
     MemoryIndex* indexForIdentifier(uint64_t);
 
-    void maybeRestoreDeletedIndex(std::unique_ptr<MemoryIndex>);
+    void maybeRestoreDeletedIndex(Ref<MemoryIndex>&&);
 
 private:
     MemoryObjectStore(const IDBObjectStoreInfo&);
@@ -108,7 +108,7 @@ private:
     void updateCursorsForPutRecord(std::set<IDBKeyData>::iterator);
     void updateCursorsForDeleteRecord(const IDBKeyData&);
 
-    std::unique_ptr<MemoryIndex> takeIndexByName(const String& name);
+    RefPtr<MemoryIndex> takeIndexByName(const String& name);
 
     IDBObjectStoreInfo m_info;
 
@@ -119,8 +119,8 @@ private:
     std::unique_ptr<std::set<IDBKeyData>> m_orderedKeys;
 
     void unregisterIndex(MemoryIndex&);
-    HashMap<uint64_t, std::unique_ptr<MemoryIndex>> m_indexesByIdentifier;
-    HashMap<String, MemoryIndex*> m_indexesByName;
+    HashMap<uint64_t, RefPtr<MemoryIndex>> m_indexesByIdentifier;
+    HashMap<String, RefPtr<MemoryIndex>> m_indexesByName;
     HashMap<IDBResourceIdentifier, std::unique_ptr<MemoryObjectStoreCursor>> m_cursors;
 };