Backed out 2 changesets (bug 1539720) for causing caret related failures. CLOSED...
[gecko.git] / dom / cache / Connection.cpp
bloba2ecba99788381e564131815118293df10591a3c
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::BeginTransaction() { return mBase->BeginTransaction(); }
232 NS_IMETHODIMP
233 Connection::CommitTransaction() { return mBase->CommitTransaction(); }
235 NS_IMETHODIMP
236 Connection::RollbackTransaction() { return mBase->RollbackTransaction(); }
238 NS_IMETHODIMP
239 Connection::CreateTable(const char* aTable, const char* aSchema) {
240 return mBase->CreateTable(aTable, aSchema);
243 NS_IMETHODIMP
244 Connection::SetGrowthIncrement(int32_t aIncrement,
245 const nsACString& aDatabase) {
246 return mBase->SetGrowthIncrement(aIncrement, aDatabase);
249 NS_IMETHODIMP
250 Connection::EnableModule(const nsACString& aModule) {
251 return mBase->EnableModule(aModule);
254 NS_IMETHODIMP
255 Connection::GetQuotaObjects(QuotaObject** aDatabaseQuotaObject,
256 QuotaObject** aJournalQuotaObject) {
257 return mBase->GetQuotaObjects(aDatabaseQuotaObject, aJournalQuotaObject);
260 mozilla::storage::SQLiteMutex& Connection::GetSharedDBMutex() {
261 return mBase->GetSharedDBMutex();
264 uint32_t Connection::GetTransactionNestingLevel(
265 const mozilla::storage::SQLiteMutexAutoLock& aProofOfLock) {
266 return mBase->GetTransactionNestingLevel(aProofOfLock);
269 uint32_t Connection::IncreaseTransactionNestingLevel(
270 const mozilla::storage::SQLiteMutexAutoLock& aProofOfLock) {
271 return mBase->IncreaseTransactionNestingLevel(aProofOfLock);
274 uint32_t Connection::DecreaseTransactionNestingLevel(
275 const mozilla::storage::SQLiteMutexAutoLock& aProofOfLock) {
276 return mBase->DecreaseTransactionNestingLevel(aProofOfLock);
279 } // namespace mozilla::dom::cache