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 "mozilla/dom/cache/Action.h"
11 #include "mozilla/RefPtr.h"
14 class mozIStorageConnection
;
17 namespace mozilla::dom::cache
{
19 Result
<nsCOMPtr
<mozIStorageConnection
>, nsresult
> OpenDBConnection(
20 const CacheDirectoryMetadata
& aDirectoryMetadata
, nsIFile
& aDBFile
);
22 class DBAction
: public Action
{
24 // The mode specifies whether the database should already exist or if its
25 // ok to create a new database.
26 enum Mode
{ Existing
, Create
};
28 explicit DBAction(Mode aMode
);
30 // Action objects are deleted through their base pointer
33 // Just as the resolver must be ref'd until resolve, you may also
34 // ref the DB connection. The connection can only be referenced from the
35 // target thread and must be released upon resolve.
36 virtual void RunWithDBOnTarget(
37 SafeRefPtr
<Resolver
> aResolver
,
38 const CacheDirectoryMetadata
& aDirectoryMetadata
, nsIFile
* aDBDir
,
39 mozIStorageConnection
* aConn
) = 0;
42 void RunOnTarget(SafeRefPtr
<Resolver
> aResolver
,
43 const Maybe
<CacheDirectoryMetadata
>& aDirectoryMetadata
,
44 Data
* aOptionalData
) override
;
46 Result
<nsCOMPtr
<mozIStorageConnection
>, nsresult
> OpenConnection(
47 const CacheDirectoryMetadata
& aDirectoryMetadata
, nsIFile
& aDBDir
);
52 class SyncDBAction
: public DBAction
{
54 explicit SyncDBAction(Mode aMode
);
56 // Action objects are deleted through their base pointer
57 virtual ~SyncDBAction();
59 virtual nsresult
RunSyncWithDBOnTarget(
60 const CacheDirectoryMetadata
& aDirectoryMetadata
, nsIFile
* aDBDir
,
61 mozIStorageConnection
* aConn
) = 0;
64 virtual void RunWithDBOnTarget(
65 SafeRefPtr
<Resolver
> aResolver
,
66 const CacheDirectoryMetadata
& aDirectoryMetadata
, nsIFile
* aDBDir
,
67 mozIStorageConnection
* aConn
) override
;
70 } // namespace mozilla::dom::cache
72 #endif // mozilla_dom_cache_DBAction_h