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