1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is nsDiskCacheEntry.cpp, released
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 2001
22 * the Initial Developer. All Rights Reserved.
25 * Gordon Sheridan <gordon@netscape.com>
26 * Patrick C. Beard <beard@netscape.com>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 #include "nsDiskCache.h"
43 #include "nsDiskCacheEntry.h"
44 #include "nsDiskCacheBinding.h"
49 #include "nsISerializable.h"
50 #include "nsSerializationHelper.h"
52 /******************************************************************************
54 *****************************************************************************/
59 * Creates an nsCacheEntry and sets all fields except for the binding.
62 nsDiskCacheEntry::CreateCacheEntry(nsCacheDevice
* device
)
64 nsCacheEntry
* entry
= nsnull
;
65 nsresult rv
= nsCacheEntry::Create(Key(),
66 nsICache::STREAM_BASED
,
67 nsICache::STORE_ON_DISK
,
70 if (NS_FAILED(rv
) || !entry
) return nsnull
;
72 entry
->SetFetchCount(mFetchCount
);
73 entry
->SetLastFetched(mLastFetched
);
74 entry
->SetLastModified(mLastModified
);
75 entry
->SetExpirationTime(mExpirationTime
);
76 entry
->SetCacheDevice(device
);
77 // XXX why does nsCacheService have to fill out device in BindEntry()?
78 entry
->SetDataSize(mDataSize
);
80 rv
= entry
->UnflattenMetaData(MetaData(), mMetaDataSize
);
86 // Restore security info, if present
87 const char* info
= entry
->GetMetaDataElement("security-info");
89 nsCOMPtr
<nsISupports
> infoObj
;
90 NS_DeserializeObject(nsDependentCString(info
), getter_AddRefs(infoObj
));
91 entry
->SetSecurityInfo(infoObj
);
98 /******************************************************************************
99 * nsDiskCacheEntryInfo
100 *****************************************************************************/
102 NS_IMPL_ISUPPORTS1(nsDiskCacheEntryInfo
, nsICacheEntryInfo
)
104 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetClientID(char ** clientID
)
106 NS_ENSURE_ARG_POINTER(clientID
);
107 return ClientIDFromCacheKey(nsDependentCString(mDiskEntry
->Key()), clientID
);
110 extern const char DISK_CACHE_DEVICE_ID
[];
111 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetDeviceID(char ** deviceID
)
113 NS_ENSURE_ARG_POINTER(deviceID
);
114 *deviceID
= NS_strdup(mDeviceID
);
115 return *deviceID
? NS_OK
: NS_ERROR_OUT_OF_MEMORY
;
119 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetKey(nsACString
&clientKey
)
121 return ClientKeyFromCacheKey(nsDependentCString(mDiskEntry
->Key()), clientKey
);
124 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetFetchCount(PRInt32
*aFetchCount
)
126 NS_ENSURE_ARG_POINTER(aFetchCount
);
127 *aFetchCount
= mDiskEntry
->mFetchCount
;
131 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetLastFetched(PRUint32
*aLastFetched
)
133 NS_ENSURE_ARG_POINTER(aLastFetched
);
134 *aLastFetched
= mDiskEntry
->mLastFetched
;
138 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetLastModified(PRUint32
*aLastModified
)
140 NS_ENSURE_ARG_POINTER(aLastModified
);
141 *aLastModified
= mDiskEntry
->mLastModified
;
145 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetExpirationTime(PRUint32
*aExpirationTime
)
147 NS_ENSURE_ARG_POINTER(aExpirationTime
);
148 *aExpirationTime
= mDiskEntry
->mExpirationTime
;
152 NS_IMETHODIMP
nsDiskCacheEntryInfo::IsStreamBased(PRBool
*aStreamBased
)
154 NS_ENSURE_ARG_POINTER(aStreamBased
);
155 *aStreamBased
= PR_TRUE
;
159 NS_IMETHODIMP
nsDiskCacheEntryInfo::GetDataSize(PRUint32
*aDataSize
)
161 NS_ENSURE_ARG_POINTER(aDataSize
);
162 *aDataSize
= mDiskEntry
->mDataSize
;