tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Connection.cpp (8428B)


      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/. */
      6 
      7 #include "mozilla/dom/cache/Connection.h"
      8 
      9 #include "mozStorageHelper.h"
     10 #include "mozilla/dom/cache/DBSchema.h"
     11 
     12 namespace mozilla::dom::cache {
     13 
     14 using mozilla::dom::quota::QuotaObject;
     15 
     16 NS_IMPL_ISUPPORTS(cache::Connection, mozIStorageAsyncConnection,
     17                  mozIStorageConnection);
     18 
     19 Connection::Connection(mozIStorageConnection* aBase)
     20    : mBase(aBase), mClosed(false) {
     21  MOZ_DIAGNOSTIC_ASSERT(mBase);
     22 }
     23 
     24 Connection::~Connection() {
     25  NS_ASSERT_OWNINGTHREAD(Connection);
     26  MOZ_ALWAYS_SUCCEEDS(Close());
     27 }
     28 
     29 NS_IMETHODIMP
     30 Connection::Close() {
     31  NS_ASSERT_OWNINGTHREAD(Connection);
     32 
     33  if (mClosed) {
     34    return NS_OK;
     35  }
     36  mClosed = true;
     37 
     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  (void)NS_WARN_IF(NS_FAILED(db::IncrementalVacuum(*this)));
     41 
     42  return mBase->Close();
     43 }
     44 
     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.
     49 
     50 // mozIStorageAsyncConnection methods
     51 
     52 NS_IMETHODIMP
     53 Connection::AsyncVacuum(mozIStorageCompletionCallback*, bool, int32_t) {
     54  // async methods are not supported
     55  return NS_ERROR_NOT_IMPLEMENTED;
     56 }
     57 
     58 NS_IMETHODIMP
     59 Connection::AsyncClose(mozIStorageCompletionCallback*) {
     60  // async methods are not supported
     61  return NS_ERROR_NOT_IMPLEMENTED;
     62 }
     63 
     64 NS_IMETHODIMP
     65 Connection::SpinningSynchronousClose() {
     66  // not supported
     67  return NS_ERROR_NOT_IMPLEMENTED;
     68 }
     69 
     70 NS_IMETHODIMP
     71 Connection::AsyncClone(bool, mozIStorageCompletionCallback*) {
     72  // async methods are not supported
     73  return NS_ERROR_NOT_IMPLEMENTED;
     74 }
     75 
     76 NS_IMETHODIMP
     77 Connection::GetDatabaseFile(nsIFile** aFileOut) {
     78  return mBase->GetDatabaseFile(aFileOut);
     79 }
     80 
     81 NS_IMETHODIMP
     82 Connection::CreateAsyncStatement(const nsACString&,
     83                                 mozIStorageAsyncStatement**) {
     84  // async methods are not supported
     85  return NS_ERROR_NOT_IMPLEMENTED;
     86 }
     87 
     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;
     94 }
     95 
     96 NS_IMETHODIMP
     97 Connection::ExecuteSimpleSQLAsync(const nsACString&,
     98                                  mozIStorageStatementCallback*,
     99                                  mozIStoragePendingStatement**) {
    100  // async methods are not supported
    101  return NS_ERROR_NOT_IMPLEMENTED;
    102 }
    103 
    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;
    110 }
    111 
    112 NS_IMETHODIMP
    113 Connection::RemoveFunction(const nsACString& aFunctionName) {
    114  return mBase->RemoveFunction(aFunctionName);
    115 }
    116 
    117 NS_IMETHODIMP
    118 Connection::SetProgressHandler(int32_t aGranularity,
    119                               mozIStorageProgressHandler* aHandler,
    120                               mozIStorageProgressHandler** aHandlerOut) {
    121  return mBase->SetProgressHandler(aGranularity, aHandler, aHandlerOut);
    122 }
    123 
    124 NS_IMETHODIMP
    125 Connection::RemoveProgressHandler(mozIStorageProgressHandler** aHandlerOut) {
    126  return mBase->RemoveProgressHandler(aHandlerOut);
    127 }
    128 
    129 // mozIStorageConnection methods
    130 
    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;
    137  }
    138 
    139  nsCOMPtr<mozIStorageConnection> wrapped = new Connection(conn);
    140  wrapped.forget(aConnectionOut);
    141 
    142  return rv;
    143 }
    144 
    145 NS_IMETHODIMP
    146 Connection::Interrupt() { return mBase->Interrupt(); }
    147 
    148 NS_IMETHODIMP
    149 Connection::GetDefaultPageSize(int32_t* aSizeOut) {
    150  return mBase->GetDefaultPageSize(aSizeOut);
    151 }
    152 
    153 NS_IMETHODIMP
    154 Connection::GetConnectionReady(bool* aReadyOut) {
    155  return mBase->GetConnectionReady(aReadyOut);
    156 }
    157 
    158 NS_IMETHODIMP
    159 Connection::GetLastInsertRowID(int64_t* aRowIdOut) {
    160  return mBase->GetLastInsertRowID(aRowIdOut);
    161 }
    162 
    163 NS_IMETHODIMP
    164 Connection::GetAffectedRows(int32_t* aCountOut) {
    165  return mBase->GetAffectedRows(aCountOut);
    166 }
    167 
    168 NS_IMETHODIMP
    169 Connection::GetLastError(int32_t* aErrorOut) {
    170  return mBase->GetLastError(aErrorOut);
    171 }
    172 
    173 NS_IMETHODIMP
    174 Connection::GetLastErrorString(nsACString& aErrorOut) {
    175  return mBase->GetLastErrorString(aErrorOut);
    176 }
    177 
    178 NS_IMETHODIMP
    179 Connection::GetSchemaVersion(int32_t* aVersionOut) {
    180  return mBase->GetSchemaVersion(aVersionOut);
    181 }
    182 
    183 NS_IMETHODIMP
    184 Connection::SetSchemaVersion(int32_t aVersion) {
    185  return mBase->SetSchemaVersion(aVersion);
    186 }
    187 
    188 NS_IMETHODIMP
    189 Connection::CreateStatement(const nsACString& aQuery,
    190                            mozIStorageStatement** aStatementOut) {
    191  return mBase->CreateStatement(aQuery, aStatementOut);
    192 }
    193 
    194 NS_IMETHODIMP
    195 Connection::ExecuteSimpleSQL(const nsACString& aQuery) {
    196  return mBase->ExecuteSimpleSQL(aQuery);
    197 }
    198 
    199 NS_IMETHODIMP
    200 Connection::TableExists(const nsACString& aTableName, bool* aExistsOut) {
    201  return mBase->TableExists(aTableName, aExistsOut);
    202 }
    203 
    204 NS_IMETHODIMP
    205 Connection::IndexExists(const nsACString& aIndexName, bool* aExistsOut) {
    206  return mBase->IndexExists(aIndexName, aExistsOut);
    207 }
    208 
    209 NS_IMETHODIMP
    210 Connection::GetTransactionInProgress(bool* aResultOut) {
    211  return mBase->GetTransactionInProgress(aResultOut);
    212 }
    213 
    214 NS_IMETHODIMP
    215 Connection::GetDefaultTransactionType(int32_t* aResultOut) {
    216  return mBase->GetDefaultTransactionType(aResultOut);
    217 }
    218 
    219 NS_IMETHODIMP
    220 Connection::SetDefaultTransactionType(int32_t aType) {
    221  return mBase->SetDefaultTransactionType(aType);
    222 }
    223 
    224 NS_IMETHODIMP
    225 Connection::GetVariableLimit(int32_t* aResultOut) {
    226  return mBase->GetVariableLimit(aResultOut);
    227 }
    228 
    229 NS_IMETHODIMP
    230 Connection::SetVariableLimit(int32_t aLimit) {
    231  return mBase->SetVariableLimit(aLimit);
    232 }
    233 
    234 NS_IMETHODIMP
    235 Connection::BeginTransaction() { return mBase->BeginTransaction(); }
    236 
    237 NS_IMETHODIMP
    238 Connection::CommitTransaction() { return mBase->CommitTransaction(); }
    239 
    240 NS_IMETHODIMP
    241 Connection::RollbackTransaction() { return mBase->RollbackTransaction(); }
    242 
    243 NS_IMETHODIMP
    244 Connection::CreateTable(const char* aTable, const char* aSchema) {
    245  return mBase->CreateTable(aTable, aSchema);
    246 }
    247 
    248 NS_IMETHODIMP
    249 Connection::SetGrowthIncrement(int32_t aIncrement,
    250                               const nsACString& aDatabase) {
    251  return mBase->SetGrowthIncrement(aIncrement, aDatabase);
    252 }
    253 
    254 NS_IMETHODIMP
    255 Connection::LoadExtension(const nsACString& aExtensionName,
    256                          mozIStorageCompletionCallback* aCallback) {
    257  return mBase->LoadExtension(aExtensionName, aCallback);
    258 }
    259 NS_IMETHODIMP
    260 Connection::EnableModule(const nsACString& aModule) {
    261  return mBase->EnableModule(aModule);
    262 }
    263 
    264 NS_IMETHODIMP
    265 Connection::GetQuotaObjects(QuotaObject** aDatabaseQuotaObject,
    266                            QuotaObject** aJournalQuotaObject) {
    267  return mBase->GetQuotaObjects(aDatabaseQuotaObject, aJournalQuotaObject);
    268 }
    269 
    270 mozilla::storage::SQLiteMutex& Connection::GetSharedDBMutex() {
    271  return mBase->GetSharedDBMutex();
    272 }
    273 
    274 uint32_t Connection::GetTransactionNestingLevel(
    275    const mozilla::storage::SQLiteMutexAutoLock& aProofOfLock) {
    276  return mBase->GetTransactionNestingLevel(aProofOfLock);
    277 }
    278 
    279 uint32_t Connection::IncreaseTransactionNestingLevel(
    280    const mozilla::storage::SQLiteMutexAutoLock& aProofOfLock) {
    281  return mBase->IncreaseTransactionNestingLevel(aProofOfLock);
    282 }
    283 
    284 uint32_t Connection::DecreaseTransactionNestingLevel(
    285    const mozilla::storage::SQLiteMutexAutoLock& aProofOfLock) {
    286  return mBase->DecreaseTransactionNestingLevel(aProofOfLock);
    287 }
    288 
    289 NS_IMETHODIMP
    290 Connection::BackupToFileAsync(nsIFile* aDestinationFile,
    291                              mozIStorageCompletionCallback* aCallback,
    292                              uint32_t aPagesPerStep, uint32_t aStepDelayMs) {
    293  // async methods are not supported
    294  return NS_ERROR_NOT_IMPLEMENTED;
    295 }
    296 
    297 }  // namespace mozilla::dom::cache