1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/quota/PersistenceType.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,99 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_quota_persistencetype_h__ 1.11 +#define mozilla_dom_quota_persistencetype_h__ 1.12 + 1.13 +#include "mozilla/dom/quota/QuotaCommon.h" 1.14 + 1.15 +#include "mozilla/dom/StorageTypeBinding.h" 1.16 + 1.17 +BEGIN_QUOTA_NAMESPACE 1.18 + 1.19 +enum PersistenceType 1.20 +{ 1.21 + PERSISTENCE_TYPE_PERSISTENT = 0, 1.22 + PERSISTENCE_TYPE_TEMPORARY, 1.23 + 1.24 + // Only needed for IPC serialization helper, should never be used in code. 1.25 + PERSISTENCE_TYPE_INVALID 1.26 +}; 1.27 + 1.28 +inline void 1.29 +PersistenceTypeToText(PersistenceType aPersistenceType, nsACString& aText) 1.30 +{ 1.31 + switch (aPersistenceType) { 1.32 + case PERSISTENCE_TYPE_PERSISTENT: 1.33 + aText.AssignLiteral("persistent"); 1.34 + return; 1.35 + case PERSISTENCE_TYPE_TEMPORARY: 1.36 + aText.AssignLiteral("temporary"); 1.37 + return; 1.38 + 1.39 + case PERSISTENCE_TYPE_INVALID: 1.40 + default: 1.41 + MOZ_CRASH("Bad persistence type value!"); 1.42 + } 1.43 + 1.44 + MOZ_ASSUME_UNREACHABLE("Should never get here!"); 1.45 +} 1.46 + 1.47 +inline PersistenceType 1.48 +PersistenceTypeFromText(const nsACString& aText) 1.49 +{ 1.50 + if (aText.EqualsLiteral("persistent")) { 1.51 + return PERSISTENCE_TYPE_PERSISTENT; 1.52 + } 1.53 + 1.54 + if (aText.EqualsLiteral("temporary")) { 1.55 + return PERSISTENCE_TYPE_TEMPORARY; 1.56 + } 1.57 + 1.58 + MOZ_ASSUME_UNREACHABLE("Should never get here!"); 1.59 +} 1.60 + 1.61 +inline nsresult 1.62 +NullablePersistenceTypeFromText(const nsACString& aText, 1.63 + Nullable<PersistenceType> *aPersistenceType) 1.64 +{ 1.65 + if (aText.IsVoid()) { 1.66 + *aPersistenceType = Nullable<PersistenceType>(); 1.67 + return NS_OK; 1.68 + } 1.69 + 1.70 + if (aText.EqualsLiteral("persistent")) { 1.71 + *aPersistenceType = Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT); 1.72 + return NS_OK; 1.73 + } 1.74 + 1.75 + if (aText.EqualsLiteral("temporary")) { 1.76 + *aPersistenceType = Nullable<PersistenceType>(PERSISTENCE_TYPE_TEMPORARY); 1.77 + return NS_OK; 1.78 + } 1.79 + 1.80 + return NS_ERROR_UNEXPECTED; 1.81 +} 1.82 + 1.83 +inline mozilla::dom::StorageType 1.84 +PersistenceTypeToStorage(PersistenceType aPersistenceType) 1.85 +{ 1.86 + return mozilla::dom::StorageType(static_cast<int>(aPersistenceType)); 1.87 +} 1.88 + 1.89 +inline PersistenceType 1.90 +PersistenceTypeFromStorage(const Optional<mozilla::dom::StorageType>& aStorage, 1.91 + PersistenceType aDefaultPersistenceType) 1.92 +{ 1.93 + if (aStorage.WasPassed()) { 1.94 + return PersistenceType(static_cast<int>(aStorage.Value())); 1.95 + } 1.96 + 1.97 + return aDefaultPersistenceType; 1.98 +} 1.99 + 1.100 +END_QUOTA_NAMESPACE 1.101 + 1.102 +#endif // mozilla_dom_quota_persistencetype_h__