Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Unified Diff: third_party/WebKit/Source/modules/indexeddb/IDBObjectStore.h

Issue 2314933005: Align IndexedDB metadata rollback on transaction abort to spec. (Closed)
Patch Set: Rebased past the big reformat. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/indexeddb/IDBObjectStore.h
diff --git a/third_party/WebKit/Source/modules/indexeddb/IDBObjectStore.h b/third_party/WebKit/Source/modules/indexeddb/IDBObjectStore.h
index 0638156e8541050bc431d88614a05795a7a66a50..dcd0b55abeae4cad7d76e9bbfe745a76e4a16807 100644
--- a/third_party/WebKit/Source/modules/indexeddb/IDBObjectStore.h
+++ b/third_party/WebKit/Source/modules/indexeddb/IDBObjectStore.h
@@ -39,7 +39,6 @@
#include "public/platform/modules/indexeddb/WebIDBCursor.h"
#include "public/platform/modules/indexeddb/WebIDBDatabase.h"
#include "public/platform/modules/indexeddb/WebIDBTypes.h"
-#include "wtf/PassRefPtr.h"
#include "wtf/RefPtr.h"
#include "wtf/text/WTFString.h"
@@ -54,14 +53,14 @@ class IDBObjectStore final : public GarbageCollectedFinalized<IDBObjectStore>,
DEFINE_WRAPPERTYPEINFO();
public:
- static IDBObjectStore* create(const IDBObjectStoreMetadata& metadata,
+ static IDBObjectStore* create(RefPtr<IDBObjectStoreMetadata> metadata,
IDBTransaction* transaction) {
- return new IDBObjectStore(metadata, transaction);
+ return new IDBObjectStore(std::move(metadata), transaction);
}
~IDBObjectStore() {}
DECLARE_TRACE();
- const IDBObjectStoreMetadata& metadata() const { return m_metadata; }
+ const IDBObjectStoreMetadata& metadata() const { return *m_metadata; }
const IDBKeyPath& idbKeyPath() const { return metadata().keyPath; }
// Implement the IDBObjectStore IDL
@@ -137,23 +136,44 @@ class IDBObjectStore final : public GarbageCollectedFinalized<IDBObjectStore>,
void markDeleted();
bool isDeleted() const { return m_deleted; }
- void abort();
- void transactionFinished();
- void setMetadata(const IDBObjectStoreMetadata& metadata) {
- m_metadata = metadata;
- }
+ // Clears the cache used to implement the index() method.
+ //
+ // This should be called when the store's transaction clears its reference
+ // to this IDBObjectStore instance, so the store can clear its references to
+ // IDBIndex instances. This way, Oilpan can garbage-collect the instances
+ // that are not referenced in JavaScript.
+ //
+ // For most stores, the condition above is met when the transaction
+ // finishes. The exception is stores that are created and deleted in the
+ // same transaction. Those stores will remain marked for deletion even if
+ // the transaction aborts, so the transaction can forget about them (and
+ // clear their index caches) right when they are deleted.
+ void clearIndexCache();
+
+ // Sets the object store's metadata to a previous version.
+ //
+ // The reverting process includes reverting the metadata for the IDBIndex
+ // instances that are still tracked by the store. It does not revert the
+ // IDBIndex metadata for indexes that were deleted in this transaction.
+ //
+ // Used when a versionchange transaction is aborted.
+ void revertMetadata(RefPtr<IDBObjectStoreMetadata> previousMetadata);
+ // This relies on the changes made by revertMetadata().
+ void revertDeletedIndexMetadata(IDBIndex& deletedIndex);
// Used by IDBIndex::setName:
bool containsIndex(const String& name) const {
return findIndexId(name) != IDBIndexMetadata::InvalidId;
}
- void indexRenamed(int64_t indexId, const String& newName);
+ void renameIndex(int64_t indexId, const String& newName);
WebIDBDatabase* backendDB() const;
private:
- IDBObjectStore(const IDBObjectStoreMetadata&, IDBTransaction*);
+ using IDBIndexMap = HeapHashMap<String, Member<IDBIndex>>;
+
+ IDBObjectStore(RefPtr<IDBObjectStoreMetadata>, IDBTransaction*);
IDBIndex* createIndex(ScriptState*,
const String& name,
@@ -169,23 +189,25 @@ class IDBObjectStore final : public GarbageCollectedFinalized<IDBObjectStore>,
int64_t findIndexId(const String& name) const;
- IDBObjectStoreMetadata m_metadata;
+ // The IDBObjectStoreMetadata is shared with the object store map in the
+ // database's metadata.
+ RefPtr<IDBObjectStoreMetadata> m_metadata;
Member<IDBTransaction> m_transaction;
bool m_deleted = false;
// Caches the IDBIndex instances returned by the index() method.
+ //
// The spec requires that an object store's index() returns the same
// IDBIndex instance for a specific index, so this cache is necessary
// for correctness.
//
// index() throws for completed/aborted transactions, so this is not used
// after a transaction is finished, and can be cleared.
- using IDBIndexMap = HeapHashMap<String, Member<IDBIndex>>;
IDBIndexMap m_indexMap;
- // Used to mark indexes created in an aborted upgrade transaction as
- // deleted.
- HeapHashSet<Member<IDBIndex>> m_createdIndexes;
+#if DCHECK_IS_ON()
+ bool m_clearIndexCacheCalled = false;
+#endif // DCHECK_IS_ON()
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698