no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / quota / StorageHelpers.h
blobf1830db360b19c6618931c2e63e38d5624dac8a2
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef DOM_QUOTA_QUOTADATABASEHELPER_H
8 #define DOM_QUOTA_QUOTADATABASEHELPER_H
10 #include "mozilla/dom/quota/QuotaCommon.h"
11 #include "mozIStorageConnection.h"
12 #include "nsCOMPtr.h"
13 #include "nsString.h"
15 namespace mozilla::dom::quota {
17 /**
18 * This class provides a RAII wrap of attaching and detaching database
19 * in a given C++ scope. It is guaranteed that an attached database will
20 * be detached even if you have an exception or return early.
22 * @param aConnection
23 * The connection to attach a database to.
24 * @param aDatabaseFile
25 * The database file to attach.
26 * @param aSchemaName
27 * The schema-name. Can be any string literal which is supported by the
28 * underlying database. For more details about schema-name, see
29 * https://www.sqlite.org/lang_attach.html
31 class MOZ_STACK_CLASS AutoDatabaseAttacher final {
32 public:
33 explicit AutoDatabaseAttacher(nsCOMPtr<mozIStorageConnection> aConnection,
34 nsCOMPtr<nsIFile> aDatabaseFile,
35 const nsLiteralCString& aSchemaName);
37 ~AutoDatabaseAttacher();
39 AutoDatabaseAttacher() = delete;
41 [[nodiscard]] nsresult Attach();
43 [[nodiscard]] nsresult Detach();
45 private:
46 nsCOMPtr<mozIStorageConnection> mConnection;
47 nsCOMPtr<nsIFile> mDatabaseFile;
48 const nsLiteralCString mSchemaName;
49 bool mAttached;
52 } // namespace mozilla::dom::quota
54 #endif // DOM_QUOTA_QUOTADATABASEHELPER_H