michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_indexeddb_databaseinfo_h__ michael@0: #define mozilla_dom_indexeddb_databaseinfo_h__ michael@0: michael@0: #include "mozilla/dom/indexedDB/IndexedDatabase.h" michael@0: michael@0: #include "mozilla/dom/quota/PersistenceType.h" michael@0: #include "nsRefPtrHashtable.h" michael@0: #include "nsHashKeys.h" michael@0: michael@0: #include "mozilla/dom/indexedDB/Key.h" michael@0: #include "mozilla/dom/indexedDB/KeyPath.h" michael@0: #include "mozilla/dom/indexedDB/IDBObjectStore.h" michael@0: michael@0: BEGIN_INDEXEDDB_NAMESPACE michael@0: michael@0: class IndexedDBDatabaseChild; michael@0: struct ObjectStoreInfo; michael@0: michael@0: typedef nsRefPtrHashtable michael@0: ObjectStoreInfoHash; michael@0: michael@0: struct DatabaseInfoGuts michael@0: { michael@0: typedef mozilla::dom::quota::PersistenceType PersistenceType; michael@0: michael@0: DatabaseInfoGuts() michael@0: : nextObjectStoreId(1), nextIndexId(1) michael@0: { } michael@0: michael@0: bool operator==(const DatabaseInfoGuts& aOther) const michael@0: { michael@0: return this->name == aOther.name && michael@0: this->group == aOther.group && michael@0: this->origin == aOther.origin && michael@0: this->version == aOther.version && michael@0: this->persistenceType == aOther.persistenceType && michael@0: this->nextObjectStoreId == aOther.nextObjectStoreId && michael@0: this->nextIndexId == aOther.nextIndexId; michael@0: }; michael@0: michael@0: // Make sure to update ipc/SerializationHelpers.h when changing members here! michael@0: nsString name; michael@0: nsCString group; michael@0: nsCString origin; michael@0: uint64_t version; michael@0: PersistenceType persistenceType; michael@0: int64_t nextObjectStoreId; michael@0: int64_t nextIndexId; michael@0: }; michael@0: michael@0: struct DatabaseInfo MOZ_FINAL : public DatabaseInfoGuts michael@0: { michael@0: DatabaseInfo() michael@0: : cloned(false) michael@0: { } michael@0: michael@0: private: michael@0: // Private destructor, to discourage deletion outside of Release(): michael@0: ~DatabaseInfo(); michael@0: michael@0: public: michael@0: static bool Get(const nsACString& aId, michael@0: DatabaseInfo** aInfo); michael@0: michael@0: static bool Put(DatabaseInfo* aInfo); michael@0: michael@0: static void Remove(const nsACString& aId); michael@0: michael@0: bool GetObjectStoreNames(nsTArray& aNames); michael@0: bool ContainsStoreName(const nsAString& aName); michael@0: michael@0: ObjectStoreInfo* GetObjectStore(const nsAString& aName); michael@0: michael@0: bool PutObjectStore(ObjectStoreInfo* aInfo); michael@0: michael@0: void RemoveObjectStore(const nsAString& aName); michael@0: michael@0: already_AddRefed Clone(); michael@0: michael@0: nsCString id; michael@0: nsString filePath; michael@0: bool cloned; michael@0: michael@0: nsAutoPtr objectStoreHash; michael@0: michael@0: NS_INLINE_DECL_REFCOUNTING(DatabaseInfo) michael@0: }; michael@0: michael@0: struct IndexInfo michael@0: { michael@0: #ifdef NS_BUILD_REFCNT_LOGGING michael@0: IndexInfo(); michael@0: IndexInfo(const IndexInfo& aOther); michael@0: ~IndexInfo(); michael@0: #else michael@0: IndexInfo() michael@0: : id(INT64_MIN), keyPath(0), unique(false), multiEntry(false) { } michael@0: #endif michael@0: michael@0: bool operator==(const IndexInfo& aOther) const michael@0: { michael@0: return this->name == aOther.name && michael@0: this->id == aOther.id && michael@0: this->keyPath == aOther.keyPath && michael@0: this->unique == aOther.unique && michael@0: this->multiEntry == aOther.multiEntry; michael@0: }; michael@0: michael@0: // Make sure to update ipc/SerializationHelpers.h when changing members here! michael@0: nsString name; michael@0: int64_t id; michael@0: KeyPath keyPath; michael@0: bool unique; michael@0: bool multiEntry; michael@0: }; michael@0: michael@0: struct ObjectStoreInfoGuts michael@0: { michael@0: ObjectStoreInfoGuts() michael@0: : id(0), keyPath(0), autoIncrement(false) michael@0: { } michael@0: michael@0: bool operator==(const ObjectStoreInfoGuts& aOther) const michael@0: { michael@0: return this->name == aOther.name && michael@0: this->id == aOther.id; michael@0: }; michael@0: michael@0: // Make sure to update ipc/SerializationHelpers.h when changing members here! michael@0: michael@0: // Constant members, can be gotten on any thread michael@0: nsString name; michael@0: int64_t id; michael@0: KeyPath keyPath; michael@0: bool autoIncrement; michael@0: michael@0: // Main-thread only members. This must *not* be touched on the database michael@0: // thread. michael@0: nsTArray indexes; michael@0: }; michael@0: michael@0: struct ObjectStoreInfo MOZ_FINAL : public ObjectStoreInfoGuts michael@0: { michael@0: #ifdef NS_BUILD_REFCNT_LOGGING michael@0: ObjectStoreInfo(); michael@0: #else michael@0: ObjectStoreInfo() michael@0: : nextAutoIncrementId(0), comittedAutoIncrementId(0) { } michael@0: #endif michael@0: michael@0: ObjectStoreInfo(ObjectStoreInfo& aOther); michael@0: michael@0: private: michael@0: // Private destructor, to discourage deletion outside of Release(): michael@0: #ifdef NS_BUILD_REFCNT_LOGGING michael@0: ~ObjectStoreInfo(); michael@0: #else michael@0: ~ObjectStoreInfo() {} michael@0: #endif michael@0: public: michael@0: michael@0: // Database-thread members. After the ObjectStoreInfo has been initialized, michael@0: // these can *only* be touced on the database thread. michael@0: int64_t nextAutoIncrementId; michael@0: int64_t comittedAutoIncrementId; michael@0: michael@0: // This is threadsafe since the ObjectStoreInfos are created on the database michael@0: // thread but then only used from the main thread. Ideal would be if we michael@0: // could transfer ownership from the database thread to the main thread, but michael@0: // we don't have that ability yet. michael@0: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ObjectStoreInfo) michael@0: }; michael@0: michael@0: struct IndexUpdateInfo michael@0: { michael@0: #ifdef NS_BUILD_REFCNT_LOGGING michael@0: IndexUpdateInfo(); michael@0: IndexUpdateInfo(const IndexUpdateInfo& aOther); michael@0: ~IndexUpdateInfo(); michael@0: #endif michael@0: michael@0: bool operator==(const IndexUpdateInfo& aOther) const michael@0: { michael@0: return this->indexId == aOther.indexId && michael@0: this->indexUnique == aOther.indexUnique && michael@0: this->value == aOther.value; michael@0: }; michael@0: michael@0: // Make sure to update ipc/SerializationHelpers.h when changing members here! michael@0: int64_t indexId; michael@0: bool indexUnique; michael@0: Key value; michael@0: }; michael@0: michael@0: END_INDEXEDDB_NAMESPACE michael@0: michael@0: #endif // mozilla_dom_indexeddb_databaseinfo_h__