summaryrefslogtreecommitdiffstats
path: root/dom/quota/PersistenceType.h
blob: dd2f09ecbdf387a52b0e4edc06219d4b7396cd18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_dom_quota_persistencetype_h__
#define mozilla_dom_quota_persistencetype_h__

#include <array>
#include <cstdint>
#include "mozilla/Assertions.h"
#include "mozilla/Maybe.h"
#include "mozilla/fallible.h"
#include "nsStringFwd.h"

class nsIFile;

namespace mozilla::dom::quota {

enum PersistenceType {
  PERSISTENCE_TYPE_PERSISTENT = 0,
  PERSISTENCE_TYPE_TEMPORARY,
  PERSISTENCE_TYPE_DEFAULT,
  PERSISTENCE_TYPE_PRIVATE,

  // Only needed for IPC serialization helper, should never be used in code.
  PERSISTENCE_TYPE_INVALID
};

static const PersistenceType kAllPersistenceTypes[] = {
    PERSISTENCE_TYPE_PERSISTENT, PERSISTENCE_TYPE_TEMPORARY,
    PERSISTENCE_TYPE_DEFAULT, PERSISTENCE_TYPE_PRIVATE};

static const PersistenceType kBestEffortPersistenceTypes[] = {
    PERSISTENCE_TYPE_TEMPORARY, PERSISTENCE_TYPE_DEFAULT,
    PERSISTENCE_TYPE_PRIVATE};

static const PersistenceType kInitializableBestEffortPersistenceTypes[] = {
    PERSISTENCE_TYPE_TEMPORARY, PERSISTENCE_TYPE_DEFAULT};

bool IsValidPersistenceType(PersistenceType aPersistenceType);

bool IsBestEffortPersistenceType(const PersistenceType aPersistenceType);

nsLiteralCString PersistenceTypeToString(PersistenceType aPersistenceType);

Maybe<PersistenceType> PersistenceTypeFromString(const nsACString& aString,
                                                 const fallible_t&);

PersistenceType PersistenceTypeFromString(const nsACString& aString);

Maybe<PersistenceType> PersistenceTypeFromInt32(int32_t aInt32,
                                                const fallible_t&);

// aFile is expected to be a repository directory (not some file or directory
// within that).
Maybe<PersistenceType> PersistenceTypeFromFile(nsIFile& aFile,
                                               const fallible_t&);

std::array<PersistenceType, 2> ComplementaryPersistenceTypes(
    const PersistenceType aPersistenceType);

}  // namespace mozilla::dom::quota

#endif  // mozilla_dom_quota_persistencetype_h__