#include "config.h"
#if ENABLE(QUOTA)
#include "StorageInfo.h"
#include "Document.h"
#include "ExceptionCode.h"
#include "ScriptExecutionContext.h"
#include "StorageErrorCallback.h"
#include "StorageQuota.h"
#include "StorageQuotaCallback.h"
#include "StorageUsageCallback.h"
namespace WebCore {
StorageInfo::StorageInfo()
{
}
StorageInfo::~StorageInfo()
{
}
void StorageInfo::queryUsageAndQuota(ScriptExecutionContext& scriptExecutionContext, int storageType, RefPtr<StorageUsageCallback>&& successCallback, RefPtr<StorageErrorCallback>&& errorCallback)
{
StorageQuota* storageQuota = getStorageQuota(storageType);
if (!storageQuota) {
scriptExecutionContext->postTask(StorageErrorCallback::CallbackTask::create(WTFMove(errorCallback), NOT_SUPPORTED_ERR));
return;
}
storageQuota->queryUsageAndQuota(scriptExecutionContext, WTFMove(successCallback), WTFMove(errorCallback));
}
void StorageInfo::requestQuota(ScriptExecutionContext& scriptExecutionContext, int storageType, unsigned long long newQuotaInBytes, RefPtr<StorageQuotaCallback>&& successCallback, RefPtr<StorageErrorCallback>&& errorCallback)
{
StorageQuota* storageQuota = getStorageQuota(storageType);
if (!storageQuota) {
scriptExecutionContext->postTask(StorageErrorCallback::CallbackTask::create(WTFMove(errorCallback), NOT_SUPPORTED_ERR));
return;
}
storageQuota->requestQuota(scriptExecutionContext, newQuotaInBytes, WTFMove(successCallback), WTFMove(errorCallback));
}
StorageQuota* StorageInfo::getStorageQuota(int storageType)
{
switch (storageType) {
case TEMPORARY:
if (!m_temporaryStorage)
m_temporaryStorage = StorageQuota::create(StorageQuota::Temporary);
return m_temporaryStorage.get();
case PERSISTENT:
if (!m_persistentStorage)
m_persistentStorage = StorageQuota::create(StorageQuota::Persistent);
return m_persistentStorage.get();
}
return 0;
}
}
#endif // ENABLE(QUOTA)