netwerk/cache/nsDiskCacheEntry.cpp

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 *
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "nsCache.h"
michael@0 8 #include "nsDiskCache.h"
michael@0 9 #include "nsDiskCacheEntry.h"
michael@0 10 #include "nsDiskCacheBinding.h"
michael@0 11 #include "nsCRT.h"
michael@0 12
michael@0 13 #include "nsISerializable.h"
michael@0 14 #include "nsSerializationHelper.h"
michael@0 15
michael@0 16 /******************************************************************************
michael@0 17 * nsDiskCacheEntry
michael@0 18 *****************************************************************************/
michael@0 19
michael@0 20 /**
michael@0 21 * CreateCacheEntry()
michael@0 22 *
michael@0 23 * Creates an nsCacheEntry and sets all fields except for the binding.
michael@0 24 */
michael@0 25 nsCacheEntry *
michael@0 26 nsDiskCacheEntry::CreateCacheEntry(nsCacheDevice * device)
michael@0 27 {
michael@0 28 nsCacheEntry * entry = nullptr;
michael@0 29 nsresult rv = nsCacheEntry::Create(Key(),
michael@0 30 nsICache::STREAM_BASED,
michael@0 31 nsICache::STORE_ON_DISK,
michael@0 32 device,
michael@0 33 &entry);
michael@0 34 if (NS_FAILED(rv) || !entry) return nullptr;
michael@0 35
michael@0 36 entry->SetFetchCount(mFetchCount);
michael@0 37 entry->SetLastFetched(mLastFetched);
michael@0 38 entry->SetLastModified(mLastModified);
michael@0 39 entry->SetExpirationTime(mExpirationTime);
michael@0 40 entry->SetCacheDevice(device);
michael@0 41 // XXX why does nsCacheService have to fill out device in BindEntry()?
michael@0 42 entry->SetDataSize(mDataSize);
michael@0 43
michael@0 44 rv = entry->UnflattenMetaData(MetaData(), mMetaDataSize);
michael@0 45 if (NS_FAILED(rv)) {
michael@0 46 delete entry;
michael@0 47 return nullptr;
michael@0 48 }
michael@0 49
michael@0 50 // Restore security info, if present
michael@0 51 const char* info = entry->GetMetaDataElement("security-info");
michael@0 52 if (info) {
michael@0 53 nsCOMPtr<nsISupports> infoObj;
michael@0 54 rv = NS_DeserializeObject(nsDependentCString(info),
michael@0 55 getter_AddRefs(infoObj));
michael@0 56 if (NS_FAILED(rv)) {
michael@0 57 delete entry;
michael@0 58 return nullptr;
michael@0 59 }
michael@0 60 entry->SetSecurityInfo(infoObj);
michael@0 61 }
michael@0 62
michael@0 63 return entry;
michael@0 64 }
michael@0 65
michael@0 66
michael@0 67 /******************************************************************************
michael@0 68 * nsDiskCacheEntryInfo
michael@0 69 *****************************************************************************/
michael@0 70
michael@0 71 NS_IMPL_ISUPPORTS(nsDiskCacheEntryInfo, nsICacheEntryInfo)
michael@0 72
michael@0 73 NS_IMETHODIMP nsDiskCacheEntryInfo::GetClientID(char ** clientID)
michael@0 74 {
michael@0 75 NS_ENSURE_ARG_POINTER(clientID);
michael@0 76 return ClientIDFromCacheKey(nsDependentCString(mDiskEntry->Key()), clientID);
michael@0 77 }
michael@0 78
michael@0 79 extern const char DISK_CACHE_DEVICE_ID[];
michael@0 80 NS_IMETHODIMP nsDiskCacheEntryInfo::GetDeviceID(char ** deviceID)
michael@0 81 {
michael@0 82 NS_ENSURE_ARG_POINTER(deviceID);
michael@0 83 *deviceID = NS_strdup(mDeviceID);
michael@0 84 return *deviceID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
michael@0 85 }
michael@0 86
michael@0 87
michael@0 88 NS_IMETHODIMP nsDiskCacheEntryInfo::GetKey(nsACString &clientKey)
michael@0 89 {
michael@0 90 return ClientKeyFromCacheKey(nsDependentCString(mDiskEntry->Key()), clientKey);
michael@0 91 }
michael@0 92
michael@0 93 NS_IMETHODIMP nsDiskCacheEntryInfo::GetFetchCount(int32_t *aFetchCount)
michael@0 94 {
michael@0 95 NS_ENSURE_ARG_POINTER(aFetchCount);
michael@0 96 *aFetchCount = mDiskEntry->mFetchCount;
michael@0 97 return NS_OK;
michael@0 98 }
michael@0 99
michael@0 100 NS_IMETHODIMP nsDiskCacheEntryInfo::GetLastFetched(uint32_t *aLastFetched)
michael@0 101 {
michael@0 102 NS_ENSURE_ARG_POINTER(aLastFetched);
michael@0 103 *aLastFetched = mDiskEntry->mLastFetched;
michael@0 104 return NS_OK;
michael@0 105 }
michael@0 106
michael@0 107 NS_IMETHODIMP nsDiskCacheEntryInfo::GetLastModified(uint32_t *aLastModified)
michael@0 108 {
michael@0 109 NS_ENSURE_ARG_POINTER(aLastModified);
michael@0 110 *aLastModified = mDiskEntry->mLastModified;
michael@0 111 return NS_OK;
michael@0 112 }
michael@0 113
michael@0 114 NS_IMETHODIMP nsDiskCacheEntryInfo::GetExpirationTime(uint32_t *aExpirationTime)
michael@0 115 {
michael@0 116 NS_ENSURE_ARG_POINTER(aExpirationTime);
michael@0 117 *aExpirationTime = mDiskEntry->mExpirationTime;
michael@0 118 return NS_OK;
michael@0 119 }
michael@0 120
michael@0 121 NS_IMETHODIMP nsDiskCacheEntryInfo::IsStreamBased(bool *aStreamBased)
michael@0 122 {
michael@0 123 NS_ENSURE_ARG_POINTER(aStreamBased);
michael@0 124 *aStreamBased = true;
michael@0 125 return NS_OK;
michael@0 126 }
michael@0 127
michael@0 128 NS_IMETHODIMP nsDiskCacheEntryInfo::GetDataSize(uint32_t *aDataSize)
michael@0 129 {
michael@0 130 NS_ENSURE_ARG_POINTER(aDataSize);
michael@0 131 *aDataSize = mDiskEntry->mDataSize;
michael@0 132 return NS_OK;
michael@0 133 }

mercurial