no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / cache / Connection.cpp
blobe9c9becebc7e6987f507220f50bedebe9b0377e1
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/cache/Connection.h"
9 #include "mozilla/dom/cache/DBSchema.h"
10 #include "mozStorageHelper.h"
12 namespace mozilla::dom::cache {
14 using mozilla::dom::quota::QuotaObject;
16 NS_IMPL_ISUPPORTS(cache::Connection, mozIStorageAsyncConnection,
17 mozIStorageConnection);
19 Connection::Connection(mozIStorageConnection* aBase)
20 : mBase(aBase), mClosed(false) {
21 MOZ_DIAGNOSTIC_ASSERT(mBase);
24 Connection::~Connection() {
25 NS_ASSERT_OWNINGTHREAD(Connection);
26 MOZ_ALWAYS_SUCCEEDS(Close());
29 NS_IMETHODIMP
30 Connection::Close() {
31 NS_ASSERT_OWNINGTHREAD(Connection);
33 if (mClosed) {
34 return NS_OK;
36 mClosed = true;
38 // If we are closing here, then Cache must not have a transaction
39 // open anywhere else. This may fail if storage is corrupted.
40 Unused << NS_WARN_IF(NS_FAILED(db::IncrementalVacuum(*this)));
42 return mBase->Close();
45 // The following methods are all boilerplate that either forward to the
46 // base connection or block the method. All the async execution methods
47 // are blocked because Cache does not use them and they would require more
48 // work to wrap properly.
50 // mozIStorageAsyncConnection methods
52 NS_IMETHODIMP
53 Connection::AsyncVacuum(mozIStorageCompletionCallback*, bool, int32_t) {
54 // async methods are not supported
55 return NS_ERROR_NOT_IMPLEMENTED;
58 NS_IMETHODIMP
59 Connection::AsyncClose(mozIStorageCompletionCallback*) {
60 // async methods are not supported
61 return NS_ERROR_NOT_IMPLEMENTED;
64 NS_IMETHODIMP
65 Connection::SpinningSynchronousClose() {
66 // not supported
67 return NS_ERROR_NOT_IMPLEMENTED;
70 NS_IMETHODIMP
71 Connection::AsyncClone(bool, mozIStorageCompletionCallback*) {
72 // async methods are not supported
73 return NS_ERROR_NOT_IMPLEMENTED;
76 NS_IMETHODIMP
77 Connection::GetDatabaseFile(nsIFile** aFileOut) {
78 return mBase->GetDatabaseFile(aFileOut);
81 NS_IMETHODIMP
82 Connection::CreateAsyncStatement(const nsACString&,
83 mozIStorageAsyncStatement**) {
84 // async methods are not supported
85 return NS_ERROR_NOT_IMPLEMENTED;
88 NS_IMETHODIMP
89 Connection::ExecuteAsync(const nsTArray<RefPtr<mozIStorageBaseStatement>>&,
90 mozIStorageStatementCallback*,
91 mozIStoragePendingStatement**) {
92 // async methods are not supported
93 return NS_ERROR_NOT_IMPLEMENTED;
96 NS_IMETHODIMP
97 Connection::ExecuteSimpleSQLAsync(const nsACString&,
98 mozIStorageStatementCallback*,
99 mozIStoragePendingStatement**) {
100 // async methods are not supported
101 return NS_ERROR_NOT_IMPLEMENTED;
104 NS_IMETHODIMP
105 Connection::CreateFunction(const nsACString& aFunctionName,
106 int32_t aNumArguments,
107 mozIStorageFunction* aFunction) {
108 // async methods are not supported
109 return NS_ERROR_NOT_IMPLEMENTED;
112 NS_IMETHODIMP
113 Connection::RemoveFunction(const nsACString& aFunctionName) {
114 return mBase->RemoveFunction(aFunctionName);
117 NS_IMETHODIMP
118 Connection::SetProgressHandler(int32_t aGranularity,
119 mozIStorageProgressHandler* aHandler,
120 mozIStorageProgressHandler** aHandlerOut) {
121 return mBase->SetProgressHandler(aGranularity, aHandler, aHandlerOut);
124 NS_IMETHODIMP
125 Connection::RemoveProgressHandler(mozIStorageProgressHandler** aHandlerOut) {
126 return mBase->RemoveProgressHandler(aHandlerOut);
129 // mozIStorageConnection methods
131 NS_IMETHODIMP
132 Connection::Clone(bool aReadOnly, mozIStorageConnection** aConnectionOut) {
133 nsCOMPtr<mozIStorageConnection> conn;
134 nsresult rv = mBase->Clone(aReadOnly, getter_AddRefs(conn));
135 if (NS_WARN_IF(NS_FAILED(rv))) {
136 return rv;
139 nsCOMPtr<mozIStorageConnection> wrapped = new Connection(conn);
140 wrapped.forget(aConnectionOut);
142 return rv;
145 NS_IMETHODIMP
146 Connection::Interrupt() { return mBase->Interrupt(); }
148 NS_IMETHODIMP
149 Connection::GetDefaultPageSize(int32_t* aSizeOut) {
150 return mBase->GetDefaultPageSize(aSizeOut);
153 NS_IMETHODIMP
154 Connection::GetConnectionReady(bool* aReadyOut) {
155 return mBase->GetConnectionReady(aReadyOut);
158 NS_IMETHODIMP
159 Connection::GetLastInsertRowID(int64_t* aRowIdOut) {
160 return mBase->GetLastInsertRowID(aRowIdOut);
163 NS_IMETHODIMP
164 Connection::GetAffectedRows(int32_t* aCountOut) {
165 return mBase->GetAffectedRows(aCountOut);
168 NS_IMETHODIMP
169 Connection::GetLastError(int32_t* aErrorOut) {
170 return mBase->GetLastError(aErrorOut);
173 NS_IMETHODIMP
174 Connection::GetLastErrorString(nsACString& aErrorOut) {
175 return mBase->GetLastErrorString(aErrorOut);
178 NS_IMETHODIMP
179 Connection::GetSchemaVersion(int32_t* aVersionOut) {
180 return mBase->GetSchemaVersion(aVersionOut);
183 NS_IMETHODIMP
184 Connection::SetSchemaVersion(int32_t aVersion) {
185 return mBase->SetSchemaVersion(aVersion);
188 NS_IMETHODIMP
189 Connection::CreateStatement(const nsACString& aQuery,
190 mozIStorageStatement** aStatementOut) {
191 return mBase->CreateStatement(aQuery, aStatementOut);
194 NS_IMETHODIMP
195 Connection::ExecuteSimpleSQL(const nsACString& aQuery) {
196 return mBase->ExecuteSimpleSQL(aQuery);
199 NS_IMETHODIMP
200 Connection::TableExists(const nsACString& aTableName, bool* aExistsOut) {
201 return mBase->TableExists(aTableName, aExistsOut);
204 NS_IMETHODIMP
205 Connection::IndexExists(const nsACString& aIndexName, bool* aExistsOut) {
206 return mBase->IndexExists(aIndexName, aExistsOut);
209 NS_IMETHODIMP
210 Connection::GetTransactionInProgress(bool* aResultOut) {
211 return mBase->GetTransactionInProgress(aResultOut);
214 NS_IMETHODIMP
215 Connection::GetDefaultTransactionType(int32_t* aResultOut) {
216 return mBase->GetDefaultTransactionType(aResultOut);
219 NS_IMETHODIMP
220 Connection::SetDefaultTransactionType(int32_t aType) {
221 return mBase->SetDefaultTransactionType(aType);
224 NS_IMETHODIMP
225 Connection::GetVariableLimit(int32_t* aResultOut) {
226 return mBase->GetVariableLimit(aResultOut);
229 NS_IMETHODIMP
230 Connection::SetVariableLimit(int32_t aLimit) {
231 return mBase->SetVariableLimit(aLimit);
234 NS_IMETHODIMP
235 Connection::BeginTransaction() { return mBase->BeginTransaction(); }
237 NS_IMETHODIMP
238 Connection::CommitTransaction() { return mBase->CommitTransaction(); }
240 NS_IMETHODIMP
241 Connection::RollbackTransaction() { return mBase->RollbackTransaction(); }
243 NS_IMETHODIMP
244 Connection::CreateTable(const char* aTable, const char* aSchema) {
245 return mBase->CreateTable(aTable, aSchema);
248 NS_IMETHODIMP
249 Connection::SetGrowthIncrement(int32_t aIncrement,
250 const nsACString& aDatabase) {
251 return mBase->SetGrowthIncrement(aIncrement, aDatabase);
254 NS_IMETHODIMP
255 Connection::LoadExtension(const nsACString& aExtensionName,
256 mozIStorageCompletionCallback* aCallback) {
257 return mBase->LoadExtension(aExtensionName, aCallback);
259 NS_IMETHODIMP
260 Connection::EnableModule(const nsACString& aModule) {
261 return mBase->EnableModule(aModule);
264 NS_IMETHODIMP
265 Connection::GetQuotaObjects(QuotaObject** aDatabaseQuotaObject,
266 QuotaObject** aJournalQuotaObject) {
267 return mBase->GetQuotaObjects(aDatabaseQuotaObject, aJournalQuotaObject);
270 mozilla::storage::SQLiteMutex& Connection::GetSharedDBMutex() {
271 return mBase->GetSharedDBMutex();
274 uint32_t Connection::GetTransactionNestingLevel(
275 const mozilla::storage::SQLiteMutexAutoLock& aProofOfLock) {
276 return mBase->GetTransactionNestingLevel(aProofOfLock);
279 uint32_t Connection::IncreaseTransactionNestingLevel(
280 const mozilla::storage::SQLiteMutexAutoLock& aProofOfLock) {
281 return mBase->IncreaseTransactionNestingLevel(aProofOfLock);
284 uint32_t Connection::DecreaseTransactionNestingLevel(
285 const mozilla::storage::SQLiteMutexAutoLock& aProofOfLock) {
286 return mBase->DecreaseTransactionNestingLevel(aProofOfLock);
289 NS_IMETHODIMP
290 Connection::BackupToFileAsync(nsIFile* aDestinationFile,
291 mozIStorageCompletionCallback* aCallback) {
292 // async methods are not supported
293 return NS_ERROR_NOT_IMPLEMENTED;
296 } // namespace mozilla::dom::cache