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

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. Created 4 years, 3 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 9349f10380237c95024c5baf0788d9d093d8318c..3d4baf184326b0f3b3981e46276debf2ab262ff0 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"
@@ -52,21 +51,23 @@ class ExceptionState;
class IDBObjectStore final : public GarbageCollectedFinalized<IDBObjectStore>, public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
- static IDBObjectStore* create(const IDBObjectStoreMetadata& metadata, IDBTransaction* transaction)
+ 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; }
+
// Implement the IDBObjectStore IDL
- int64_t id() const { return m_metadata.id; }
- const String& name() const { return m_metadata.name; }
+ int64_t id() const { return metadata().own.id; }
+ const String& name() const { return metadata().own.name; }
void setName(const String& name, ExceptionState&);
ScriptValue keyPath(ScriptState*) const;
DOMStringList* indexNames() const;
IDBTransaction* transaction() const { return m_transaction.get(); }
- bool autoIncrement() const { return m_metadata.autoIncrement; }
+ bool autoIncrement() const { return metadata().own.autoIncrement; }
IDBRequest* openCursor(ScriptState*, const ScriptValue& range, const String& direction, ExceptionState&);
IDBRequest* openKeyCursor(ScriptState*, const ScriptValue& range, const String& direction, ExceptionState&);
@@ -96,43 +97,55 @@ public:
// Used internally and by InspectorIndexedDBAgent:
IDBRequest* openCursor(ScriptState*, IDBKeyRange*, WebIDBCursorDirection, WebIDBTaskType = WebIDBTaskTypeNormal);
- void markDeleted() { m_deleted = true; }
+ void markDeleted();
bool isDeleted() const { return m_deleted; }
- void abort();
void transactionFinished();
- const IDBObjectStoreMetadata& metadata() const { return m_metadata; }
- void setMetadata(const IDBObjectStoreMetadata& metadata) { m_metadata = metadata; }
-
- typedef HeapVector<Member<IDBKey>> IndexKeys;
+ // 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*);
+ IDBObjectStore(RefPtr<IDBObjectStoreMetadata>, IDBTransaction*);
IDBIndex* createIndex(ScriptState*, const String& name, const IDBKeyPath&, const IDBIndexParameters&, ExceptionState&);
IDBRequest* put(ScriptState*, WebIDBPutMode, IDBAny* source, const ScriptValue&, const ScriptValue& key, ExceptionState&);
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;
- typedef HeapHashMap<String, Member<IDBIndex>> IDBIndexMap;
- IDBIndexMap m_indexMap;
-
- // Used to mark indexes created in an aborted upgrade transaction as
- // deleted.
- HeapHashSet<Member<IDBIndex>> m_createdIndexes;
+ // 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.
+ //
+ // The cache may be in an inconsistent state after a transaction is aborted.
+ // index() throws for inactive transactions, which makes the cache not
+ // observable, so reverting the cache would be a waste of resources.
+ using IndexMap = HeapHashMap<String, Member<IDBIndex>>;
+ IndexMap m_indexMap;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698