1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/cache/nsDiskCacheEntry.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,133 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "nsCache.h" 1.11 +#include "nsDiskCache.h" 1.12 +#include "nsDiskCacheEntry.h" 1.13 +#include "nsDiskCacheBinding.h" 1.14 +#include "nsCRT.h" 1.15 + 1.16 +#include "nsISerializable.h" 1.17 +#include "nsSerializationHelper.h" 1.18 + 1.19 +/****************************************************************************** 1.20 + * nsDiskCacheEntry 1.21 + *****************************************************************************/ 1.22 + 1.23 +/** 1.24 + * CreateCacheEntry() 1.25 + * 1.26 + * Creates an nsCacheEntry and sets all fields except for the binding. 1.27 + */ 1.28 +nsCacheEntry * 1.29 +nsDiskCacheEntry::CreateCacheEntry(nsCacheDevice * device) 1.30 +{ 1.31 + nsCacheEntry * entry = nullptr; 1.32 + nsresult rv = nsCacheEntry::Create(Key(), 1.33 + nsICache::STREAM_BASED, 1.34 + nsICache::STORE_ON_DISK, 1.35 + device, 1.36 + &entry); 1.37 + if (NS_FAILED(rv) || !entry) return nullptr; 1.38 + 1.39 + entry->SetFetchCount(mFetchCount); 1.40 + entry->SetLastFetched(mLastFetched); 1.41 + entry->SetLastModified(mLastModified); 1.42 + entry->SetExpirationTime(mExpirationTime); 1.43 + entry->SetCacheDevice(device); 1.44 + // XXX why does nsCacheService have to fill out device in BindEntry()? 1.45 + entry->SetDataSize(mDataSize); 1.46 + 1.47 + rv = entry->UnflattenMetaData(MetaData(), mMetaDataSize); 1.48 + if (NS_FAILED(rv)) { 1.49 + delete entry; 1.50 + return nullptr; 1.51 + } 1.52 + 1.53 + // Restore security info, if present 1.54 + const char* info = entry->GetMetaDataElement("security-info"); 1.55 + if (info) { 1.56 + nsCOMPtr<nsISupports> infoObj; 1.57 + rv = NS_DeserializeObject(nsDependentCString(info), 1.58 + getter_AddRefs(infoObj)); 1.59 + if (NS_FAILED(rv)) { 1.60 + delete entry; 1.61 + return nullptr; 1.62 + } 1.63 + entry->SetSecurityInfo(infoObj); 1.64 + } 1.65 + 1.66 + return entry; 1.67 +} 1.68 + 1.69 + 1.70 +/****************************************************************************** 1.71 + * nsDiskCacheEntryInfo 1.72 + *****************************************************************************/ 1.73 + 1.74 +NS_IMPL_ISUPPORTS(nsDiskCacheEntryInfo, nsICacheEntryInfo) 1.75 + 1.76 +NS_IMETHODIMP nsDiskCacheEntryInfo::GetClientID(char ** clientID) 1.77 +{ 1.78 + NS_ENSURE_ARG_POINTER(clientID); 1.79 + return ClientIDFromCacheKey(nsDependentCString(mDiskEntry->Key()), clientID); 1.80 +} 1.81 + 1.82 +extern const char DISK_CACHE_DEVICE_ID[]; 1.83 +NS_IMETHODIMP nsDiskCacheEntryInfo::GetDeviceID(char ** deviceID) 1.84 +{ 1.85 + NS_ENSURE_ARG_POINTER(deviceID); 1.86 + *deviceID = NS_strdup(mDeviceID); 1.87 + return *deviceID ? NS_OK : NS_ERROR_OUT_OF_MEMORY; 1.88 +} 1.89 + 1.90 + 1.91 +NS_IMETHODIMP nsDiskCacheEntryInfo::GetKey(nsACString &clientKey) 1.92 +{ 1.93 + return ClientKeyFromCacheKey(nsDependentCString(mDiskEntry->Key()), clientKey); 1.94 +} 1.95 + 1.96 +NS_IMETHODIMP nsDiskCacheEntryInfo::GetFetchCount(int32_t *aFetchCount) 1.97 +{ 1.98 + NS_ENSURE_ARG_POINTER(aFetchCount); 1.99 + *aFetchCount = mDiskEntry->mFetchCount; 1.100 + return NS_OK; 1.101 +} 1.102 + 1.103 +NS_IMETHODIMP nsDiskCacheEntryInfo::GetLastFetched(uint32_t *aLastFetched) 1.104 +{ 1.105 + NS_ENSURE_ARG_POINTER(aLastFetched); 1.106 + *aLastFetched = mDiskEntry->mLastFetched; 1.107 + return NS_OK; 1.108 +} 1.109 + 1.110 +NS_IMETHODIMP nsDiskCacheEntryInfo::GetLastModified(uint32_t *aLastModified) 1.111 +{ 1.112 + NS_ENSURE_ARG_POINTER(aLastModified); 1.113 + *aLastModified = mDiskEntry->mLastModified; 1.114 + return NS_OK; 1.115 +} 1.116 + 1.117 +NS_IMETHODIMP nsDiskCacheEntryInfo::GetExpirationTime(uint32_t *aExpirationTime) 1.118 +{ 1.119 + NS_ENSURE_ARG_POINTER(aExpirationTime); 1.120 + *aExpirationTime = mDiskEntry->mExpirationTime; 1.121 + return NS_OK; 1.122 +} 1.123 + 1.124 +NS_IMETHODIMP nsDiskCacheEntryInfo::IsStreamBased(bool *aStreamBased) 1.125 +{ 1.126 + NS_ENSURE_ARG_POINTER(aStreamBased); 1.127 + *aStreamBased = true; 1.128 + return NS_OK; 1.129 +} 1.130 + 1.131 +NS_IMETHODIMP nsDiskCacheEntryInfo::GetDataSize(uint32_t *aDataSize) 1.132 +{ 1.133 + NS_ENSURE_ARG_POINTER(aDataSize); 1.134 + *aDataSize = mDiskEntry->mDataSize; 1.135 + return NS_OK; 1.136 +}