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