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
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.
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___
43 #include "mozIStorageConnection.h"
44 #include "mozIStorageStatement.h"
45 #include "nsTHashtable.h"
48 class nsSessionStorageEntry
;
50 class nsDOMStoragePersistentDB
53 nsDOMStoragePersistentDB() {}
54 ~nsDOMStoragePersistentDB() {}
57 Init(const nsString
& aDatabaseName
);
60 * Retrieve a list of all the keys associated with a particular domain.
63 GetAllKeys(nsDOMStorage
* aStorage
,
64 nsTHashtable
<nsSessionStorageEntry
>* aKeys
);
67 * Retrieve a value and secure flag for a key from storage.
69 * @throws NS_ERROR_DOM_NOT_FOUND_ERR if key not found
72 GetKeyValue(nsDOMStorage
* aStorage
,
73 const nsAString
& aKey
,
78 * Set the value and secure flag for a key in storage.
81 SetKey(nsDOMStorage
* aStorage
,
82 const nsAString
& aKey
,
83 const nsAString
& aValue
,
86 PRBool aExcludeOfflineFromUsage
,
90 * Set the secure flag for a key in storage. Does nothing if the key was
94 SetSecure(nsDOMStorage
* aStorage
,
95 const nsAString
& aKey
,
96 const PRBool aSecure
);
99 * Removes a key from storage.
102 RemoveKey(nsDOMStorage
* aStorage
,
103 const nsAString
& aKey
,
104 PRBool aExcludeOfflineFromUsage
,
108 * Remove all keys belonging to this storage.
110 nsresult
ClearStorage(nsDOMStorage
* aStorage
);
113 * Removes all keys added by a given domain.
116 RemoveOwner(const nsACString
& aOwner
, PRBool aIncludeSubDomains
);
119 * Removes keys owned by domains that either match or don't match the
123 RemoveOwners(const nsTArray
<nsString
>& aOwners
,
124 PRBool aIncludeSubDomains
, PRBool aMatch
);
127 * Removes all keys from storage. Used when clearing storage.
133 * Returns usage for a storage using its GetQuotaDomainDBKey() as a key.
136 GetUsage(nsDOMStorage
* aStorage
, PRBool aExcludeOfflineFromUsage
, PRInt32
*aUsage
);
139 * Returns usage of the domain and optionaly by any subdomain.
142 GetUsage(const nsACString
& aDomain
, PRBool aIncludeSubDomains
, PRInt32
*aUsage
);
145 * Clears all in-memory data from private browsing mode
147 nsresult
ClearAllPrivateBrowsingData();
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
;
171 GetUsageInternal(const nsACString
& aQuotaDomainDBKey
, PRBool aExcludeOfflineFromUsage
, PRInt32
*aUsage
);
174 #endif /* nsDOMStorageDB_h___ */