98 CHttpCacheEntry* self = CHttpCacheEntry::NewL( aUrl, aEvictionHandler ); |
96 CHttpCacheEntry* self = CHttpCacheEntry::NewL( aUrl, aEvictionHandler ); |
99 CleanupStack::PushL( self ); |
97 CleanupStack::PushL( self ); |
100 return self; |
98 return self; |
101 } |
99 } |
102 |
100 |
|
101 // ----------------------------------------------------------------------------- |
103 // Destructor |
102 // Destructor |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
104 CHttpCacheEntry::~CHttpCacheEntry() |
105 CHttpCacheEntry::~CHttpCacheEntry() |
105 { |
106 { |
106 if( iVictim && iEvictionHandler) |
107 // Clean up eviction handler |
107 { |
108 if ( iEvictionCandidate && iEvictionHandler ) |
108 iEvictionHandler->Remove( *this ); |
109 { |
109 } |
110 iEvictionHandler->Remove( *this ); |
|
111 } |
|
112 |
|
113 // Close files, this will commit changes |
|
114 if ( iCacheFilesOpened ) |
|
115 { |
|
116 iHeaderFile.Close(); |
|
117 iBodyFile.Close(); |
|
118 } |
|
119 |
|
120 // Clean up our memory |
110 delete iUrl; |
121 delete iUrl; |
111 delete iFileName; |
122 delete iFileName; |
|
123 delete iCacheBuffer; |
112 } |
124 } |
113 |
125 |
114 // ----------------------------------------------------------------------------- |
126 // ----------------------------------------------------------------------------- |
115 // CHttpCacheEntry::SetState |
127 // CHttpCacheEntry::SetState |
116 // |
128 // |
117 // ----------------------------------------------------------------------------- |
129 // ----------------------------------------------------------------------------- |
118 // |
130 // |
119 void CHttpCacheEntry::SetState( |
131 void CHttpCacheEntry::SetState( TCacheEntryState aState ) |
120 TCacheEntryState aState ) |
132 { |
121 { |
133 // Add entry to the eviction table once it gets completed |
122 // add entry to the eviction table once it gets completed |
134 if ( aState == ECacheComplete && !iEvictionCandidate ) |
123 if( aState == ECacheComplete && !iVictim ) |
|
124 { |
135 { |
125 // don't add it twice |
136 // don't add it twice |
126 iEvictionHandler->Insert( *this ); |
137 iEvictionHandler->Insert( *this ); |
127 iVictim = ETrue; |
138 iEvictionCandidate = ETrue; |
128 } |
139 } |
|
140 |
129 iState = aState; |
141 iState = aState; |
130 } |
142 } |
131 |
143 |
132 |
|
133 // ----------------------------------------------------------------------------- |
144 // ----------------------------------------------------------------------------- |
134 // CHttpCacheEntry::SetFileNameL |
145 // CHttpCacheEntry::SetFileNameL |
135 // |
146 // |
136 // ----------------------------------------------------------------------------- |
147 // ----------------------------------------------------------------------------- |
137 // |
148 // |
138 void CHttpCacheEntry::SetFileNameL( |
149 void CHttpCacheEntry::SetFileNameL( const TFileName& aFileName ) |
139 const TFileName& aFileName ) |
|
140 { |
150 { |
141 delete iFileName; |
151 delete iFileName; |
142 iFileName = NULL; |
152 iFileName = NULL; |
|
153 |
143 iFileName = aFileName.AllocL(); |
154 iFileName = aFileName.AllocL(); |
144 } |
155 } |
145 |
156 |
146 |
157 |
147 // ----------------------------------------------------------------------------- |
158 // ----------------------------------------------------------------------------- |
151 // |
162 // |
152 void CHttpCacheEntry::Accessed() |
163 void CHttpCacheEntry::Accessed() |
153 { |
164 { |
154 TTime now; |
165 TTime now; |
155 now.HomeTime(); |
166 now.HomeTime(); |
156 |
|
157 iLastAccessed = now.Int64(); |
167 iLastAccessed = now.Int64(); |
158 |
168 |
159 iRef++; |
169 iRef++; |
160 if( iVictim ) |
170 |
|
171 if ( iEvictionCandidate ) |
161 { |
172 { |
162 iEvictionHandler->Accessed( *this ); |
173 iEvictionHandler->Accessed( *this ); |
163 } |
174 } |
|
175 |
164 #ifdef __CACHELOG__ |
176 #ifdef __CACHELOG__ |
165 _LIT( KAccessFormat, "entry accessed: %d" ); |
177 _LIT( KAccessFormat, "entry accessed: %d" ); |
166 TBuf<100> buf; |
178 TBuf<100> buf; |
167 buf.Format( KAccessFormat, iRef ); |
179 buf.Format( KAccessFormat, iRef ); |
168 HttpCacheUtil::WriteUrlToLog( 0, buf, iUrl->Des() ); |
180 HttpCacheUtil::WriteUrlToLog( 0, buf, iUrl->Des() ); |
169 #endif // __CACHELOG__ |
181 #endif // __CACHELOG__ |
170 } |
182 |
171 |
183 } |
172 // ----------------------------------------------------------------------------- |
184 |
173 // CHttpCacheEntry::SetSize |
185 // ----------------------------------------------------------------------------- |
174 // |
186 // CHttpCacheEntry::SetBodySize |
175 // ----------------------------------------------------------------------------- |
187 // |
176 // |
188 // ----------------------------------------------------------------------------- |
177 void CHttpCacheEntry::SetSize( |
189 // |
178 TUint aSize ) |
190 void CHttpCacheEntry::SetBodySize( TUint aBodySize ) |
179 { |
191 { |
180 if( iSize && !aSize ) |
192 if ( iBodySize && !aBodySize ) |
181 { |
193 { |
182 // body removal |
194 // Remove from the eviction table, this is no longer a candidate |
183 // remove itself from the eviction table. |
195 if ( iEvictionCandidate ) |
184 // this is no longer a victim |
196 { |
185 if( iVictim ) |
197 iEvictionHandler->Remove( *this ); |
186 { |
198 iEvictionCandidate = EFalse; |
187 iEvictionHandler->Remove( *this ); |
199 } |
188 iVictim = EFalse; |
200 } |
189 } |
201 iBodySize = aBodySize; |
190 } |
|
191 iSize = aSize; |
|
192 } |
202 } |
193 |
203 |
194 // ----------------------------------------------------------------------------- |
204 // ----------------------------------------------------------------------------- |
195 // CHttpCacheEntry::SetProtected |
205 // CHttpCacheEntry::SetProtected |
196 // |
206 // |
197 // ----------------------------------------------------------------------------- |
207 // ----------------------------------------------------------------------------- |
198 // |
208 // |
199 void CHttpCacheEntry::SetProtected() |
209 void CHttpCacheEntry::SetProtected() |
200 { |
210 { |
201 iProtected = ETrue; |
211 iProtected = ETrue; |
202 // iRef |
|
203 iRef = 50; |
212 iRef = 50; |
204 HttpCacheUtil::WriteLog( 0, _L( "protected item" ) ); |
213 |
|
214 #ifdef __CACHELOG__ |
|
215 HttpCacheUtil::WriteLog( 0, _L( "CHttpCacheEntry::SetProtected - protected item" ) ); |
|
216 #endif |
205 } |
217 } |
206 |
218 |
207 // ----------------------------------------------------------------------------- |
219 // ----------------------------------------------------------------------------- |
208 // CHttpCacheEntry::Internalize |
220 // CHttpCacheEntry::Internalize |
209 // |
221 // |
210 // ----------------------------------------------------------------------------- |
222 // ----------------------------------------------------------------------------- |
211 // |
223 // |
212 TInt CHttpCacheEntry::Internalize( |
224 TInt CHttpCacheEntry::Internalize( RFileReadStream& aReadStream ) |
213 RFileReadStream& aReadStream ) |
225 { |
214 { |
226 // url length |
215 TRAPD( err, |
227 TRAPD( err, |
216 TInt len; |
228 TInt len; |
217 |
229 |
218 // url length |
230 // url length |
219 len = aReadStream.ReadInt32L(); |
231 len = aReadStream.ReadInt32L(); |
220 delete iUrl; |
232 delete iUrl; |
221 iUrl=NULL; |
233 iUrl=NULL; |
222 iUrl = HBufC8::NewL( len ); |
234 iUrl = HBufC8::NewL( len ); |
223 TPtr8 ptr8( iUrl->Des() ); |
235 TPtr8 ptr8( iUrl->Des() ); |
224 // url |
236 // url |
225 aReadStream.ReadL( ptr8, len ); |
237 aReadStream.ReadL( ptr8, len ); |
226 |
238 |
227 // filename length |
239 // filename length |
228 len = aReadStream.ReadInt32L(); |
240 len = aReadStream.ReadInt32L(); |
229 HBufC* filename = HBufC::NewLC( len ); |
241 HBufC* filename = HBufC::NewLC( len ); |
230 TPtr ptr( filename->Des() ); |
242 TPtr ptr( filename->Des() ); |
231 // url |
243 // url |
232 aReadStream.ReadL( ptr, len ); |
244 aReadStream.ReadL( ptr, len ); |
233 // |
245 // |
234 SetFileNameL( filename->Des() ); |
246 SetFileNameL( filename->Des() ); |
235 // |
247 // |
236 CleanupStack::PopAndDestroy(); // filename |
248 CleanupStack::PopAndDestroy(); // filename |
237 // la |
249 // la |
238 TReal64 la; |
250 TReal64 la; |
239 la = aReadStream.ReadReal64L(); |
251 la = aReadStream.ReadReal64L(); |
240 iLastAccessed = la; |
252 iLastAccessed = la; |
241 // ref |
253 // ref |
242 iRef = aReadStream.ReadUint32L(); |
254 iRef = aReadStream.ReadUint32L(); |
243 // size |
255 // size |
244 iSize = aReadStream.ReadUint32L( ); |
256 iBodySize = aReadStream.ReadUint32L( ); |
245 // size |
257 // size |
246 iHeaderSize = aReadStream.ReadUint32L( ); |
258 iHeaderSize = aReadStream.ReadUint32L( ); |
247 // protected |
259 // protected |
248 iProtected = aReadStream.ReadInt32L(); |
260 iProtected = aReadStream.ReadInt32L(); |
249 // |
261 // |
250 SetState( ECacheComplete ); ); |
262 SetState( ECacheComplete ); |
|
263 ); // end of TRAPD |
|
264 |
251 return err; |
265 return err; |
252 } |
266 } |
253 |
267 |
254 // ----------------------------------------------------------------------------- |
268 // ----------------------------------------------------------------------------- |
255 // CHttpCacheEntry::Externalize |
269 // CHttpCacheEntry::Externalize |
256 // |
270 // |
257 // ----------------------------------------------------------------------------- |
271 // ----------------------------------------------------------------------------- |
258 // |
272 // |
259 TInt CHttpCacheEntry::Externalize( |
273 TInt CHttpCacheEntry::Externalize( RFileWriteStream& aWriteStream ) |
260 RFileWriteStream& aWriteStream ) |
|
261 { |
274 { |
262 TRAPD( err, |
275 TRAPD( err, |
263 // url length |
276 // url length |
264 aWriteStream.WriteInt32L( iUrl->Length() ); |
277 aWriteStream.WriteInt32L( iUrl->Length() ); |
265 // url |
278 // url |
266 aWriteStream.WriteL( iUrl->Des() ); |
279 aWriteStream.WriteL( iUrl->Des() ); |
267 // filename length |
280 // filename length |
268 aWriteStream.WriteInt32L( iFileName->Length() ); |
281 aWriteStream.WriteInt32L( iFileName->Length() ); |
269 // filename |
282 // filename |
270 aWriteStream.WriteL( iFileName->Des() ); |
283 aWriteStream.WriteL( iFileName->Des() ); |
271 // la |
284 // la |
272 aWriteStream.WriteReal64L( iLastAccessed ); |
285 aWriteStream.WriteReal64L( iLastAccessed ); |
273 // ref |
286 // ref |
274 aWriteStream.WriteUint32L( iRef ); |
287 aWriteStream.WriteUint32L( iRef ); |
275 // size |
288 // size |
276 aWriteStream.WriteUint32L( iSize ); |
289 aWriteStream.WriteUint32L( iBodySize ); |
277 // size |
290 // size |
278 aWriteStream.WriteUint32L( iHeaderSize ); |
291 aWriteStream.WriteUint32L( iHeaderSize ); |
279 // protected |
292 // protected |
280 aWriteStream.WriteInt32L( iProtected ); ); |
293 aWriteStream.WriteInt32L( iProtected ); |
|
294 ); // end of TRAPD |
|
295 |
281 return err; |
296 return err; |
282 } |
297 } |
283 |
298 |
284 // ----------------------------------------------------------------------------- |
299 // ----------------------------------------------------------------------------- |
285 // CHttpCacheEntry::Accessed |
300 // CHttpCacheEntry::Accessed |
286 // |
301 // |
287 // ----------------------------------------------------------------------------- |
302 // ----------------------------------------------------------------------------- |
288 // |
303 // |
289 void CHttpCacheEntry::Accessed(TInt64 aLastAccessed, TUint16 aRef) |
304 void CHttpCacheEntry::Accessed( TInt64 aLastAccessed, TUint16 aRef ) |
290 { |
305 { |
291 iLastAccessed = aLastAccessed; |
306 iLastAccessed = aLastAccessed; |
292 iRef = aRef; |
307 iRef = aRef; |
293 if( iVictim ) |
308 if ( iEvictionCandidate ) |
294 { |
309 { |
295 iEvictionHandler->Accessed( *this ); |
310 iEvictionHandler->Accessed( *this ); |
296 } |
311 } |
|
312 |
297 #ifdef __CACHELOG__ |
313 #ifdef __CACHELOG__ |
298 _LIT( KAccessFormat, "entry accessed: %d" ); |
314 _LIT( KAccessFormat, "entry accessed: %d" ); |
299 TBuf<100> buf; |
315 TBuf<100> buf; |
300 buf.Format( KAccessFormat, iRef ); |
316 buf.Format( KAccessFormat, iRef ); |
301 HttpCacheUtil::WriteUrlToLog( 0, buf, iUrl->Des() ); |
317 HttpCacheUtil::WriteUrlToLog( 0, buf, iUrl->Des() ); |
302 #endif // __CACHELOG__ |
318 #endif // __CACHELOG__ |
303 |
319 |
304 } |
320 } |
305 |
321 |
|
322 // ----------------------------------------------------------------------------- |
|
323 // CHttpCacheEntry::SetCacheFilesOpened |
|
324 // |
|
325 // ----------------------------------------------------------------------------- |
|
326 // |
|
327 void CHttpCacheEntry::SetCacheFilesOpened( TBool aCacheFilesOpened ) |
|
328 { |
|
329 // Set our files open flag |
|
330 iCacheFilesOpened = aCacheFilesOpened; |
|
331 } |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // CHttpCacheEntry::CacheBuffer |
|
335 // NOTE: Cache buffer is created on: |
|
336 // 1. Normal content entrypoint into CacheManager |
|
337 // CacheManager::ReceivedResponseHeadersL -> CacheHandler::ReceivedResponseHeadersL -> |
|
338 // CacheHandler::HandleResponseOkL (calls method - SetCacheBuffer, needed to |
|
339 // accumulate body content on multiple CacheHandler::ReceivedBodyDataL calls) |
|
340 // 2. Multipart content entrypoint into CacheManager |
|
341 // CacheManager::SaveL -> CacheHandler::SaveL -> CacheHandler::SaveBuffer -> |
|
342 // CacheStreamHandler::SaveBodyData (calls this method - CacheBuffer, needed |
|
343 // because cacheBuffer=null and single call made, no accumulation of body data) |
|
344 // ----------------------------------------------------------------------------- |
|
345 // |
|
346 TPtr8 CHttpCacheEntry::CacheBuffer() |
|
347 { |
|
348 if ( iCacheBuffer == NULL ) |
|
349 { |
|
350 // Create the cache buffer, if needed |
|
351 iCacheBuffer = HBufC8::New( KBufferSize32k ); |
|
352 if ( iCacheBuffer == NULL ) |
|
353 { |
|
354 // OOM, return empty cache buffer |
|
355 TPtr8 emptyCacheBuffer( NULL, 0, 0 ); |
|
356 return emptyCacheBuffer; |
|
357 } |
|
358 } |
|
359 |
|
360 return iCacheBuffer->Des(); |
|
361 } |
|
362 |
|
363 // ----------------------------------------------------------------------------- |
|
364 // CHttpCacheEntry::SetCacheBufferL |
|
365 // |
|
366 // ----------------------------------------------------------------------------- |
|
367 // |
|
368 void CHttpCacheEntry::SetCacheBufferL( TInt aCacheBufferSize ) |
|
369 { |
|
370 if ( aCacheBufferSize > 0 && iCacheBuffer == NULL ) |
|
371 { |
|
372 iCacheBuffer = HBufC8::NewL( aCacheBufferSize ); |
|
373 } |
|
374 else if ( aCacheBufferSize <= 0 ) |
|
375 { |
|
376 delete iCacheBuffer; |
|
377 iCacheBuffer = NULL; |
|
378 } |
|
379 } |
306 // End of File |
380 // End of File |