storage/public/mozIStorageService.idl

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: idl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsISupports.idl"
michael@0 7
michael@0 8 interface mozIStorageConnection;
michael@0 9 interface nsIFile;
michael@0 10 interface nsIFileURL;
michael@0 11 interface nsIPropertyBag2;
michael@0 12 interface nsIVariant;
michael@0 13 interface mozIStorageCompletionCallback;
michael@0 14
michael@0 15 /**
michael@0 16 * The mozIStorageService interface is intended to be implemented by
michael@0 17 * a service that can create storage connections (mozIStorageConnection)
michael@0 18 * to either a well-known profile database or to a specific database file.
michael@0 19 *
michael@0 20 * This is the only way to open a database connection.
michael@0 21 *
michael@0 22 * @note The first reference to mozIStorageService must be made on the main
michael@0 23 * thread.
michael@0 24 */
michael@0 25 [scriptable, uuid(07b6b2f5-6d97-47b4-9584-e65bc467fe9e)]
michael@0 26 interface mozIStorageService : nsISupports {
michael@0 27 /**
michael@0 28 * Open an asynchronous connection to a database.
michael@0 29 *
michael@0 30 * This method MUST be called from the main thread. The connection object
michael@0 31 * returned by this function is not threadsafe. You MUST use it only from
michael@0 32 * the main thread.
michael@0 33 *
michael@0 34 * If you have more than one connection to a file, you MUST use the EXACT
michael@0 35 * SAME NAME for the file each time, including case. The sqlite code uses
michael@0 36 * a simple string compare to see if there is already a connection. Opening
michael@0 37 * a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE.
michael@0 38 *
michael@0 39 * @param aDatabaseStore Either a nsIFile representing the file that contains
michael@0 40 * the database or a special string to open a special database. The special
michael@0 41 * string may be:
michael@0 42 * - "memory" to open an in-memory database.
michael@0 43 *
michael@0 44 * @param aOptions A set of options (may be null). Options may contain:
michael@0 45 * - bool shared (defaults to |false|).
michael@0 46 * -- If |true|, opens the database with a shared-cache. The
michael@0 47 * shared-cache mode is more memory-efficient when many
michael@0 48 * connections to the same database are expected, though, the
michael@0 49 * connections will contend the cache resource. In any cases
michael@0 50 * where performance matter, working without a shared-cache will
michael@0 51 * improve concurrency. @see openUnsharedDatabase
michael@0 52 *
michael@0 53 * - int growthIncrement (defaults to none).
michael@0 54 * -- Set the growth increment for the main database. This hints SQLite to
michael@0 55 * grow the database file by a given chunk size and may reduce
michael@0 56 * filesystem fragmentation on large databases.
michael@0 57 * @see mozIStorageConnection::setGrowthIncrement
michael@0 58 *
michael@0 59 * @param aCallback A callback that will receive the result of the operation.
michael@0 60 * In case of error, it may receive as status:
michael@0 61 * - NS_ERROR_OUT_OF_MEMORY if allocating a new storage object fails.
michael@0 62 * - NS_ERROR_FILE_CORRUPTED if the database file is corrupted.
michael@0 63 * In case of success, it receives as argument the new database
michael@0 64 * connection, as an instance of |mozIStorageAsyncConnection|.
michael@0 65 *
michael@0 66 * @throws NS_ERROR_INVALID_ARG if |aDatabaseStore| is neither a file nor
michael@0 67 * one of the special strings understood by this method, or if one of
michael@0 68 * the options passed through |aOptions| does not have the right type.
michael@0 69 * @throws NS_ERROR_NOT_SAME_THREAD if called from a thread other than the
michael@0 70 * main thread.
michael@0 71 */
michael@0 72 void openAsyncDatabase(in nsIVariant aDatabaseStore,
michael@0 73 [optional] in nsIPropertyBag2 aOptions,
michael@0 74 in mozIStorageCompletionCallback aCallback);
michael@0 75 /**
michael@0 76 * Get a connection to a named special database storage.
michael@0 77 *
michael@0 78 * @param aStorageKey a string key identifying the type of storage
michael@0 79 * requested. Valid values include: "memory".
michael@0 80 *
michael@0 81 * @see openDatabase for restrictions on how database connections may be
michael@0 82 * used. For the profile database, you should only access it from the main
michael@0 83 * thread since other callers may also have connections.
michael@0 84 *
michael@0 85 * @returns a new mozIStorageConnection for the requested
michael@0 86 * storage database.
michael@0 87 *
michael@0 88 * @throws NS_ERROR_INVALID_ARG if aStorageKey is invalid.
michael@0 89 */
michael@0 90 mozIStorageConnection openSpecialDatabase(in string aStorageKey);
michael@0 91
michael@0 92 /**
michael@0 93 * Open a connection to the specified file.
michael@0 94 *
michael@0 95 * Consumers should check mozIStorageConnection::connectionReady to ensure
michael@0 96 * that they can use the database. If this value is false, it is strongly
michael@0 97 * recommended that the database be backed up with
michael@0 98 * mozIStorageConnection::backupDB so user data is not lost.
michael@0 99 *
michael@0 100 * ==========
michael@0 101 * DANGER
michael@0 102 * ==========
michael@0 103 *
michael@0 104 * If you have more than one connection to a file, you MUST use the EXACT
michael@0 105 * SAME NAME for the file each time, including case. The sqlite code uses
michael@0 106 * a simple string compare to see if there is already a connection. Opening
michael@0 107 * a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE.
michael@0 108 *
michael@0 109 * The connection object returned by this function is not threadsafe. You must
michael@0 110 * use it only from the thread you created it from.
michael@0 111 *
michael@0 112 * @param aDatabaseFile
michael@0 113 * A nsIFile that represents the database that is to be opened..
michael@0 114 *
michael@0 115 * @returns a mozIStorageConnection for the requested database file.
michael@0 116 *
michael@0 117 * @throws NS_ERROR_OUT_OF_MEMORY
michael@0 118 * If allocating a new storage object fails.
michael@0 119 * @throws NS_ERROR_FILE_CORRUPTED
michael@0 120 * If the database file is corrupted.
michael@0 121 */
michael@0 122 mozIStorageConnection openDatabase(in nsIFile aDatabaseFile);
michael@0 123
michael@0 124 /**
michael@0 125 * Open a connection to the specified file that doesn't share a sqlite cache.
michael@0 126 *
michael@0 127 * Without a shared-cache, each connection uses its own pages cache, which
michael@0 128 * may be memory inefficient with a large number of connections, in such a
michael@0 129 * case so you should use openDatabase instead. On the other side, if cache
michael@0 130 * contention may be an issue, for instance when concurrency is important to
michael@0 131 * ensure responsiveness, using unshared connections may be a performance win.
michael@0 132 *
michael@0 133 * ==========
michael@0 134 * DANGER
michael@0 135 * ==========
michael@0 136 *
michael@0 137 * If you have more than one connection to a file, you MUST use the EXACT
michael@0 138 * SAME NAME for the file each time, including case. The sqlite code uses
michael@0 139 * a simple string compare to see if there is already a connection. Opening
michael@0 140 * a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE.
michael@0 141 *
michael@0 142 * The connection object returned by this function is not threadsafe. You must
michael@0 143 * use it only from the thread you created it from.
michael@0 144 *
michael@0 145 * @param aDatabaseFile
michael@0 146 * A nsIFile that represents the database that is to be opened.
michael@0 147 *
michael@0 148 * @returns a mozIStorageConnection for the requested database file.
michael@0 149 *
michael@0 150 * @throws NS_ERROR_OUT_OF_MEMORY
michael@0 151 * If allocating a new storage object fails.
michael@0 152 * @throws NS_ERROR_FILE_CORRUPTED
michael@0 153 * If the database file is corrupted.
michael@0 154 */
michael@0 155 mozIStorageConnection openUnsharedDatabase(in nsIFile aDatabaseFile);
michael@0 156
michael@0 157 /**
michael@0 158 * See openDatabase(). Exactly the same only initialized with a file URL.
michael@0 159 * Custom parameters can be passed to SQLite and VFS implementations through
michael@0 160 * the query part of the URL.
michael@0 161 *
michael@0 162 * @param aURL
michael@0 163 * A nsIFileURL that represents the database that is to be opened.
michael@0 164 */
michael@0 165 mozIStorageConnection openDatabaseWithFileURL(in nsIFileURL aFileURL);
michael@0 166
michael@0 167 /*
michael@0 168 * Utilities
michael@0 169 */
michael@0 170
michael@0 171 /**
michael@0 172 * Copies the specified database file to the specified parent directory with
michael@0 173 * the specified file name. If the parent directory is not specified, it
michael@0 174 * places the backup in the same directory as the current file. This function
michael@0 175 * ensures that the file being created is unique.
michael@0 176 *
michael@0 177 * @param aDBFile
michael@0 178 * The database file that will be backed up.
michael@0 179 * @param aBackupFileName
michael@0 180 * The name of the new backup file to create.
michael@0 181 * @param [optional] aBackupParentDirectory
michael@0 182 * The directory you'd like the backup file to be placed.
michael@0 183 * @return The nsIFile representing the backup file.
michael@0 184 */
michael@0 185 nsIFile backupDatabaseFile(in nsIFile aDBFile, in AString aBackupFileName,
michael@0 186 [optional] in nsIFile aBackupParentDirectory);
michael@0 187 };
michael@0 188
michael@0 189 %{C++
michael@0 190
michael@0 191 #define MOZ_STORAGE_MEMORY_STORAGE_KEY "memory"
michael@0 192
michael@0 193 %}

mercurial