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_DBSchema_h
8 #define mozilla_dom_cache_DBSchema_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/cache/Types.h"
14 #include "nsTArrayForwardDeclare.h"
16 class mozIStorageConnection
;
19 namespace mozilla::dom::cache
{
21 class CacheQueryParams
;
29 // Note, this cannot be executed within a transaction.
30 nsresult
CreateOrMigrateSchema(nsIFile
& aDBDir
, mozIStorageConnection
& aConn
);
32 // Note, this cannot be executed within a transaction.
33 nsresult
InitializeConnection(mozIStorageConnection
& aConn
);
35 Result
<CacheId
, nsresult
> CreateCacheId(mozIStorageConnection
& aConn
);
37 Result
<DeletionInfo
, nsresult
> DeleteCacheId(mozIStorageConnection
& aConn
,
40 Result
<AutoTArray
<CacheId
, 8>, nsresult
> FindOrphanedCacheIds(
41 mozIStorageConnection
& aConn
);
43 Result
<int64_t, nsresult
> FindOverallPaddingSize(mozIStorageConnection
& aConn
);
45 Result
<int64_t, nsresult
> GetTotalDiskUsage(mozIStorageConnection
& aConn
);
47 Result
<nsTArray
<nsID
>, nsresult
> GetKnownBodyIds(mozIStorageConnection
& aConn
);
49 Result
<Maybe
<SavedResponse
>, nsresult
> CacheMatch(
50 mozIStorageConnection
& aConn
, CacheId aCacheId
,
51 const CacheRequest
& aRequest
, const CacheQueryParams
& aParams
);
53 Result
<nsTArray
<SavedResponse
>, nsresult
> CacheMatchAll(
54 mozIStorageConnection
& aConn
, CacheId aCacheId
,
55 const Maybe
<CacheRequest
>& aMaybeRequest
, const CacheQueryParams
& aParams
);
57 Result
<DeletionInfo
, nsresult
> CachePut(mozIStorageConnection
& aConn
,
59 const CacheRequest
& aRequest
,
60 const nsID
* aRequestBodyId
,
61 const CacheResponse
& aResponse
,
62 const nsID
* aResponseBodyId
);
64 Result
<Maybe
<DeletionInfo
>, nsresult
> CacheDelete(
65 mozIStorageConnection
& aConn
, CacheId aCacheId
,
66 const CacheRequest
& aRequest
, const CacheQueryParams
& aParams
);
68 Result
<nsTArray
<SavedRequest
>, nsresult
> CacheKeys(
69 mozIStorageConnection
& aConn
, CacheId aCacheId
,
70 const Maybe
<CacheRequest
>& aMaybeRequest
, const CacheQueryParams
& aParams
);
72 Result
<Maybe
<SavedResponse
>, nsresult
> StorageMatch(
73 mozIStorageConnection
& aConn
, Namespace aNamespace
,
74 const CacheRequest
& aRequest
, const CacheQueryParams
& aParams
);
76 Result
<Maybe
<CacheId
>, nsresult
> StorageGetCacheId(mozIStorageConnection
& aConn
,
78 const nsAString
& aKey
);
80 nsresult
StoragePutCache(mozIStorageConnection
& aConn
, Namespace aNamespace
,
81 const nsAString
& aKey
, CacheId aCacheId
);
83 nsresult
StorageForgetCache(mozIStorageConnection
& aConn
, Namespace aNamespace
,
84 const nsAString
& aKey
);
86 Result
<nsTArray
<nsString
>, nsresult
> StorageGetKeys(
87 mozIStorageConnection
& aConn
, Namespace aNamespace
);
89 // Note, this works best when its NOT executed within a transaction.
90 nsresult
IncrementalVacuum(mozIStorageConnection
& aConn
);
92 // We will wipe out databases with a schema versions less than this. Newer
93 // versions will be migrated on open to the latest schema version.
94 extern const int32_t kFirstShippedSchemaVersion
;
97 } // namespace mozilla::dom::cache
99 #endif // mozilla_dom_cache_DBSchema_h