Bumping manifests a=b2g-bump
[gecko.git] / dom / indexedDB / DatabaseInfo.h
blob3b9fa30b3a5d4466b8cb1effe7fbe4ee81c42695
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_indexeddb_databaseinfo_h__
8 #define mozilla_dom_indexeddb_databaseinfo_h__
10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
12 #include "mozilla/dom/quota/PersistenceType.h"
13 #include "nsRefPtrHashtable.h"
14 #include "nsHashKeys.h"
16 #include "mozilla/dom/indexedDB/Key.h"
17 #include "mozilla/dom/indexedDB/KeyPath.h"
18 #include "mozilla/dom/indexedDB/IDBObjectStore.h"
20 BEGIN_INDEXEDDB_NAMESPACE
22 class IndexedDBDatabaseChild;
23 struct ObjectStoreInfo;
25 typedef nsRefPtrHashtable<nsStringHashKey, ObjectStoreInfo>
26 ObjectStoreInfoHash;
28 struct DatabaseInfoGuts
30 typedef mozilla::dom::quota::PersistenceType PersistenceType;
32 DatabaseInfoGuts()
33 : nextObjectStoreId(1), nextIndexId(1)
34 { }
36 bool operator==(const DatabaseInfoGuts& aOther) const
38 return this->name == aOther.name &&
39 this->group == aOther.group &&
40 this->origin == aOther.origin &&
41 this->version == aOther.version &&
42 this->persistenceType == aOther.persistenceType &&
43 this->nextObjectStoreId == aOther.nextObjectStoreId &&
44 this->nextIndexId == aOther.nextIndexId;
47 // Make sure to update ipc/SerializationHelpers.h when changing members here!
48 nsString name;
49 nsCString group;
50 nsCString origin;
51 uint64_t version;
52 PersistenceType persistenceType;
53 int64_t nextObjectStoreId;
54 int64_t nextIndexId;
57 struct DatabaseInfo MOZ_FINAL : public DatabaseInfoGuts
59 DatabaseInfo()
60 : cloned(false)
61 { }
63 private:
64 // Private destructor, to discourage deletion outside of Release():
65 ~DatabaseInfo();
67 public:
68 static bool Get(const nsACString& aId,
69 DatabaseInfo** aInfo);
71 static bool Put(DatabaseInfo* aInfo);
73 static void Remove(const nsACString& aId);
75 bool GetObjectStoreNames(nsTArray<nsString>& aNames);
76 bool ContainsStoreName(const nsAString& aName);
78 ObjectStoreInfo* GetObjectStore(const nsAString& aName);
80 bool PutObjectStore(ObjectStoreInfo* aInfo);
82 void RemoveObjectStore(const nsAString& aName);
84 already_AddRefed<DatabaseInfo> Clone();
86 nsCString id;
87 nsString filePath;
88 bool cloned;
90 nsAutoPtr<ObjectStoreInfoHash> objectStoreHash;
92 NS_INLINE_DECL_REFCOUNTING(DatabaseInfo)
95 struct IndexInfo
97 #ifdef NS_BUILD_REFCNT_LOGGING
98 IndexInfo();
99 IndexInfo(const IndexInfo& aOther);
100 ~IndexInfo();
101 #else
102 IndexInfo()
103 : id(INT64_MIN), keyPath(0), unique(false), multiEntry(false) { }
104 #endif
106 bool operator==(const IndexInfo& aOther) const
108 return this->name == aOther.name &&
109 this->id == aOther.id &&
110 this->keyPath == aOther.keyPath &&
111 this->unique == aOther.unique &&
112 this->multiEntry == aOther.multiEntry;
115 // Make sure to update ipc/SerializationHelpers.h when changing members here!
116 nsString name;
117 int64_t id;
118 KeyPath keyPath;
119 bool unique;
120 bool multiEntry;
123 struct ObjectStoreInfoGuts
125 ObjectStoreInfoGuts()
126 : id(0), keyPath(0), autoIncrement(false)
129 bool operator==(const ObjectStoreInfoGuts& aOther) const
131 return this->name == aOther.name &&
132 this->id == aOther.id;
135 // Make sure to update ipc/SerializationHelpers.h when changing members here!
137 // Constant members, can be gotten on any thread
138 nsString name;
139 int64_t id;
140 KeyPath keyPath;
141 bool autoIncrement;
143 // Main-thread only members. This must *not* be touched on the database
144 // thread.
145 nsTArray<IndexInfo> indexes;
148 struct ObjectStoreInfo MOZ_FINAL : public ObjectStoreInfoGuts
150 #ifdef NS_BUILD_REFCNT_LOGGING
151 ObjectStoreInfo();
152 #else
153 ObjectStoreInfo()
154 : nextAutoIncrementId(0), comittedAutoIncrementId(0) { }
155 #endif
157 ObjectStoreInfo(ObjectStoreInfo& aOther);
159 private:
160 // Private destructor, to discourage deletion outside of Release():
161 #ifdef NS_BUILD_REFCNT_LOGGING
162 ~ObjectStoreInfo();
163 #else
164 ~ObjectStoreInfo() {}
165 #endif
166 public:
168 // Database-thread members. After the ObjectStoreInfo has been initialized,
169 // these can *only* be touced on the database thread.
170 int64_t nextAutoIncrementId;
171 int64_t comittedAutoIncrementId;
173 // This is threadsafe since the ObjectStoreInfos are created on the database
174 // thread but then only used from the main thread. Ideal would be if we
175 // could transfer ownership from the database thread to the main thread, but
176 // we don't have that ability yet.
177 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ObjectStoreInfo)
180 struct IndexUpdateInfo
182 #ifdef NS_BUILD_REFCNT_LOGGING
183 IndexUpdateInfo();
184 IndexUpdateInfo(const IndexUpdateInfo& aOther);
185 ~IndexUpdateInfo();
186 #endif
188 bool operator==(const IndexUpdateInfo& aOther) const
190 return this->indexId == aOther.indexId &&
191 this->indexUnique == aOther.indexUnique &&
192 this->value == aOther.value;
195 // Make sure to update ipc/SerializationHelpers.h when changing members here!
196 int64_t indexId;
197 bool indexUnique;
198 Key value;
201 END_INDEXEDDB_NAMESPACE
203 #endif // mozilla_dom_indexeddb_databaseinfo_h__