|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Definition of CHttpCacheHandler |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CHTTPCACHEHANDLER_H |
|
19 #define CHTTPCACHEHANDLER_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32base.h> |
|
23 #include <BrCtlDefs.h> |
|
24 #include <http\rhttpsession.h> |
|
25 #include <stringpool.h> |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 // MACROS |
|
30 |
|
31 // DATA TYPES |
|
32 |
|
33 // FUNCTION PROTOTYPES |
|
34 |
|
35 // FORWARD DECLARATIONS |
|
36 class CHttpCacheEntry; |
|
37 class CHttpCacheLookupTable; |
|
38 class CHttpCacheStreamHandler; |
|
39 class RHTTPTransaction; |
|
40 class RHTTPHeaders; |
|
41 class RStringPool; |
|
42 class MHTTPDataSupplier; |
|
43 class CIdle; |
|
44 class CHttpCacheEvictionHandler; |
|
45 class THttpCacheEntry; |
|
46 class CHttpCacheObserver; |
|
47 |
|
48 // CLASS DECLARATION |
|
49 |
|
50 /** |
|
51 * |
|
52 * @lib |
|
53 * @since 3.1 |
|
54 */ |
|
55 class CHttpCacheHandler : public CBase |
|
56 { |
|
57 public: // Constructors and destructor |
|
58 |
|
59 /** |
|
60 * Two-phased constructor. |
|
61 * @since 3.1 |
|
62 * @param |
|
63 * @param |
|
64 * @return CacheHandler object. |
|
65 */ |
|
66 static CHttpCacheHandler* NewL( TInt aSize, |
|
67 const TDesC& aDirectory, |
|
68 const TDesC& aIndexFile, |
|
69 TInt aCriticalLevel ); |
|
70 |
|
71 /** |
|
72 * Destructor. |
|
73 */ |
|
74 virtual ~CHttpCacheHandler(); |
|
75 |
|
76 public: // new functions |
|
77 |
|
78 /** |
|
79 * |
|
80 * @since 3.1 |
|
81 * @param |
|
82 * @return |
|
83 */ |
|
84 TInt RequestL( RHTTPTransaction& aTrans, TBrCtlDefs::TBrCtlCacheMode aCacheMode, THttpCacheEntry& aCacheEntry ); |
|
85 |
|
86 /** |
|
87 * |
|
88 * @since 3.1 |
|
89 * @param |
|
90 * @return |
|
91 */ |
|
92 TInt RequestHeadersL( RHTTPTransaction& aTrans, THttpCacheEntry& aCacheEntry ); |
|
93 |
|
94 /** |
|
95 * |
|
96 * @since 3.1 |
|
97 * @param |
|
98 * @return |
|
99 */ |
|
100 HBufC8* RequestNextChunkL( RHTTPTransaction& aTrans, TBool& aLastChunk, THttpCacheEntry& aCacheEntry ); |
|
101 |
|
102 /** |
|
103 * |
|
104 * @since 3.1 |
|
105 * @param |
|
106 * @return |
|
107 */ |
|
108 void ReceivedResponseHeadersL( RHTTPTransaction& aTrans, THttpCacheEntry& aCacheEntry ); |
|
109 |
|
110 /** |
|
111 * |
|
112 * @since 3.1 |
|
113 * @param |
|
114 * @return |
|
115 */ |
|
116 void ReceivedResponseBodyDataL( RHTTPTransaction& aTrans, MHTTPDataSupplier& aBodyDataSupplier, THttpCacheEntry& aCacheEntry ); |
|
117 |
|
118 /** |
|
119 * |
|
120 * @since 3.1 |
|
121 * @param |
|
122 * @return |
|
123 */ |
|
124 void ResponseComplete( RHTTPTransaction& aTrans, THttpCacheEntry& aCacheEntry ); |
|
125 |
|
126 /** |
|
127 * |
|
128 * @since 3.1 |
|
129 * @param |
|
130 * @return |
|
131 */ |
|
132 void RequestClosed( RHTTPTransaction* aTrans, THttpCacheEntry& aCacheEntry ); |
|
133 |
|
134 /** |
|
135 * |
|
136 * @since 3.1 |
|
137 * @param |
|
138 * @return |
|
139 */ |
|
140 TInt RemoveAllL(); |
|
141 |
|
142 /** |
|
143 * |
|
144 * @since 7.1 |
|
145 * @param |
|
146 * @return |
|
147 */ |
|
148 TInt CHttpCacheHandler::ListFiles(RPointerArray<TDesC>& aFilenameList); |
|
149 |
|
150 /** |
|
151 * |
|
152 * @since 3.1 |
|
153 * @param |
|
154 * @return |
|
155 */ |
|
156 TInt RemoveL( const TDesC8& aUrl ); |
|
157 |
|
158 /** |
|
159 * |
|
160 * @since 3.1 |
|
161 * @param |
|
162 * @return |
|
163 */ |
|
164 TBool Find( const TDesC8& aUrl ); |
|
165 |
|
166 /** |
|
167 * |
|
168 * @since 3.1 |
|
169 * @param |
|
170 * @return |
|
171 */ |
|
172 TBool SaveL( const TDesC8& aUrl, const TDesC8& aHeader, const TDesC8& aContent ); |
|
173 |
|
174 /** |
|
175 * |
|
176 * @since 3.1 |
|
177 * @param |
|
178 * @return |
|
179 */ |
|
180 TInt AddHeaderL( const TDesC8& aUrl, const TDesC8& aName, const TDesC8& aValue ); |
|
181 |
|
182 /** |
|
183 * Some time response time form the origin server is not matching |
|
184 * with GMt time. Adjust the response time. |
|
185 * |
|
186 * @since 3.1 |
|
187 * @param |
|
188 * @return |
|
189 */ |
|
190 void AdjustResponseTime(RHTTPTransaction& aTrans); |
|
191 |
|
192 /** |
|
193 * Some other application modified the cache and the lookup table needs to be updated |
|
194 * |
|
195 * @since 3.1 |
|
196 * @param |
|
197 * @return |
|
198 */ |
|
199 void UpdateLookupTable(); |
|
200 |
|
201 private: |
|
202 |
|
203 /** |
|
204 * Construct. |
|
205 * @since 3.1 |
|
206 * @param |
|
207 * @param |
|
208 * @return CacheHandler object. |
|
209 */ |
|
210 CHttpCacheHandler( TInt aSize ); |
|
211 |
|
212 /** |
|
213 * By default Symbian 2nd phase constructor is private. |
|
214 */ |
|
215 void ConstructL( const TDesC& aDirectory, const TDesC& aIndexFile, TInt aCriticalLevel); |
|
216 |
|
217 private: // |
|
218 |
|
219 /** |
|
220 * Some other application modified the cache and the lookup table needs to be updated |
|
221 * |
|
222 * @since 3.1 |
|
223 * @param |
|
224 * @return |
|
225 */ |
|
226 void UpdateLookupTableL(); |
|
227 |
|
228 /** |
|
229 * |
|
230 * @since 3.1 |
|
231 * @param |
|
232 * @param |
|
233 * @return |
|
234 */ |
|
235 TBool CacheNeedsValidationL( CHttpCacheEntry& aCacheEntry, RHTTPTransaction& aTrans, TBrCtlDefs::TBrCtlCacheMode aCacheMode ); |
|
236 |
|
237 /** |
|
238 * |
|
239 * @since 3.1 |
|
240 * @param |
|
241 * @param |
|
242 * @return |
|
243 */ |
|
244 TBool CacheNeedsSpaceL( TInt aSize ); |
|
245 |
|
246 /** |
|
247 * |
|
248 * @since 3.1 |
|
249 * @param |
|
250 * @param |
|
251 * @return |
|
252 */ |
|
253 TBool IsCacheable( RHTTPTransaction& aTrans, TBool& aProtectedEntry ); |
|
254 |
|
255 /** |
|
256 * |
|
257 * @since 3.1 |
|
258 * @param |
|
259 * @param |
|
260 * @return |
|
261 */ |
|
262 TBool HandleResponseOkL( CHttpCacheEntry& aEntry, RHTTPTransaction& aTrans ); |
|
263 |
|
264 /** |
|
265 * |
|
266 * @since 3.1 |
|
267 * @param |
|
268 * @param |
|
269 * @return |
|
270 */ |
|
271 TBool HandleResponseNotModifiedL( CHttpCacheEntry& aEntry, RHTTPTransaction& aTrans ); |
|
272 |
|
273 /** |
|
274 * |
|
275 * @since 3.1 |
|
276 * @param |
|
277 * @param |
|
278 * @return |
|
279 */ |
|
280 void SaveLookupTableL(); |
|
281 |
|
282 /** |
|
283 * |
|
284 * @since 3.1 |
|
285 * @param |
|
286 * @param |
|
287 * @return |
|
288 */ |
|
289 void OpenLookupTableL(); |
|
290 |
|
291 /** |
|
292 * |
|
293 * @since 3.1 |
|
294 * @param |
|
295 * @param |
|
296 * @return |
|
297 */ |
|
298 void OpenLookupTableL(CHttpCacheLookupTable* aLookupTable); |
|
299 |
|
300 /** |
|
301 * |
|
302 * @since 3.1 |
|
303 * @param |
|
304 * @param |
|
305 * @return |
|
306 */ |
|
307 void HandleCorruptEntry( CHttpCacheEntry& aStrayEntry, TBool aUpdate = ETrue ); |
|
308 |
|
309 |
|
310 /** |
|
311 * |
|
312 * @since 3.1 |
|
313 * @param |
|
314 * @param |
|
315 * @return |
|
316 */ |
|
317 TBool SaveBuffer( CHttpCacheEntry& aEntry, const TDesC8& aBuffer, TBool aBody = EFalse ); |
|
318 |
|
319 private: // Data |
|
320 |
|
321 // hash table for cache entries |
|
322 CHttpCacheLookupTable* iLookupTable; // owned |
|
323 // stream manager |
|
324 CHttpCacheStreamHandler* iStreamHandler; // owned |
|
325 // |
|
326 CHttpCacheEvictionHandler* iEvictionHandler; // owned |
|
327 // cache size |
|
328 TInt iSize; |
|
329 // cache directory |
|
330 HBufC* iDirectory; // owned |
|
331 // name of the index file |
|
332 HBufC* iIndexFile; // owned |
|
333 // Observing changes in cache |
|
334 CHttpCacheObserver* iHttpCacheObserver; // owned |
|
335 // An opened and configured file server session |
|
336 RFs iRfs; |
|
337 }; |
|
338 |
|
339 #endif // CHTTPCACHEHANDLER_H |
|
340 |
|
341 // End of File |