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"
15 class mozIStorageConnection
;
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
{
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
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;
44 void RunOnTarget(SafeRefPtr
<Resolver
> aResolver
,
45 const Maybe
<CacheDirectoryMetadata
>& aDirectoryMetadata
,
47 const Maybe
<CipherKey
>& aMaybeCipherKey
) override
;
49 Result
<nsCOMPtr
<mozIStorageConnection
>, nsresult
> OpenConnection(
50 const CacheDirectoryMetadata
& aDirectoryMetadata
, nsIFile
& aDBDir
,
51 const Maybe
<CipherKey
>& aMaybeCipherKey
);
56 class SyncDBAction
: public DBAction
{
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;
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