|
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: Implementation of CHttpCacheFileWriteHandler |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CHTTPCACHEFILEWRITEHANDLER_H |
|
19 #define CHTTPCACHEFILEWRITEHANDLER_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32base.h> |
|
23 #include <f32file.h> |
|
24 #include "HttpCacheHandler.h" |
|
25 #include "MemoryManager.h" |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 // MACROS |
|
30 |
|
31 // DATA TYPES |
|
32 |
|
33 // FUNCTION PROTOTYPES |
|
34 class CAsyncFileWriter; |
|
35 class CHttpCacheWriteTimeout; |
|
36 |
|
37 // FORWARD DECLARATIONS |
|
38 |
|
39 // CLASS DECLARATION |
|
40 |
|
41 /** |
|
42 * |
|
43 * @lib |
|
44 * @since 5.0 |
|
45 */ |
|
46 NONSHARABLE_CLASS(CHttpCacheFileWriteHandler) : public CActive, public MMemoryCollector |
|
47 { |
|
48 public: // Constructors and destructor |
|
49 |
|
50 /** |
|
51 * Two-phased constructor. |
|
52 * @since 5.0 |
|
53 * @param |
|
54 * @param |
|
55 * @return CacheFileWriteHandler object. |
|
56 */ |
|
57 static CHttpCacheFileWriteHandler* NewL(CHttpCacheHandler* aManager, CHttpCacheStreamHandler* aStreamHandler, RFs& aRfs, const TInt aWriteTimeout); |
|
58 |
|
59 /** |
|
60 * Destructor. |
|
61 */ |
|
62 virtual ~CHttpCacheFileWriteHandler(); |
|
63 |
|
64 public: // From MMemoryCollector |
|
65 /** |
|
66 * Collect free memory, this function is called when allocation from |
|
67 * System heap fails |
|
68 * @since 3.1 |
|
69 * @param amount of memory needs to be collected |
|
70 * @return amount of memory collected |
|
71 */ |
|
72 virtual TUint Collect(TUint aRequired); |
|
73 |
|
74 /** |
|
75 * restore the entity controlled memory collector when there is enough memory |
|
76 * System heap fails |
|
77 * @since 3.1 |
|
78 * @param |
|
79 * @return |
|
80 */ |
|
81 virtual void Restore(); |
|
82 |
|
83 /** |
|
84 * Priority of this collector, 0 - lowest, 10 - highest; |
|
85 * the lower the priority, the earlier this collector is executed. |
|
86 * @since 3.1 |
|
87 * @param |
|
88 * @return |
|
89 */ |
|
90 virtual TOOMPriority Priority(); |
|
91 |
|
92 /** |
|
93 * |
|
94 * @since 7.1 |
|
95 * @param |
|
96 * @return |
|
97 */ |
|
98 TBool IsCacheEntryPostponed(const CHttpCacheEntry* aEntry); |
|
99 |
|
100 public: // new functions |
|
101 enum TAddStatus { |
|
102 EAddedOk, |
|
103 EBodySmallerThanThreshold, |
|
104 ENotEnoughFreeMemory, |
|
105 ECheckReturn |
|
106 }; |
|
107 |
|
108 /** |
|
109 * Add a cache entry to write out when possible |
|
110 * |
|
111 */ |
|
112 TInt AddEntry(TAddStatus& aAddStatus, CHttpCacheEntry *aEntry); |
|
113 |
|
114 /** |
|
115 * Remove a stream entry from the list |
|
116 */ |
|
117 CHttpCacheEntry* RemoveEntry(CHttpCacheEntry *aEntry); |
|
118 |
|
119 /** |
|
120 * Remove all stream entries from the list |
|
121 */ |
|
122 void RemoveAll(); |
|
123 |
|
124 /** |
|
125 * Emergency method if memory is short - write everything |
|
126 * to disk *now* and wait for it. Or maybe just dump it all |
|
127 * and delete the headers... |
|
128 */ |
|
129 void DumpAllObjects(); |
|
130 |
|
131 /** |
|
132 * Signal called by the timer callback to indicate that we |
|
133 * should begin writing out the cached data. |
|
134 */ |
|
135 void BeginWriting(); |
|
136 |
|
137 private: |
|
138 |
|
139 /** |
|
140 * Construct. |
|
141 * @since 5.0 |
|
142 * @param |
|
143 * @param |
|
144 * @return CacheFileWriteHandler object. |
|
145 */ |
|
146 CHttpCacheFileWriteHandler(CHttpCacheHandler* aHandler, CHttpCacheStreamHandler* aStreamHandler, RFs& aRfs); |
|
147 |
|
148 /** |
|
149 * By default Symbian 2nd phase constructor is private. |
|
150 */ |
|
151 void ConstructL(const TInt aWriteTimeout); |
|
152 |
|
153 /** |
|
154 * from CActive |
|
155 */ |
|
156 void DoCancel(); |
|
157 |
|
158 /** |
|
159 * from CActive |
|
160 */ |
|
161 void RunL(); |
|
162 |
|
163 void ContinueFlushing(); |
|
164 |
|
165 void OutputQueueContentToDebug(); |
|
166 |
|
167 // sort by size function for arrays of CHttpCacheEntry objects. |
|
168 static TInt CompareHttpCacheEntrySize( const CHttpCacheEntry& aFirst, const CHttpCacheEntry& aSecond ); |
|
169 void CollectMemory( TUint aRequired ); |
|
170 |
|
171 /** |
|
172 * Callback function for timer to activate writing. |
|
173 */ |
|
174 static TInt WriteTimeout(TAny* aParam); |
|
175 |
|
176 private: // Data |
|
177 CHttpCacheHandler* iCacheHandler; |
|
178 CHttpCacheStreamHandler* iCacheStreamHandler; |
|
179 TInt iFreeRamThreshold; |
|
180 TInt iImmediateWriteThreshold; |
|
181 TBool iLowMemoryState; |
|
182 RFs iFs; |
|
183 CHttpCacheWriteTimeout* iWaitTimer; |
|
184 // objects in this array are not owned. |
|
185 RPointerArray<CHttpCacheEntry> iObjectQueue; |
|
186 // contains a pointer to the object that flush was called for |
|
187 CHttpCacheEntry* iObjectFlushing; |
|
188 }; |
|
189 |
|
190 #endif // CHttpCacheFileWriteHandler_H |
|
191 |
|
192 // End of File |