2013-09-11 08:18:36 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-09-11 08:18:36 +04:00
|
|
|
/* 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 "mozilla/dom/quota/QuotaCommon.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/StorageTypeBinding.h"
|
|
|
|
|
|
|
|
BEGIN_QUOTA_NAMESPACE
|
|
|
|
|
|
|
|
enum PersistenceType
|
|
|
|
{
|
|
|
|
PERSISTENCE_TYPE_PERSISTENT = 0,
|
|
|
|
PERSISTENCE_TYPE_TEMPORARY,
|
2014-11-28 11:44:12 +03:00
|
|
|
PERSISTENCE_TYPE_DEFAULT,
|
2013-09-11 08:18:36 +04:00
|
|
|
|
|
|
|
// Only needed for IPC serialization helper, should never be used in code.
|
|
|
|
PERSISTENCE_TYPE_INVALID
|
|
|
|
};
|
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
static const PersistenceType kAllPersistenceTypes[] = {
|
|
|
|
PERSISTENCE_TYPE_PERSISTENT,
|
|
|
|
PERSISTENCE_TYPE_TEMPORARY,
|
|
|
|
PERSISTENCE_TYPE_DEFAULT
|
|
|
|
};
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
inline void
|
|
|
|
PersistenceTypeToText(PersistenceType aPersistenceType, nsACString& aText)
|
|
|
|
{
|
|
|
|
switch (aPersistenceType) {
|
|
|
|
case PERSISTENCE_TYPE_PERSISTENT:
|
|
|
|
aText.AssignLiteral("persistent");
|
|
|
|
return;
|
|
|
|
case PERSISTENCE_TYPE_TEMPORARY:
|
|
|
|
aText.AssignLiteral("temporary");
|
|
|
|
return;
|
2014-11-28 11:44:12 +03:00
|
|
|
case PERSISTENCE_TYPE_DEFAULT:
|
|
|
|
aText.AssignLiteral("default");
|
|
|
|
return;
|
2013-09-11 08:18:36 +04:00
|
|
|
|
|
|
|
case PERSISTENCE_TYPE_INVALID:
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Bad persistence type value!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline PersistenceType
|
|
|
|
PersistenceTypeFromText(const nsACString& aText)
|
|
|
|
{
|
|
|
|
if (aText.EqualsLiteral("persistent")) {
|
|
|
|
return PERSISTENCE_TYPE_PERSISTENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aText.EqualsLiteral("temporary")) {
|
|
|
|
return PERSISTENCE_TYPE_TEMPORARY;
|
|
|
|
}
|
|
|
|
|
2014-11-28 11:44:12 +03:00
|
|
|
if (aText.EqualsLiteral("default")) {
|
|
|
|
return PERSISTENCE_TYPE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2014-04-20 11:36:40 +04:00
|
|
|
MOZ_CRASH("Should never get here!");
|
2013-09-11 08:18:36 +04:00
|
|
|
}
|
|
|
|
|
2014-04-15 00:48:49 +04:00
|
|
|
inline nsresult
|
|
|
|
NullablePersistenceTypeFromText(const nsACString& aText,
|
2014-04-16 06:30:26 +04:00
|
|
|
Nullable<PersistenceType>* aPersistenceType)
|
2014-04-15 00:48:49 +04:00
|
|
|
{
|
|
|
|
if (aText.IsVoid()) {
|
|
|
|
*aPersistenceType = Nullable<PersistenceType>();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aText.EqualsLiteral("persistent")) {
|
|
|
|
*aPersistenceType = Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aText.EqualsLiteral("temporary")) {
|
|
|
|
*aPersistenceType = Nullable<PersistenceType>(PERSISTENCE_TYPE_TEMPORARY);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-28 11:44:12 +03:00
|
|
|
if (aText.EqualsLiteral("default")) {
|
|
|
|
*aPersistenceType = Nullable<PersistenceType>(PERSISTENCE_TYPE_DEFAULT);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-16 06:30:26 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2014-04-15 00:48:49 +04:00
|
|
|
}
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
inline mozilla::dom::StorageType
|
|
|
|
PersistenceTypeToStorage(PersistenceType aPersistenceType)
|
|
|
|
{
|
|
|
|
return mozilla::dom::StorageType(static_cast<int>(aPersistenceType));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline PersistenceType
|
2014-11-04 23:44:56 +03:00
|
|
|
PersistenceTypeFromStorage(const Optional<mozilla::dom::StorageType>& aStorage)
|
2013-09-11 08:18:36 +04:00
|
|
|
{
|
|
|
|
if (aStorage.WasPassed()) {
|
|
|
|
return PersistenceType(static_cast<int>(aStorage.Value()));
|
|
|
|
}
|
|
|
|
|
2014-11-28 11:44:12 +03:00
|
|
|
return PERSISTENCE_TYPE_DEFAULT;
|
2014-11-04 23:44:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline PersistenceType
|
|
|
|
ComplementaryPersistenceType(PersistenceType aPersistenceType)
|
|
|
|
{
|
2014-11-28 11:44:12 +03:00
|
|
|
MOZ_ASSERT(aPersistenceType == PERSISTENCE_TYPE_DEFAULT ||
|
|
|
|
aPersistenceType == PERSISTENCE_TYPE_TEMPORARY);
|
|
|
|
|
|
|
|
if (aPersistenceType == PERSISTENCE_TYPE_DEFAULT) {
|
2014-11-04 23:44:56 +03:00
|
|
|
return PERSISTENCE_TYPE_TEMPORARY;
|
|
|
|
}
|
|
|
|
|
2014-11-28 11:44:12 +03:00
|
|
|
return PERSISTENCE_TYPE_DEFAULT;
|
2013-09-11 08:18:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
END_QUOTA_NAMESPACE
|
|
|
|
|
|
|
|
#endif // mozilla_dom_quota_persistencetype_h__
|