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 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Indexed Database.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * The Mozilla Foundation.
20 : * Portions created by the Initial Developer are Copyright (C) 2010
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Ben Turner <bent.mozilla@gmail.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef mozilla_dom_indexeddb_databaseinfo_h__
41 : #define mozilla_dom_indexeddb_databaseinfo_h__
42 :
43 : // Only meant to be included in IndexedDB source files, not exported.
44 : #include "IndexedDatabase.h"
45 :
46 : #include "Key.h"
47 : #include "IDBObjectStore.h"
48 :
49 : #include "nsRefPtrHashtable.h"
50 : #include "nsHashKeys.h"
51 :
52 : BEGIN_INDEXEDDB_NAMESPACE
53 :
54 : struct ObjectStoreInfo;
55 :
56 : typedef nsRefPtrHashtable<nsStringHashKey, ObjectStoreInfo>
57 : ObjectStoreInfoHash;
58 :
59 : class IDBDatabase;
60 : class OpenDatabaseHelper;
61 :
62 : struct DatabaseInfo
63 : {
64 : friend class IDBDatabase;
65 : friend class OpenDatabaseHelper;
66 :
67 : private:
68 80 : DatabaseInfo()
69 : : nextObjectStoreId(1),
70 : nextIndexId(1),
71 80 : cloned(false)
72 80 : { }
73 : ~DatabaseInfo();
74 :
75 : static bool Get(nsIAtom* aId,
76 : DatabaseInfo** aInfo);
77 :
78 : static bool Put(DatabaseInfo* aInfo);
79 :
80 : public:
81 : static void Remove(nsIAtom* aId);
82 :
83 : static void RemoveAllForOrigin(const nsACString& aOrigin);
84 :
85 : bool GetObjectStoreNames(nsTArray<nsString>& aNames);
86 : bool ContainsStoreName(const nsAString& aName);
87 :
88 : ObjectStoreInfo* GetObjectStore(const nsAString& aName);
89 :
90 : bool PutObjectStore(ObjectStoreInfo* aInfo);
91 :
92 : void RemoveObjectStore(const nsAString& aName);
93 :
94 : already_AddRefed<DatabaseInfo> Clone();
95 :
96 : nsString name;
97 : nsCString origin;
98 : PRUint64 version;
99 : nsCOMPtr<nsIAtom> id;
100 : nsString filePath;
101 : PRInt64 nextObjectStoreId;
102 : PRInt64 nextIndexId;
103 : bool cloned;
104 :
105 : nsAutoPtr<ObjectStoreInfoHash> objectStoreHash;
106 :
107 1362 : NS_INLINE_DECL_REFCOUNTING(DatabaseInfo)
108 : };
109 :
110 : struct IndexInfo
111 : {
112 : #ifdef NS_BUILD_REFCNT_LOGGING
113 : IndexInfo();
114 : IndexInfo(const IndexInfo& aOther);
115 : ~IndexInfo();
116 : #else
117 : IndexInfo()
118 : : id(LL_MININT), unique(false), multiEntry(false) { }
119 : #endif
120 :
121 : PRInt64 id;
122 : nsString name;
123 : nsString keyPath;
124 : nsTArray<nsString> keyPathArray;
125 : bool unique;
126 : bool multiEntry;
127 : };
128 :
129 : struct ObjectStoreInfo
130 : {
131 : #ifdef NS_BUILD_REFCNT_LOGGING
132 : ObjectStoreInfo();
133 : #else
134 : ObjectStoreInfo()
135 : : id(0), nextAutoIncrementId(0), comittedAutoIncrementId(0) { }
136 : #endif
137 :
138 : ObjectStoreInfo(ObjectStoreInfo& aOther);
139 :
140 : private:
141 : #ifdef NS_BUILD_REFCNT_LOGGING
142 : ~ObjectStoreInfo();
143 : #else
144 : ~ObjectStoreInfo() {}
145 : #endif
146 : public:
147 :
148 : // Constant members, can be gotten on any thread
149 : nsString name;
150 : PRInt64 id;
151 : nsString keyPath;
152 : nsTArray<nsString> keyPathArray;
153 :
154 : // Main-thread only members. This must *not* be touced on the database thread
155 : nsTArray<IndexInfo> indexes;
156 :
157 : // Database-thread members. After the ObjectStoreInfo has been initialized,
158 : // these can *only* be touced on the database thread.
159 : PRInt64 nextAutoIncrementId;
160 : PRInt64 comittedAutoIncrementId;
161 :
162 : // This is threadsafe since the ObjectStoreInfos are created on the database
163 : // thread but then only used from the main thread. Ideal would be if we
164 : // could transfer ownership from the database thread to the main thread, but
165 : // we don't have that ability yet.
166 2563 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ObjectStoreInfo)
167 : };
168 :
169 : struct IndexUpdateInfo
170 : {
171 : #ifdef NS_BUILD_REFCNT_LOGGING
172 : IndexUpdateInfo();
173 : ~IndexUpdateInfo();
174 : #endif
175 :
176 : PRInt64 indexId;
177 : bool indexUnique;
178 : Key value;
179 : };
180 :
181 : END_INDEXEDDB_NAMESPACE
182 :
183 : #endif // mozilla_dom_indexeddb_databaseinfo_h__
|