|
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/. */ |
|
6 |
|
7 #ifndef mozilla_dom_indexeddb_databaseinfo_h__ |
|
8 #define mozilla_dom_indexeddb_databaseinfo_h__ |
|
9 |
|
10 #include "mozilla/dom/indexedDB/IndexedDatabase.h" |
|
11 |
|
12 #include "mozilla/dom/quota/PersistenceType.h" |
|
13 #include "nsRefPtrHashtable.h" |
|
14 #include "nsHashKeys.h" |
|
15 |
|
16 #include "mozilla/dom/indexedDB/Key.h" |
|
17 #include "mozilla/dom/indexedDB/KeyPath.h" |
|
18 #include "mozilla/dom/indexedDB/IDBObjectStore.h" |
|
19 |
|
20 BEGIN_INDEXEDDB_NAMESPACE |
|
21 |
|
22 class IndexedDBDatabaseChild; |
|
23 struct ObjectStoreInfo; |
|
24 |
|
25 typedef nsRefPtrHashtable<nsStringHashKey, ObjectStoreInfo> |
|
26 ObjectStoreInfoHash; |
|
27 |
|
28 struct DatabaseInfoGuts |
|
29 { |
|
30 typedef mozilla::dom::quota::PersistenceType PersistenceType; |
|
31 |
|
32 DatabaseInfoGuts() |
|
33 : nextObjectStoreId(1), nextIndexId(1) |
|
34 { } |
|
35 |
|
36 bool operator==(const DatabaseInfoGuts& aOther) const |
|
37 { |
|
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; |
|
45 }; |
|
46 |
|
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; |
|
55 }; |
|
56 |
|
57 struct DatabaseInfo MOZ_FINAL : public DatabaseInfoGuts |
|
58 { |
|
59 DatabaseInfo() |
|
60 : cloned(false) |
|
61 { } |
|
62 |
|
63 private: |
|
64 // Private destructor, to discourage deletion outside of Release(): |
|
65 ~DatabaseInfo(); |
|
66 |
|
67 public: |
|
68 static bool Get(const nsACString& aId, |
|
69 DatabaseInfo** aInfo); |
|
70 |
|
71 static bool Put(DatabaseInfo* aInfo); |
|
72 |
|
73 static void Remove(const nsACString& aId); |
|
74 |
|
75 bool GetObjectStoreNames(nsTArray<nsString>& aNames); |
|
76 bool ContainsStoreName(const nsAString& aName); |
|
77 |
|
78 ObjectStoreInfo* GetObjectStore(const nsAString& aName); |
|
79 |
|
80 bool PutObjectStore(ObjectStoreInfo* aInfo); |
|
81 |
|
82 void RemoveObjectStore(const nsAString& aName); |
|
83 |
|
84 already_AddRefed<DatabaseInfo> Clone(); |
|
85 |
|
86 nsCString id; |
|
87 nsString filePath; |
|
88 bool cloned; |
|
89 |
|
90 nsAutoPtr<ObjectStoreInfoHash> objectStoreHash; |
|
91 |
|
92 NS_INLINE_DECL_REFCOUNTING(DatabaseInfo) |
|
93 }; |
|
94 |
|
95 struct IndexInfo |
|
96 { |
|
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 |
|
105 |
|
106 bool operator==(const IndexInfo& aOther) const |
|
107 { |
|
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; |
|
113 }; |
|
114 |
|
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; |
|
121 }; |
|
122 |
|
123 struct ObjectStoreInfoGuts |
|
124 { |
|
125 ObjectStoreInfoGuts() |
|
126 : id(0), keyPath(0), autoIncrement(false) |
|
127 { } |
|
128 |
|
129 bool operator==(const ObjectStoreInfoGuts& aOther) const |
|
130 { |
|
131 return this->name == aOther.name && |
|
132 this->id == aOther.id; |
|
133 }; |
|
134 |
|
135 // Make sure to update ipc/SerializationHelpers.h when changing members here! |
|
136 |
|
137 // Constant members, can be gotten on any thread |
|
138 nsString name; |
|
139 int64_t id; |
|
140 KeyPath keyPath; |
|
141 bool autoIncrement; |
|
142 |
|
143 // Main-thread only members. This must *not* be touched on the database |
|
144 // thread. |
|
145 nsTArray<IndexInfo> indexes; |
|
146 }; |
|
147 |
|
148 struct ObjectStoreInfo MOZ_FINAL : public ObjectStoreInfoGuts |
|
149 { |
|
150 #ifdef NS_BUILD_REFCNT_LOGGING |
|
151 ObjectStoreInfo(); |
|
152 #else |
|
153 ObjectStoreInfo() |
|
154 : nextAutoIncrementId(0), comittedAutoIncrementId(0) { } |
|
155 #endif |
|
156 |
|
157 ObjectStoreInfo(ObjectStoreInfo& aOther); |
|
158 |
|
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: |
|
167 |
|
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; |
|
172 |
|
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) |
|
178 }; |
|
179 |
|
180 struct IndexUpdateInfo |
|
181 { |
|
182 #ifdef NS_BUILD_REFCNT_LOGGING |
|
183 IndexUpdateInfo(); |
|
184 IndexUpdateInfo(const IndexUpdateInfo& aOther); |
|
185 ~IndexUpdateInfo(); |
|
186 #endif |
|
187 |
|
188 bool operator==(const IndexUpdateInfo& aOther) const |
|
189 { |
|
190 return this->indexId == aOther.indexId && |
|
191 this->indexUnique == aOther.indexUnique && |
|
192 this->value == aOther.value; |
|
193 }; |
|
194 |
|
195 // Make sure to update ipc/SerializationHelpers.h when changing members here! |
|
196 int64_t indexId; |
|
197 bool indexUnique; |
|
198 Key value; |
|
199 }; |
|
200 |
|
201 END_INDEXEDDB_NAMESPACE |
|
202 |
|
203 #endif // mozilla_dom_indexeddb_databaseinfo_h__ |