2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-21 17:14:00 -08:00
|
|
|
#include "nsCache.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDiskCache.h"
|
|
|
|
#include "nsDiskCacheEntry.h"
|
|
|
|
#include "nsDiskCacheBinding.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
|
2008-01-05 17:07:16 -08:00
|
|
|
#include "nsISerializable.h"
|
|
|
|
#include "nsSerializationHelper.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* nsDiskCacheEntry
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CreateCacheEntry()
|
|
|
|
*
|
|
|
|
* Creates an nsCacheEntry and sets all fields except for the binding.
|
|
|
|
*/
|
|
|
|
nsCacheEntry *
|
|
|
|
nsDiskCacheEntry::CreateCacheEntry(nsCacheDevice * device)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsCacheEntry * entry = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = nsCacheEntry::Create(Key(),
|
|
|
|
nsICache::STREAM_BASED,
|
|
|
|
nsICache::STORE_ON_DISK,
|
|
|
|
device,
|
|
|
|
&entry);
|
2012-07-30 07:20:58 -07:00
|
|
|
if (NS_FAILED(rv) || !entry) return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
entry->SetFetchCount(mFetchCount);
|
|
|
|
entry->SetLastFetched(mLastFetched);
|
|
|
|
entry->SetLastModified(mLastModified);
|
|
|
|
entry->SetExpirationTime(mExpirationTime);
|
|
|
|
entry->SetCacheDevice(device);
|
|
|
|
// XXX why does nsCacheService have to fill out device in BindEntry()?
|
|
|
|
entry->SetDataSize(mDataSize);
|
|
|
|
|
|
|
|
rv = entry->UnflattenMetaData(MetaData(), mMetaDataSize);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete entry;
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-01-05 17:07:16 -08:00
|
|
|
|
|
|
|
// Restore security info, if present
|
|
|
|
const char* info = entry->GetMetaDataElement("security-info");
|
|
|
|
if (info) {
|
|
|
|
nsCOMPtr<nsISupports> infoObj;
|
2012-03-30 02:21:01 -07:00
|
|
|
rv = NS_DeserializeObject(nsDependentCString(info),
|
|
|
|
getter_AddRefs(infoObj));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete entry;
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-30 02:21:01 -07:00
|
|
|
}
|
2008-01-05 17:07:16 -08:00
|
|
|
entry->SetSecurityInfo(infoObj);
|
|
|
|
}
|
|
|
|
|
2007-12-28 20:22:54 -08:00
|
|
|
return entry;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* nsDiskCacheEntryInfo
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsDiskCacheEntryInfo, nsICacheEntryInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetClientID(char ** clientID)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(clientID);
|
|
|
|
return ClientIDFromCacheKey(nsDependentCString(mDiskEntry->Key()), clientID);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern const char DISK_CACHE_DEVICE_ID[];
|
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetDeviceID(char ** deviceID)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(deviceID);
|
2007-05-14 13:09:20 -07:00
|
|
|
*deviceID = NS_strdup(mDeviceID);
|
2007-03-22 10:30:00 -07:00
|
|
|
return *deviceID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetKey(nsACString &clientKey)
|
|
|
|
{
|
|
|
|
return ClientKeyFromCacheKey(nsDependentCString(mDiskEntry->Key()), clientKey);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetFetchCount(int32_t *aFetchCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aFetchCount);
|
|
|
|
*aFetchCount = mDiskEntry->mFetchCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetLastFetched(uint32_t *aLastFetched)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLastFetched);
|
|
|
|
*aLastFetched = mDiskEntry->mLastFetched;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetLastModified(uint32_t *aLastModified)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLastModified);
|
|
|
|
*aLastModified = mDiskEntry->mLastModified;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetExpirationTime(uint32_t *aExpirationTime)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aExpirationTime);
|
|
|
|
*aExpirationTime = mDiskEntry->mExpirationTime;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::IsStreamBased(bool *aStreamBased)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aStreamBased);
|
2011-10-17 07:59:28 -07:00
|
|
|
*aStreamBased = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetDataSize(uint32_t *aDataSize)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDataSize);
|
|
|
|
*aDataSize = mDiskEntry->mDataSize;
|
|
|
|
return NS_OK;
|
|
|
|
}
|