1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/storage/public/mozIStorageService.idl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,193 @@ 1.4 +/* -*- Mode: idl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsISupports.idl" 1.10 + 1.11 +interface mozIStorageConnection; 1.12 +interface nsIFile; 1.13 +interface nsIFileURL; 1.14 +interface nsIPropertyBag2; 1.15 +interface nsIVariant; 1.16 +interface mozIStorageCompletionCallback; 1.17 + 1.18 +/** 1.19 + * The mozIStorageService interface is intended to be implemented by 1.20 + * a service that can create storage connections (mozIStorageConnection) 1.21 + * to either a well-known profile database or to a specific database file. 1.22 + * 1.23 + * This is the only way to open a database connection. 1.24 + * 1.25 + * @note The first reference to mozIStorageService must be made on the main 1.26 + * thread. 1.27 + */ 1.28 +[scriptable, uuid(07b6b2f5-6d97-47b4-9584-e65bc467fe9e)] 1.29 +interface mozIStorageService : nsISupports { 1.30 + /** 1.31 + * Open an asynchronous connection to a database. 1.32 + * 1.33 + * This method MUST be called from the main thread. The connection object 1.34 + * returned by this function is not threadsafe. You MUST use it only from 1.35 + * the main thread. 1.36 + * 1.37 + * If you have more than one connection to a file, you MUST use the EXACT 1.38 + * SAME NAME for the file each time, including case. The sqlite code uses 1.39 + * a simple string compare to see if there is already a connection. Opening 1.40 + * a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE. 1.41 + * 1.42 + * @param aDatabaseStore Either a nsIFile representing the file that contains 1.43 + * the database or a special string to open a special database. The special 1.44 + * string may be: 1.45 + * - "memory" to open an in-memory database. 1.46 + * 1.47 + * @param aOptions A set of options (may be null). Options may contain: 1.48 + * - bool shared (defaults to |false|). 1.49 + * -- If |true|, opens the database with a shared-cache. The 1.50 + * shared-cache mode is more memory-efficient when many 1.51 + * connections to the same database are expected, though, the 1.52 + * connections will contend the cache resource. In any cases 1.53 + * where performance matter, working without a shared-cache will 1.54 + * improve concurrency. @see openUnsharedDatabase 1.55 + * 1.56 + * - int growthIncrement (defaults to none). 1.57 + * -- Set the growth increment for the main database. This hints SQLite to 1.58 + * grow the database file by a given chunk size and may reduce 1.59 + * filesystem fragmentation on large databases. 1.60 + * @see mozIStorageConnection::setGrowthIncrement 1.61 + * 1.62 + * @param aCallback A callback that will receive the result of the operation. 1.63 + * In case of error, it may receive as status: 1.64 + * - NS_ERROR_OUT_OF_MEMORY if allocating a new storage object fails. 1.65 + * - NS_ERROR_FILE_CORRUPTED if the database file is corrupted. 1.66 + * In case of success, it receives as argument the new database 1.67 + * connection, as an instance of |mozIStorageAsyncConnection|. 1.68 + * 1.69 + * @throws NS_ERROR_INVALID_ARG if |aDatabaseStore| is neither a file nor 1.70 + * one of the special strings understood by this method, or if one of 1.71 + * the options passed through |aOptions| does not have the right type. 1.72 + * @throws NS_ERROR_NOT_SAME_THREAD if called from a thread other than the 1.73 + * main thread. 1.74 + */ 1.75 + void openAsyncDatabase(in nsIVariant aDatabaseStore, 1.76 + [optional] in nsIPropertyBag2 aOptions, 1.77 + in mozIStorageCompletionCallback aCallback); 1.78 + /** 1.79 + * Get a connection to a named special database storage. 1.80 + * 1.81 + * @param aStorageKey a string key identifying the type of storage 1.82 + * requested. Valid values include: "memory". 1.83 + * 1.84 + * @see openDatabase for restrictions on how database connections may be 1.85 + * used. For the profile database, you should only access it from the main 1.86 + * thread since other callers may also have connections. 1.87 + * 1.88 + * @returns a new mozIStorageConnection for the requested 1.89 + * storage database. 1.90 + * 1.91 + * @throws NS_ERROR_INVALID_ARG if aStorageKey is invalid. 1.92 + */ 1.93 + mozIStorageConnection openSpecialDatabase(in string aStorageKey); 1.94 + 1.95 + /** 1.96 + * Open a connection to the specified file. 1.97 + * 1.98 + * Consumers should check mozIStorageConnection::connectionReady to ensure 1.99 + * that they can use the database. If this value is false, it is strongly 1.100 + * recommended that the database be backed up with 1.101 + * mozIStorageConnection::backupDB so user data is not lost. 1.102 + * 1.103 + * ========== 1.104 + * DANGER 1.105 + * ========== 1.106 + * 1.107 + * If you have more than one connection to a file, you MUST use the EXACT 1.108 + * SAME NAME for the file each time, including case. The sqlite code uses 1.109 + * a simple string compare to see if there is already a connection. Opening 1.110 + * a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE. 1.111 + * 1.112 + * The connection object returned by this function is not threadsafe. You must 1.113 + * use it only from the thread you created it from. 1.114 + * 1.115 + * @param aDatabaseFile 1.116 + * A nsIFile that represents the database that is to be opened.. 1.117 + * 1.118 + * @returns a mozIStorageConnection for the requested database file. 1.119 + * 1.120 + * @throws NS_ERROR_OUT_OF_MEMORY 1.121 + * If allocating a new storage object fails. 1.122 + * @throws NS_ERROR_FILE_CORRUPTED 1.123 + * If the database file is corrupted. 1.124 + */ 1.125 + mozIStorageConnection openDatabase(in nsIFile aDatabaseFile); 1.126 + 1.127 + /** 1.128 + * Open a connection to the specified file that doesn't share a sqlite cache. 1.129 + * 1.130 + * Without a shared-cache, each connection uses its own pages cache, which 1.131 + * may be memory inefficient with a large number of connections, in such a 1.132 + * case so you should use openDatabase instead. On the other side, if cache 1.133 + * contention may be an issue, for instance when concurrency is important to 1.134 + * ensure responsiveness, using unshared connections may be a performance win. 1.135 + * 1.136 + * ========== 1.137 + * DANGER 1.138 + * ========== 1.139 + * 1.140 + * If you have more than one connection to a file, you MUST use the EXACT 1.141 + * SAME NAME for the file each time, including case. The sqlite code uses 1.142 + * a simple string compare to see if there is already a connection. Opening 1.143 + * a connection to "Foo.sqlite" and "foo.sqlite" will CORRUPT YOUR DATABASE. 1.144 + * 1.145 + * The connection object returned by this function is not threadsafe. You must 1.146 + * use it only from the thread you created it from. 1.147 + * 1.148 + * @param aDatabaseFile 1.149 + * A nsIFile that represents the database that is to be opened. 1.150 + * 1.151 + * @returns a mozIStorageConnection for the requested database file. 1.152 + * 1.153 + * @throws NS_ERROR_OUT_OF_MEMORY 1.154 + * If allocating a new storage object fails. 1.155 + * @throws NS_ERROR_FILE_CORRUPTED 1.156 + * If the database file is corrupted. 1.157 + */ 1.158 + mozIStorageConnection openUnsharedDatabase(in nsIFile aDatabaseFile); 1.159 + 1.160 + /** 1.161 + * See openDatabase(). Exactly the same only initialized with a file URL. 1.162 + * Custom parameters can be passed to SQLite and VFS implementations through 1.163 + * the query part of the URL. 1.164 + * 1.165 + * @param aURL 1.166 + * A nsIFileURL that represents the database that is to be opened. 1.167 + */ 1.168 + mozIStorageConnection openDatabaseWithFileURL(in nsIFileURL aFileURL); 1.169 + 1.170 + /* 1.171 + * Utilities 1.172 + */ 1.173 + 1.174 + /** 1.175 + * Copies the specified database file to the specified parent directory with 1.176 + * the specified file name. If the parent directory is not specified, it 1.177 + * places the backup in the same directory as the current file. This function 1.178 + * ensures that the file being created is unique. 1.179 + * 1.180 + * @param aDBFile 1.181 + * The database file that will be backed up. 1.182 + * @param aBackupFileName 1.183 + * The name of the new backup file to create. 1.184 + * @param [optional] aBackupParentDirectory 1.185 + * The directory you'd like the backup file to be placed. 1.186 + * @return The nsIFile representing the backup file. 1.187 + */ 1.188 + nsIFile backupDatabaseFile(in nsIFile aDBFile, in AString aBackupFileName, 1.189 + [optional] in nsIFile aBackupParentDirectory); 1.190 +}; 1.191 + 1.192 +%{C++ 1.193 + 1.194 +#define MOZ_STORAGE_MEMORY_STORAGE_KEY "memory" 1.195 + 1.196 +%}