dom/quota/PersistenceType.h

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:5cdc3f534e7f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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 "mozilla/dom/quota/QuotaCommon.h"
11
12 #include "mozilla/dom/StorageTypeBinding.h"
13
14 BEGIN_QUOTA_NAMESPACE
15
16 enum PersistenceType
17 {
18 PERSISTENCE_TYPE_PERSISTENT = 0,
19 PERSISTENCE_TYPE_TEMPORARY,
20
21 // Only needed for IPC serialization helper, should never be used in code.
22 PERSISTENCE_TYPE_INVALID
23 };
24
25 inline void
26 PersistenceTypeToText(PersistenceType aPersistenceType, nsACString& aText)
27 {
28 switch (aPersistenceType) {
29 case PERSISTENCE_TYPE_PERSISTENT:
30 aText.AssignLiteral("persistent");
31 return;
32 case PERSISTENCE_TYPE_TEMPORARY:
33 aText.AssignLiteral("temporary");
34 return;
35
36 case PERSISTENCE_TYPE_INVALID:
37 default:
38 MOZ_CRASH("Bad persistence type value!");
39 }
40
41 MOZ_ASSUME_UNREACHABLE("Should never get here!");
42 }
43
44 inline PersistenceType
45 PersistenceTypeFromText(const nsACString& aText)
46 {
47 if (aText.EqualsLiteral("persistent")) {
48 return PERSISTENCE_TYPE_PERSISTENT;
49 }
50
51 if (aText.EqualsLiteral("temporary")) {
52 return PERSISTENCE_TYPE_TEMPORARY;
53 }
54
55 MOZ_ASSUME_UNREACHABLE("Should never get here!");
56 }
57
58 inline nsresult
59 NullablePersistenceTypeFromText(const nsACString& aText,
60 Nullable<PersistenceType> *aPersistenceType)
61 {
62 if (aText.IsVoid()) {
63 *aPersistenceType = Nullable<PersistenceType>();
64 return NS_OK;
65 }
66
67 if (aText.EqualsLiteral("persistent")) {
68 *aPersistenceType = Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT);
69 return NS_OK;
70 }
71
72 if (aText.EqualsLiteral("temporary")) {
73 *aPersistenceType = Nullable<PersistenceType>(PERSISTENCE_TYPE_TEMPORARY);
74 return NS_OK;
75 }
76
77 return NS_ERROR_UNEXPECTED;
78 }
79
80 inline mozilla::dom::StorageType
81 PersistenceTypeToStorage(PersistenceType aPersistenceType)
82 {
83 return mozilla::dom::StorageType(static_cast<int>(aPersistenceType));
84 }
85
86 inline PersistenceType
87 PersistenceTypeFromStorage(const Optional<mozilla::dom::StorageType>& aStorage,
88 PersistenceType aDefaultPersistenceType)
89 {
90 if (aStorage.WasPassed()) {
91 return PersistenceType(static_cast<int>(aStorage.Value()));
92 }
93
94 return aDefaultPersistenceType;
95 }
96
97 END_QUOTA_NAMESPACE
98
99 #endif // mozilla_dom_quota_persistencetype_h__

mercurial