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/. */
6
7 #ifndef mozilla_dom_quota_persistencetype_h__
8 #define mozilla_dom_quota_persistencetype_h__
9
10 #include <cstdint>
11 #include "mozilla/Assertions.h"
12 #include "mozilla/Maybe.h"
13 #include "mozilla/dom/StorageTypeBinding.h"
14 #include "mozilla/fallible.h"
15 #include "nsStringFwd.h"
16
17 namespace mozilla::dom::quota {
18
19 enum PersistenceType {
20 PERSISTENCE_TYPE_PERSISTENT = 0,
21 PERSISTENCE_TYPE_TEMPORARY,
22 PERSISTENCE_TYPE_DEFAULT,
23
24 // Only needed for IPC serialization helper, should never be used in code.
25 PERSISTENCE_TYPE_INVALID
26 };
27
28 static const PersistenceType kAllPersistenceTypes[] = {
29 PERSISTENCE_TYPE_PERSISTENT, PERSISTENCE_TYPE_TEMPORARY,
30 PERSISTENCE_TYPE_DEFAULT};
31
32 static const PersistenceType kBestEffortPersistenceTypes[] = {
33 PERSISTENCE_TYPE_TEMPORARY, PERSISTENCE_TYPE_DEFAULT};
34
35 bool IsValidPersistenceType(PersistenceType aPersistenceType);
36
37 bool IsBestEffortPersistenceType(const PersistenceType aPersistenceType);
38
39 nsLiteralCString PersistenceTypeToString(PersistenceType aPersistenceType);
40
41 Maybe<PersistenceType> PersistenceTypeFromString(const nsACString& aString,
42 const fallible_t&);
43
44 PersistenceType PersistenceTypeFromString(const nsACString& aString);
45
46 StorageType PersistenceTypeToStorageType(PersistenceType aPersistenceType);
47
48 PersistenceType PersistenceTypeFromStorageType(StorageType aStorageType);
49
50 Maybe<PersistenceType> PersistenceTypeFromInt32(int32_t aInt32,
51 const fallible_t&);
52
53 // aFile is expected to be a repository directory (not some file or directory
54 // within that).
55 Maybe<PersistenceType> PersistenceTypeFromFile(nsIFile& aFile,
56 const fallible_t&);
57
ComplementaryPersistenceType(const PersistenceType aPersistenceType)58 inline PersistenceType ComplementaryPersistenceType(
59 const PersistenceType aPersistenceType) {
60 MOZ_ASSERT(aPersistenceType == PERSISTENCE_TYPE_DEFAULT ||
61 aPersistenceType == PERSISTENCE_TYPE_TEMPORARY);
62
63 if (aPersistenceType == PERSISTENCE_TYPE_DEFAULT) {
64 return PERSISTENCE_TYPE_TEMPORARY;
65 }
66
67 return PERSISTENCE_TYPE_DEFAULT;
68 }
69
70 } // namespace mozilla::dom::quota
71
72 #endif // mozilla_dom_quota_persistencetype_h__
73