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