1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Mozilla Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 2009
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Honza Bambas <honzab@firemni.cz>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef nsDOMStorageMemoryDB_h___
40 : #define nsDOMStorageMemoryDB_h___
41 :
42 : #include "nscore.h"
43 : #include "nsDOMStorageBaseDB.h"
44 : #include "nsClassHashtable.h"
45 : #include "nsDataHashtable.h"
46 :
47 : class nsDOMStoragePersistentDB;
48 :
49 : class nsDOMStorageMemoryDB : public nsDOMStorageBaseDB
50 : {
51 : public:
52 154 : nsDOMStorageMemoryDB() : mPreloading(false) {}
53 308 : ~nsDOMStorageMemoryDB() {}
54 :
55 : class nsInMemoryItem
56 0 : {
57 : public:
58 : bool mSecure;
59 : nsString mValue;
60 : };
61 :
62 : typedef nsClassHashtable<nsStringHashKey, nsInMemoryItem> nsStorageItemsTable;
63 :
64 : class nsInMemoryStorage
65 0 : {
66 : public:
67 : nsStorageItemsTable mTable;
68 : PRInt32 mUsageDelta;
69 :
70 0 : nsInMemoryStorage() : mUsageDelta(0) {}
71 : };
72 :
73 : /**
74 : * @param aPreloadDB
75 : * If non-null, data for a domain/origin will be preloaded from
76 : * the provided database. Used for session-only cookies mode to
77 : * provide existing data from the persistent database.
78 : */
79 : nsresult
80 : Init(nsDOMStoragePersistentDB* aPreloadDB = nsnull);
81 :
82 : /**
83 : *
84 : */
85 : nsresult
86 : GetItemsTable(DOMStorageImpl* aStorage,
87 : nsInMemoryStorage** aMemoryStorage);
88 :
89 : /**
90 : * Retrieve a list of all the keys associated with a particular domain.
91 : */
92 : nsresult
93 : GetAllKeys(DOMStorageImpl* aStorage,
94 : nsTHashtable<nsSessionStorageEntry>* aKeys);
95 :
96 : /**
97 : * Retrieve a value and secure flag for a key from storage.
98 : *
99 : * @throws NS_ERROR_DOM_NOT_FOUND_ERR if key not found
100 : */
101 : nsresult
102 : GetKeyValue(DOMStorageImpl* aStorage,
103 : const nsAString& aKey,
104 : nsAString& aValue,
105 : bool* aSecure);
106 :
107 : /**
108 : * Set the value and secure flag for a key in storage.
109 : */
110 : nsresult
111 : SetKey(DOMStorageImpl* aStorage,
112 : const nsAString& aKey,
113 : const nsAString& aValue,
114 : bool aSecure,
115 : PRInt32 aQuota,
116 : bool aExcludeOfflineFromUsage,
117 : PRInt32* aNewUsage);
118 :
119 : /**
120 : * Set the secure flag for a key in storage. Does nothing if the key was
121 : * not found.
122 : */
123 : nsresult
124 : SetSecure(DOMStorageImpl* aStorage,
125 : const nsAString& aKey,
126 : const bool aSecure);
127 :
128 : /**
129 : * Removes a key from storage.
130 : */
131 : nsresult
132 : RemoveKey(DOMStorageImpl* aStorage,
133 : const nsAString& aKey,
134 : bool aExcludeOfflineFromUsage,
135 : PRInt32 aKeyUsage);
136 :
137 : /**
138 : * Remove all keys belonging to this storage.
139 : */
140 : nsresult
141 : ClearStorage(DOMStorageImpl* aStorage);
142 :
143 : /**
144 : * If we have changed the persistent storage, drop any potential session storages
145 : */
146 : nsresult
147 : DropStorage(DOMStorageImpl* aStorage);
148 :
149 : /**
150 : * Removes all keys added by a given domain.
151 : */
152 : nsresult
153 : RemoveOwner(const nsACString& aOwner, bool aIncludeSubDomains);
154 :
155 : /**
156 : * Removes keys owned by domains that either match or don't match the
157 : * list.
158 : */
159 : nsresult
160 : RemoveOwners(const nsTArray<nsString>& aOwners,
161 : bool aIncludeSubDomains, bool aMatch);
162 :
163 : /**
164 : * Removes all keys from storage. Used when clearing storage.
165 : */
166 : nsresult
167 : RemoveAll();
168 :
169 : /**
170 : * Returns usage for a storage using its GetQuotaDomainDBKey() as a key.
171 : */
172 : nsresult
173 : GetUsage(DOMStorageImpl* aStorage, bool aExcludeOfflineFromUsage, PRInt32 *aUsage);
174 :
175 : /**
176 : * Returns usage of the domain and optionaly by any subdomain.
177 : */
178 : nsresult
179 : GetUsage(const nsACString& aDomain, bool aIncludeSubDomains, PRInt32 *aUsage);
180 :
181 : protected:
182 :
183 : nsClassHashtable<nsCStringHashKey, nsInMemoryStorage> mData;
184 : nsDOMStoragePersistentDB* mPreloadDB;
185 : bool mPreloading;
186 :
187 : nsresult
188 : GetUsageInternal(const nsACString& aQuotaDomainDBKey, bool aExcludeOfflineFromUsage, PRInt32 *aUsage);
189 : };
190 :
191 : #endif
|