Merge backout.
[mozilla-central.git] / dom / src / storage / nsDOMStoragePersistentDB.h
blob09b639fa44e9efa8a10e18b5a201cf8a8bbbb1ee
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
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/
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.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Mozilla Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2006
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Neil Deakin <enndeakin@sympatico.ca>
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.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef nsDOMStoragePersistentDB_h___
40 #define nsDOMStoragePersistentDB_h___
42 #include "nscore.h"
43 #include "mozIStorageConnection.h"
44 #include "mozIStorageStatement.h"
45 #include "nsTHashtable.h"
47 class nsDOMStorage;
48 class nsSessionStorageEntry;
50 class nsDOMStoragePersistentDB
52 public:
53 nsDOMStoragePersistentDB() {}
54 ~nsDOMStoragePersistentDB() {}
56 nsresult
57 Init(const nsString& aDatabaseName);
59 /**
60 * Retrieve a list of all the keys associated with a particular domain.
62 nsresult
63 GetAllKeys(nsDOMStorage* aStorage,
64 nsTHashtable<nsSessionStorageEntry>* aKeys);
66 /**
67 * Retrieve a value and secure flag for a key from storage.
69 * @throws NS_ERROR_DOM_NOT_FOUND_ERR if key not found
71 nsresult
72 GetKeyValue(nsDOMStorage* aStorage,
73 const nsAString& aKey,
74 nsAString& aValue,
75 PRBool* aSecure);
77 /**
78 * Set the value and secure flag for a key in storage.
80 nsresult
81 SetKey(nsDOMStorage* aStorage,
82 const nsAString& aKey,
83 const nsAString& aValue,
84 PRBool aSecure,
85 PRInt32 aQuota,
86 PRBool aExcludeOfflineFromUsage,
87 PRInt32* aNewUsage);
89 /**
90 * Set the secure flag for a key in storage. Does nothing if the key was
91 * not found.
93 nsresult
94 SetSecure(nsDOMStorage* aStorage,
95 const nsAString& aKey,
96 const PRBool aSecure);
98 /**
99 * Removes a key from storage.
101 nsresult
102 RemoveKey(nsDOMStorage* aStorage,
103 const nsAString& aKey,
104 PRBool aExcludeOfflineFromUsage,
105 PRInt32 aKeyUsage);
108 * Remove all keys belonging to this storage.
110 nsresult ClearStorage(nsDOMStorage* aStorage);
113 * Removes all keys added by a given domain.
115 nsresult
116 RemoveOwner(const nsACString& aOwner, PRBool aIncludeSubDomains);
119 * Removes keys owned by domains that either match or don't match the
120 * list.
122 nsresult
123 RemoveOwners(const nsTArray<nsString>& aOwners,
124 PRBool aIncludeSubDomains, PRBool aMatch);
127 * Removes all keys from storage. Used when clearing storage.
129 nsresult
130 RemoveAll();
133 * Returns usage for a storage using its GetQuotaDomainDBKey() as a key.
135 nsresult
136 GetUsage(nsDOMStorage* aStorage, PRBool aExcludeOfflineFromUsage, PRInt32 *aUsage);
139 * Returns usage of the domain and optionaly by any subdomain.
141 nsresult
142 GetUsage(const nsACString& aDomain, PRBool aIncludeSubDomains, PRInt32 *aUsage);
145 * Clears all in-memory data from private browsing mode
147 nsresult ClearAllPrivateBrowsingData();
149 protected:
151 nsCOMPtr<mozIStorageConnection> mConnection;
153 nsCOMPtr<mozIStorageStatement> mGetAllKeysStatement;
154 nsCOMPtr<mozIStorageStatement> mGetKeyValueStatement;
155 nsCOMPtr<mozIStorageStatement> mInsertKeyStatement;
156 nsCOMPtr<mozIStorageStatement> mUpdateKeyStatement;
157 nsCOMPtr<mozIStorageStatement> mSetSecureStatement;
158 nsCOMPtr<mozIStorageStatement> mRemoveKeyStatement;
159 nsCOMPtr<mozIStorageStatement> mRemoveOwnerStatement;
160 nsCOMPtr<mozIStorageStatement> mRemoveStorageStatement;
161 nsCOMPtr<mozIStorageStatement> mRemoveAllStatement;
162 nsCOMPtr<mozIStorageStatement> mGetOfflineExcludedUsageStatement;
163 nsCOMPtr<mozIStorageStatement> mGetFullUsageStatement;
165 nsCString mCachedOwner;
166 PRInt32 mCachedUsage;
168 friend class nsDOMStorageDBWrapper;
169 friend class nsDOMStorageMemoryDB;
170 nsresult
171 GetUsageInternal(const nsACString& aQuotaDomainDBKey, PRBool aExcludeOfflineFromUsage, PRInt32 *aUsage);
174 #endif /* nsDOMStorageDB_h___ */