Bug 1686495 [wpt PR 27132] - Add tests for proposed WebDriver Shadow DOM support...
[gecko.git] / storage / mozIStorageService.idl
blob57368fd08e99274363521b9c3367916a07e63dba
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 interface mozIStorageConnection;
9 interface nsIFile;
10 interface nsIFileURL;
11 interface nsIPropertyBag2;
12 interface nsIVariant;
13 interface mozIStorageCompletionCallback;
15 /**
16 * The mozIStorageService interface is intended to be implemented by
17 * a service that can create storage connections (mozIStorageConnection)
18 * to either a well-known profile database or to a specific database file.
20 * This is the only way to open a database connection.
22 * @note The first reference to mozIStorageService must be made on the main
23 * thread.
25 [scriptable, uuid(07b6b2f5-6d97-47b4-9584-e65bc467fe9e)]
26 interface mozIStorageService : nsISupports {
27 /**
28 * Open an asynchronous connection to a database.
30 * This method MUST be called from the main thread. The connection object
31 * returned by this function is not threadsafe. You MUST use it only from
32 * the main thread.
34 * If you have more than one connection to a file, you MUST use the EXACT
35 * SAME NAME for the file each time, including case. The sqlite code uses
36 * a simple string compare to see if there is already a connection. Opening
37 * a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE.
39 * @param aDatabaseStore Either a nsIFile representing the file that contains
40 * the database or a special string to open a special database. The special
41 * string may be:
42 * - "memory" to open an in-memory database.
44 * @param aOptions A set of options (may be null). Options may contain:
45 * - bool shared (defaults to |false|).
46 * -- If |true|, opens the database with a shared-cache. The
47 * shared-cache mode is more memory-efficient when many
48 * connections to the same database are expected, though, the
49 * connections will contend the cache resource. In any cases
50 * where performance matter, working without a shared-cache will
51 * improve concurrency. @see openUnsharedDatabase
53 * - int growthIncrement (defaults to none).
54 * -- Set the growth increment for the main database. This hints SQLite to
55 * grow the database file by a given chunk size and may reduce
56 * filesystem fragmentation on large databases.
57 * @see mozIStorageConnection::setGrowthIncrement
59 * @param aCallback A callback that will receive the result of the operation.
60 * In case of error, it may receive as status:
61 * - NS_ERROR_OUT_OF_MEMORY if allocating a new storage object fails.
62 * - NS_ERROR_FILE_CORRUPTED if the database file is corrupted.
63 * In case of success, it receives as argument the new database
64 * connection, as an instance of |mozIStorageAsyncConnection|.
66 * @throws NS_ERROR_INVALID_ARG if |aDatabaseStore| is neither a file nor
67 * one of the special strings understood by this method, or if one of
68 * the options passed through |aOptions| does not have the right type.
69 * @throws NS_ERROR_NOT_SAME_THREAD if called from a thread other than the
70 * main thread.
72 void openAsyncDatabase(in nsIVariant aDatabaseStore,
73 [optional] in nsIPropertyBag2 aOptions,
74 in mozIStorageCompletionCallback aCallback);
75 /**
76 * Get a connection to a named special database storage.
78 * @param aStorageKey a string key identifying the type of storage
79 * requested. Valid values include: "memory".
81 * @param aName an optional string identifying the name of the database.
82 * If omitted, a filename of ":memory:" will be used which results in a
83 * private in-memory database specific to this connection, making it
84 * impossible to clone the in-memory database. If you want to be able to
85 * clone the connection (or otherwise connect to the in-memory database from
86 * a connection), then you must pick a name that's sufficiently unique within
87 * the process to not collide with other mozStorage users.
89 * @see openDatabase for restrictions on how database connections may be
90 * used. For the profile database, you should only access it from the main
91 * thread since other callers may also have connections.
93 * @returns a new mozIStorageConnection for the requested
94 * storage database.
96 * @throws NS_ERROR_INVALID_ARG if aStorageKey is invalid.
98 mozIStorageConnection openSpecialDatabase(in ACString aStorageKey,
99 [optional] in ACString aName);
102 * Open a connection to the specified file.
104 * Consumers should check mozIStorageConnection::connectionReady to ensure
105 * that they can use the database. If this value is false, it is strongly
106 * recommended that the database be backed up with
107 * mozIStorageConnection::backupDB so user data is not lost.
109 * ==========
110 * DANGER
111 * ==========
113 * If you have more than one connection to a file, you MUST use the EXACT
114 * SAME NAME for the file each time, including case. The sqlite code uses
115 * a simple string compare to see if there is already a connection. Opening
116 * a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE.
118 * The connection object returned by this function is not threadsafe. You must
119 * use it only from the thread you created it from.
121 * @param aDatabaseFile
122 * A nsIFile that represents the database that is to be opened..
124 * @returns a mozIStorageConnection for the requested database file.
126 * @throws NS_ERROR_OUT_OF_MEMORY
127 * If allocating a new storage object fails.
128 * @throws NS_ERROR_FILE_CORRUPTED
129 * If the database file is corrupted.
131 mozIStorageConnection openDatabase(in nsIFile aDatabaseFile);
134 * Open a connection to the specified file that doesn't share a sqlite cache.
136 * Without a shared-cache, each connection uses its own pages cache, which
137 * may be memory inefficient with a large number of connections, in such a
138 * case so you should use openDatabase instead. On the other side, if cache
139 * contention may be an issue, for instance when concurrency is important to
140 * ensure responsiveness, using unshared connections may be a performance win.
142 * ==========
143 * DANGER
144 * ==========
146 * If you have more than one connection to a file, you MUST use the EXACT
147 * SAME NAME for the file each time, including case. The sqlite code uses
148 * a simple string compare to see if there is already a connection. Opening
149 * a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE.
151 * The connection object returned by this function is not threadsafe. You must
152 * use it only from the thread you created it from.
154 * @param aDatabaseFile
155 * A nsIFile that represents the database that is to be opened.
157 * @returns a mozIStorageConnection for the requested database file.
159 * @throws NS_ERROR_OUT_OF_MEMORY
160 * If allocating a new storage object fails.
161 * @throws NS_ERROR_FILE_CORRUPTED
162 * If the database file is corrupted.
164 mozIStorageConnection openUnsharedDatabase(in nsIFile aDatabaseFile);
167 * See openDatabase(). Exactly the same only initialized with a file URL.
168 * Custom parameters can be passed to SQLite and VFS implementations through
169 * the query part of the URL.
171 * @param aURL
172 * A nsIFileURL that represents the database that is to be opened.
173 * @param [optional] aTelemetryFilename
174 * The name to use for the database in telemetry. Only needed if the
175 * actual filename can contain sensitive information.
177 mozIStorageConnection openDatabaseWithFileURL(in nsIFileURL aFileURL,
178 [optional] in ACString aTelemetryFilename);
181 * Utilities
185 * Copies the specified database file to the specified parent directory with
186 * the specified file name. If the parent directory is not specified, it
187 * places the backup in the same directory as the current file. This function
188 * ensures that the file being created is unique.
190 * @param aDBFile
191 * The database file that will be backed up.
192 * @param aBackupFileName
193 * The name of the new backup file to create.
194 * @param [optional] aBackupParentDirectory
195 * The directory you'd like the backup file to be placed.
196 * @return The nsIFile representing the backup file.
198 nsIFile backupDatabaseFile(in nsIFile aDBFile, in AString aBackupFileName,
199 [optional] in nsIFile aBackupParentDirectory);
202 %{C++
204 constexpr auto kMozStorageMemoryStorageKey = "memory"_ns;