1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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/. */
7 #include "nsDiskCache.h"
8 #include "nsDiskCacheEntry.h"
9 #include "nsDiskCacheBinding.h"
14 #include "nsISerializable.h"
15 #include "nsSerializationHelper.h"
17 /******************************************************************************
19 *****************************************************************************/
24 * Creates an nsCacheEntry and sets all fields except for the binding.
27 nsDiskCacheEntry::CreateCacheEntry(nsCacheDevice
* device
)
29 nsCacheEntry
* entry
= nullptr;
30 nsresult rv
= nsCacheEntry::Create(Key(),
31 nsICache::STREAM_BASED
,
32 nsICache::STORE_ON_DISK
,
35 if (NS_FAILED(rv
) || !entry
) return nullptr;
37 entry
->SetFetchCount(mFetchCount
);
38 entry
->SetLastFetched(mLastFetched
);
39 entry
->SetLastModified(mLastModified
);
40 entry
->SetExpirationTime(mExpirationTime
);
41 entry
->SetCacheDevice(device
);
42 // XXX why does nsCacheService have to fill out device in BindEntry()?
43 entry
->SetDataSize(mDataSize
);
45 rv
= entry
->UnflattenMetaData(MetaData(), mMetaDataSize
);
51 // Restore security info, if present
52 const char* info
= entry
->GetMetaDataElement("security-info");
54 nsCOMPtr
<nsISupports
> infoObj
;
55 rv
= NS_DeserializeObject(nsDependentCString(info
),
56 getter_AddRefs(infoObj
));
61 entry
->SetSecurityInfo(infoObj
);
68 /******************************************************************************
69 * nsDiskCacheEntryInfo
70 *****************************************************************************/
72 NS_IMPL_ISUPPORTS1(nsDiskCacheEntryInfo
, nsICacheEntryInfo
)
74 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetClientID(char ** clientID
)
76 NS_ENSURE_ARG_POINTER(clientID
);
77 return ClientIDFromCacheKey(nsDependentCString(mDiskEntry
->Key()), clientID
);
80 extern const char DISK_CACHE_DEVICE_ID
[];
81 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetDeviceID(char ** deviceID
)
83 NS_ENSURE_ARG_POINTER(deviceID
);
84 *deviceID
= NS_strdup(mDeviceID
);
85 return *deviceID
? NS_OK
: NS_ERROR_OUT_OF_MEMORY
;
89 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetKey(nsACString
&clientKey
)
91 return ClientKeyFromCacheKey(nsDependentCString(mDiskEntry
->Key()), clientKey
);
94 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetFetchCount(PRInt32
*aFetchCount
)
96 NS_ENSURE_ARG_POINTER(aFetchCount
);
97 *aFetchCount
= mDiskEntry
->mFetchCount
;
101 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetLastFetched(PRUint32
*aLastFetched
)
103 NS_ENSURE_ARG_POINTER(aLastFetched
);
104 *aLastFetched
= mDiskEntry
->mLastFetched
;
108 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetLastModified(PRUint32
*aLastModified
)
110 NS_ENSURE_ARG_POINTER(aLastModified
);
111 *aLastModified
= mDiskEntry
->mLastModified
;
115 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetExpirationTime(PRUint32
*aExpirationTime
)
117 NS_ENSURE_ARG_POINTER(aExpirationTime
);
118 *aExpirationTime
= mDiskEntry
->mExpirationTime
;
122 NS_IMETHODIMP
nsDiskCacheEntryInfo::IsStreamBased(bool *aStreamBased
)
124 NS_ENSURE_ARG_POINTER(aStreamBased
);
125 *aStreamBased
= true;
129 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetDataSize(PRUint32
*aDataSize
)
131 NS_ENSURE_ARG_POINTER(aDataSize
);
132 *aDataSize
= mDiskEntry
->mDataSize
;