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
>
28 struct DatabaseInfoGuts
30 typedef mozilla::dom::quota::PersistenceType PersistenceType
;
33 : nextObjectStoreId(1), nextIndexId(1)
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!
52 PersistenceType persistenceType
;
53 int64_t nextObjectStoreId
;
57 struct DatabaseInfo MOZ_FINAL
: public DatabaseInfoGuts
64 // Private destructor, to discourage deletion outside of Release():
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();
90 nsAutoPtr
<ObjectStoreInfoHash
> objectStoreHash
;
92 NS_INLINE_DECL_REFCOUNTING(DatabaseInfo
)
97 #ifdef NS_BUILD_REFCNT_LOGGING
99 IndexInfo(const IndexInfo
& aOther
);
103 : id(INT64_MIN
), keyPath(0), unique(false), multiEntry(false) { }
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!
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
143 // Main-thread only members. This must *not* be touched on the database
145 nsTArray
<IndexInfo
> indexes
;
148 struct ObjectStoreInfo MOZ_FINAL
: public ObjectStoreInfoGuts
150 #ifdef NS_BUILD_REFCNT_LOGGING
154 : nextAutoIncrementId(0), comittedAutoIncrementId(0) { }
157 ObjectStoreInfo(ObjectStoreInfo
& aOther
);
160 // Private destructor, to discourage deletion outside of Release():
161 #ifdef NS_BUILD_REFCNT_LOGGING
164 ~ObjectStoreInfo() {}
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
184 IndexUpdateInfo(const IndexUpdateInfo
& aOther
);
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!
201 END_INDEXEDDB_NAMESPACE
203 #endif // mozilla_dom_indexeddb_databaseinfo_h__