storage/src/mozStorageService.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef MOZSTORAGESERVICE_H
michael@0 8 #define MOZSTORAGESERVICE_H
michael@0 9
michael@0 10 #include "nsCOMPtr.h"
michael@0 11 #include "nsICollation.h"
michael@0 12 #include "nsIFile.h"
michael@0 13 #include "nsIMemoryReporter.h"
michael@0 14 #include "nsIObserver.h"
michael@0 15 #include "nsTArray.h"
michael@0 16 #include "mozilla/Mutex.h"
michael@0 17
michael@0 18 #include "mozIStorageService.h"
michael@0 19
michael@0 20 class nsIMemoryReporter;
michael@0 21 class nsIXPConnect;
michael@0 22 struct sqlite3_vfs;
michael@0 23
michael@0 24 namespace mozilla {
michael@0 25 namespace storage {
michael@0 26
michael@0 27 class Connection;
michael@0 28 class Service : public mozIStorageService
michael@0 29 , public nsIObserver
michael@0 30 , public nsIMemoryReporter
michael@0 31 {
michael@0 32 public:
michael@0 33 /**
michael@0 34 * Initializes the service. This must be called before any other function!
michael@0 35 */
michael@0 36 nsresult initialize();
michael@0 37
michael@0 38 /**
michael@0 39 * Compares two strings using the Service's locale-aware collation.
michael@0 40 *
michael@0 41 * @param aStr1
michael@0 42 * The string to be compared against aStr2.
michael@0 43 * @param aStr2
michael@0 44 * The string to be compared against aStr1.
michael@0 45 * @param aComparisonStrength
michael@0 46 * The sorting strength, one of the nsICollation constants.
michael@0 47 * @return aStr1 - aStr2. That is, if aStr1 < aStr2, returns a negative
michael@0 48 * number. If aStr1 > aStr2, returns a positive number. If
michael@0 49 * aStr1 == aStr2, returns 0.
michael@0 50 */
michael@0 51 int localeCompareStrings(const nsAString &aStr1,
michael@0 52 const nsAString &aStr2,
michael@0 53 int32_t aComparisonStrength);
michael@0 54
michael@0 55 static Service *getSingleton();
michael@0 56
michael@0 57 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 58 NS_DECL_MOZISTORAGESERVICE
michael@0 59 NS_DECL_NSIOBSERVER
michael@0 60 NS_DECL_NSIMEMORYREPORTER
michael@0 61
michael@0 62 /**
michael@0 63 * Obtains an already AddRefed pointer to XPConnect. This is used by
michael@0 64 * language helpers.
michael@0 65 */
michael@0 66 static already_AddRefed<nsIXPConnect> getXPConnect();
michael@0 67
michael@0 68 /**
michael@0 69 * Obtains the cached data for the toolkit.storage.synchronous preference.
michael@0 70 */
michael@0 71 static int32_t getSynchronousPref();
michael@0 72
michael@0 73 /**
michael@0 74 * Obtains the default page size for this platform. The default value is
michael@0 75 * specified in the SQLite makefile (SQLITE_DEFAULT_PAGE_SIZE) but it may be
michael@0 76 * overriden with the PREF_TS_PAGESIZE hidden preference.
michael@0 77 */
michael@0 78 static int32_t getDefaultPageSize()
michael@0 79 {
michael@0 80 return sDefaultPageSize;
michael@0 81 }
michael@0 82
michael@0 83 /**
michael@0 84 * Returns a boolean value indicating whether or not the given page size is
michael@0 85 * valid (currently understood as a power of 2 between 512 and 65536).
michael@0 86 */
michael@0 87 static bool pageSizeIsValid(int32_t aPageSize)
michael@0 88 {
michael@0 89 return aPageSize == 512 || aPageSize == 1024 || aPageSize == 2048 ||
michael@0 90 aPageSize == 4096 || aPageSize == 8192 || aPageSize == 16384 ||
michael@0 91 aPageSize == 32768 || aPageSize == 65536;
michael@0 92 }
michael@0 93
michael@0 94 /**
michael@0 95 * Registers the connection with the storage service. Connections are
michael@0 96 * registered so they can be iterated over.
michael@0 97 *
michael@0 98 * @pre mRegistrationMutex is not held
michael@0 99 *
michael@0 100 * @param aConnection
michael@0 101 * The connection to register.
michael@0 102 */
michael@0 103 void registerConnection(Connection *aConnection);
michael@0 104
michael@0 105 /**
michael@0 106 * Unregisters the connection with the storage service.
michael@0 107 *
michael@0 108 * @pre mRegistrationMutex is not held
michael@0 109 *
michael@0 110 * @param aConnection
michael@0 111 * The connection to unregister.
michael@0 112 */
michael@0 113 void unregisterConnection(Connection *aConnection);
michael@0 114
michael@0 115 /**
michael@0 116 * Gets the list of open connections. Note that you must test each
michael@0 117 * connection with mozIStorageConnection::connectionReady before doing
michael@0 118 * anything with it, and skip it if it's not ready.
michael@0 119 *
michael@0 120 * @pre mRegistrationMutex is not held
michael@0 121 *
michael@0 122 * @param aConnections
michael@0 123 * An inout param; it is cleared and the connections are appended to
michael@0 124 * it.
michael@0 125 * @return The open connections.
michael@0 126 */
michael@0 127 void getConnections(nsTArray<nsRefPtr<Connection> >& aConnections);
michael@0 128
michael@0 129 private:
michael@0 130 Service();
michael@0 131 virtual ~Service();
michael@0 132
michael@0 133 /**
michael@0 134 * Used for 1) locking around calls when initializing connections so that we
michael@0 135 * can ensure that the state of sqlite3_enable_shared_cache is sane and 2)
michael@0 136 * synchronizing access to mLocaleCollation.
michael@0 137 */
michael@0 138 Mutex mMutex;
michael@0 139
michael@0 140 sqlite3_vfs *mSqliteVFS;
michael@0 141
michael@0 142 /**
michael@0 143 * Protects mConnections.
michael@0 144 */
michael@0 145 Mutex mRegistrationMutex;
michael@0 146
michael@0 147 /**
michael@0 148 * The list of connections we have created. Modifications to it are
michael@0 149 * protected by |mRegistrationMutex|.
michael@0 150 */
michael@0 151 nsTArray<nsRefPtr<Connection> > mConnections;
michael@0 152
michael@0 153 /**
michael@0 154 * Frees as much heap memory as possible from all of the known open
michael@0 155 * connections.
michael@0 156 */
michael@0 157 void minimizeMemory();
michael@0 158
michael@0 159 /**
michael@0 160 * Shuts down the storage service, freeing all of the acquired resources.
michael@0 161 */
michael@0 162 void shutdown();
michael@0 163
michael@0 164 /**
michael@0 165 * Lazily creates and returns a collation created from the application's
michael@0 166 * locale that all statements of all Connections of this Service may use.
michael@0 167 * Since the collation's lifetime is that of the Service and no statement may
michael@0 168 * execute outside the lifetime of the Service, this method returns a raw
michael@0 169 * pointer.
michael@0 170 */
michael@0 171 nsICollation *getLocaleCollation();
michael@0 172
michael@0 173 /**
michael@0 174 * Lazily created collation that all statements of all Connections of this
michael@0 175 * Service may use. The collation is created from the application's locale.
michael@0 176 *
michael@0 177 * @note Collation implementations are platform-dependent and in general not
michael@0 178 * thread-safe. Access to this collation should be synchronized.
michael@0 179 */
michael@0 180 nsCOMPtr<nsICollation> mLocaleCollation;
michael@0 181
michael@0 182 nsCOMPtr<nsIFile> mProfileStorageFile;
michael@0 183
michael@0 184 nsCOMPtr<nsIMemoryReporter> mStorageSQLiteReporter;
michael@0 185
michael@0 186 static Service *gService;
michael@0 187
michael@0 188 static nsIXPConnect *sXPConnect;
michael@0 189
michael@0 190 static int32_t sSynchronousPref;
michael@0 191 static int32_t sDefaultPageSize;
michael@0 192 };
michael@0 193
michael@0 194 } // namespace storage
michael@0 195 } // namespace mozilla
michael@0 196
michael@0 197 #endif /* MOZSTORAGESERVICE_H */

mercurial