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