Bug 1828719 - Remove omnijar Gradle project from srcdir r=geckoview-reviewers,nalexan...
[gecko.git] / storage / mozIStorageService.idl
blobba8e291fb9a713b47b3e8b81847db4afe3d47966
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 the database with default flags in default mode.
36 const unsigned long OPEN_DEFAULT = 0;
38 /**
39 * Open the database with a shared cache. The shared-cache mode
40 * is more memory-efficient when many connections to the same database
41 * are expected, though, the connections will contend the cache resource.
42 * When performance matters, working without a shared-cache will
43 * improve concurrency. @see openUnsharedDatabase
45 const unsigned long OPEN_SHARED = 1 << 0;
47 /**
48 * Open the underlying database in read-only mode.
50 const unsigned long OPEN_READONLY = 1 << 1;
52 /**
53 * Allow simultaneous access to an asynchronous read-only database
54 * without any file locking.
56 * For synchronous database, the flag has no effect.
58 * Specifying the OPEN_IGNORE_LOCKING_MODE flag will automatically
59 * turn on the OPEN_READONLY flag.
61 const unsigned long OPEN_IGNORE_LOCKING_MODE = 1 << 2;
63 /**
64 * All optional connection object features are off.
66 const unsigned long CONNECTION_DEFAULT = 0;
68 /**
69 * Enable Interrupt-method for the synchronous connection object
70 * returned by openDatabase, openSpecialDatabase, openUnsharedDatabase
71 * or openDatabaseWithFileURL calls.
73 * When this flag is not set, Interrupt-method of a
74 * synchronous connection must not be used.
76 * Asynchronous connection is always interruptible and the flag
77 * does not change anything.
79 * The following are among the potential risks side effects of
80 * calling the Interrupt-method:
81 * - new queries started on a different thread after the
82 * interrupt call, but before its completion, are interrupted as if
83 * they had been running prior to the interrupt call. Thus thread
84 * synchronization is necessary.
85 * - calls to close the database will wait until the interruption
86 * finishes.
88 const unsigned long CONNECTION_INTERRUPTIBLE = 1 << 0;
90 /**
91 * Open an asynchronous connection to a database.
93 * This method MUST be called from the main thread. The connection object
94 * returned by this function is not threadsafe. You MUST use it only from
95 * the main thread.
97 * If you have more than one connection to a file, you MUST use the EXACT
98 * SAME NAME for the file each time, including case. The sqlite code uses
99 * a simple string compare to see if there is already a connection. Opening
100 * a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE.
102 * @param aDatabaseStore Either a nsIFile representing the file that contains
103 * the database or a special string to open a special database. The special
104 * string may be:
105 * - "memory" to open an in-memory database.
107 * @param [optional] aOpenFlags
108 * A set of flags to open the database with optional features.
109 * Currently supports OPEN_SHARED, OPEN_READONLY and
110 * OPEN_IGNORE_LOCKING_MODE flags.
111 * For full details, please refer to the documentation of the flags.
113 * @param [optional] aConnectionFlags
114 * A set of flags to enable optional features for the returned
115 * asynchronous connection object.
116 * Currently supports CONNECTION_INTERRUPTIBLE flag.
117 * For full details, please refer to the documentation of the flag.
119 * @param aCallback A callback that will receive the result of the operation.
120 * In case of error, it may receive as status:
121 * - NS_ERROR_OUT_OF_MEMORY if allocating a new storage object fails.
122 * - NS_ERROR_FILE_CORRUPTED if the database file is corrupted.
123 * In case of success, it receives as argument the new database
124 * connection, as an instance of |mozIStorageAsyncConnection|.
126 * @throws NS_ERROR_INVALID_ARG if |aDatabaseStore| is neither a file nor
127 * one of the special strings understood by this method, or if one of
128 * the options passed through |aOptions| does not have
129 * the right type.
130 * @throws NS_ERROR_NOT_SAME_THREAD if called from a thread other than the
131 * main thread.
133 void openAsyncDatabase(in nsIVariant aDatabaseStore,
134 [optional] in unsigned long aOpenFlags,
135 [optional] in unsigned long aConnectionFlags,
136 in mozIStorageCompletionCallback aCallback);
139 * Get a connection to a named special database storage.
141 * @param aStorageKey a string key identifying the type of storage
142 * requested. Valid values include: "memory".
144 * @param aName an optional string identifying the name of the database.
145 * If omitted, a filename of ":memory:" will be used which results in a
146 * private in-memory database specific to this connection, making it
147 * impossible to clone the in-memory database. If you want to be able to
148 * clone the connection (or otherwise connect to the in-memory database from
149 * a connection), then you must pick a name that's sufficiently unique within
150 * the process to not collide with other mozStorage users.
152 * @param [optional] aConnectionFlags
153 * A set of flags to enable optional features for the returned
154 * synchronous connection object.
155 * Currently supports CONNECTION_INTERRUPTIBLE flag.
156 * For full details, please refer to the documentation of the flag.
158 * @see openDatabase for restrictions on how database connections may be
159 * used. For the profile database, you should only access it from the main
160 * thread since other callers may also have connections.
162 * @returns a new mozIStorageConnection for the requested
163 * storage database.
165 * @throws NS_ERROR_INVALID_ARG if aStorageKey is invalid.
167 mozIStorageConnection openSpecialDatabase(
168 in ACString aStorageKey,
169 [optional] in ACString aName,
170 [optional] in unsigned long aConnectionFlags);
173 * Open a connection to the specified file.
175 * Consumers should check mozIStorageConnection::connectionReady to ensure
176 * that they can use the database. If this value is false, it is strongly
177 * recommended that the database be backed up with
178 * mozIStorageConnection::backupDB so user data is not lost.
180 * ==========
181 * DANGER
182 * ==========
184 * If you have more than one connection to a file, you MUST use the EXACT
185 * SAME NAME for the file each time, including case. The sqlite code uses
186 * a simple string compare to see if there is already a connection. Opening
187 * a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE.
189 * The connection object returned by this function is not threadsafe. You
190 * must use it only from the thread you created it from.
192 * @param aDatabaseFile
193 * A nsIFile that represents the database that is to be opened.
194 * @param [optional] aConnectionFlags
195 * A set of flags to enable optional features for the returned
196 * synchronous connection object.
197 * Currently supports CONNECTION_INTERRUPTIBLE flag.
198 * For full details, please refer to the documentation of the flag.
200 * @returns a mozIStorageConnection for the requested database file.
202 * @throws NS_ERROR_OUT_OF_MEMORY
203 * If allocating a new storage object fails.
204 * @throws NS_ERROR_FILE_CORRUPTED
205 * If the database file is corrupted.
207 mozIStorageConnection openDatabase(
208 in nsIFile aDatabaseFile, [optional] in unsigned long aConnectionFlags);
211 * Open a connection to the specified file that doesn't share a sqlite cache.
213 * Without a shared-cache, each connection uses its own pages cache, which
214 * may be memory inefficient with a large number of connections, in such a
215 * case so you should use openDatabase instead. On the other side, if cache
216 * contention may be an issue, for instance when concurrency is important to
217 * ensure responsiveness, using unshared connections may be a
218 * performance win.
220 * ==========
221 * DANGER
222 * ==========
224 * If you have more than one connection to a file, you MUST use the EXACT
225 * SAME NAME for the file each time, including case. The sqlite code uses
226 * a simple string compare to see if there is already a connection. Opening
227 * a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE.
229 * The connection object returned by this function is not threadsafe. You
230 * must use it only from the thread you created it from.
232 * @param aDatabaseFile
233 * A nsIFile that represents the database that is to be opened.
234 * @param [optional] aConnectionFlags
235 * A set of flags to enable optional features for the returned
236 * synchronous connection object.
237 * Currently supports CONNECTION_INTERRUPTIBLE flag.
238 * For full details, please refer to the documentation of the flag.
240 * @returns a mozIStorageConnection for the requested database file.
242 * @throws NS_ERROR_OUT_OF_MEMORY
243 * If allocating a new storage object fails.
244 * @throws NS_ERROR_FILE_CORRUPTED
245 * If the database file is corrupted.
247 mozIStorageConnection openUnsharedDatabase(
248 in nsIFile aDatabaseFile, [optional] in unsigned long aConnectionFlags);
251 * See openDatabase(). Exactly the same only initialized with a file URL.
252 * Custom parameters can be passed to SQLite and VFS implementations through
253 * the query part of the URL.
255 * @param aURL
256 * A nsIFileURL that represents the database that is to be opened.
257 * @param [optional] aTelemetryFilename
258 * The name to use for the database in telemetry. Only needed if the
259 * actual filename can contain sensitive information.
260 * @param [optional] aConnectionFlags
261 * A set of flags to enable optional features for the returned
262 * synchronous connection object.
263 * Currently supports CONNECTION_INTERRUPTIBLE flag.
264 * For full details, please refer to the documentation of the flag.
266 mozIStorageConnection openDatabaseWithFileURL(
267 in nsIFileURL aFileURL, [optional] in ACString aTelemetryFilename,
268 [optional] in unsigned long aConnectionFlags);
271 * Utilities
275 * Copies the specified database file to the specified parent directory with
276 * the specified file name. If the parent directory is not specified, it
277 * places the backup in the same directory as the current file. This
278 * function ensures that the file being created is unique.
280 * @param aDBFile
281 * The database file that will be backed up.
282 * @param aBackupFileName
283 * The name of the new backup file to create.
284 * @param [optional] aBackupParentDirectory
285 * The directory you'd like the backup file to be placed.
286 * @return The nsIFile representing the backup file.
288 nsIFile backupDatabaseFile(in nsIFile aDBFile, in AString aBackupFileName,
289 [optional] in nsIFile aBackupParentDirectory);
292 %{C++
294 constexpr auto kMozStorageMemoryStorageKey = "memory"_ns;