Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / cache / DBAction.h
blob4bd0c860643f51e1c5e0411a530aaeda0528a0af
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 #ifndef mozilla_dom_cache_DBAction_h
8 #define mozilla_dom_cache_DBAction_h
10 #include "CacheCipherKeyManager.h"
11 #include "mozilla/dom/cache/Action.h"
12 #include "mozilla/RefPtr.h"
13 #include "nsString.h"
15 class mozIStorageConnection;
16 class nsIFile;
18 namespace mozilla::dom::cache {
20 Result<nsCOMPtr<mozIStorageConnection>, nsresult> OpenDBConnection(
21 const CacheDirectoryMetadata& aDirectoryMetadata, nsIFile& aDBFile,
22 const Maybe<CipherKey>& aMaybeCipherKey);
24 class DBAction : public Action {
25 protected:
26 // The mode specifies whether the database should already exist or if its
27 // ok to create a new database.
28 enum Mode { Existing, Create };
30 explicit DBAction(Mode aMode);
32 // Action objects are deleted through their base pointer
33 virtual ~DBAction();
35 // Just as the resolver must be ref'd until resolve, you may also
36 // ref the DB connection. The connection can only be referenced from the
37 // target thread and must be released upon resolve.
38 virtual void RunWithDBOnTarget(
39 SafeRefPtr<Resolver> aResolver,
40 const CacheDirectoryMetadata& aDirectoryMetadata, nsIFile* aDBDir,
41 mozIStorageConnection* aConn) = 0;
43 private:
44 void RunOnTarget(SafeRefPtr<Resolver> aResolver,
45 const Maybe<CacheDirectoryMetadata>& aDirectoryMetadata,
46 Data* aOptionalData,
47 const Maybe<CipherKey>& aMaybeCipherKey) override;
49 Result<nsCOMPtr<mozIStorageConnection>, nsresult> OpenConnection(
50 const CacheDirectoryMetadata& aDirectoryMetadata, nsIFile& aDBDir,
51 const Maybe<CipherKey>& aMaybeCipherKey);
53 const Mode mMode;
56 class SyncDBAction : public DBAction {
57 protected:
58 explicit SyncDBAction(Mode aMode);
60 // Action objects are deleted through their base pointer
61 virtual ~SyncDBAction();
63 virtual nsresult RunSyncWithDBOnTarget(
64 const CacheDirectoryMetadata& aDirectoryMetadata, nsIFile* aDBDir,
65 mozIStorageConnection* aConn) = 0;
67 private:
68 virtual void RunWithDBOnTarget(
69 SafeRefPtr<Resolver> aResolver,
70 const CacheDirectoryMetadata& aDirectoryMetadata, nsIFile* aDBDir,
71 mozIStorageConnection* aConn) override;
74 } // namespace mozilla::dom::cache
76 #endif // mozilla_dom_cache_DBAction_h