|
1 /* |
|
2 * CookieClientDataArray.cpp |
|
3 * |
|
4 * Created on: Dec 18, 2009 |
|
5 * Author: mohanti |
|
6 */ |
|
7 |
|
8 //System Includes |
|
9 #include <e32cmn.h> |
|
10 #include <e32base.h> |
|
11 #include <e32std.h> |
|
12 |
|
13 //User Includes |
|
14 #include "CookieClientDataArray.h" |
|
15 #include "CookieManagerClient.h" |
|
16 #include "CookieArray.h" |
|
17 #include "CookieLogger.h" |
|
18 #include "CookieClientData.h" |
|
19 |
|
20 //Constatnts |
|
21 const TInt KCookieArrayGranularity = 10; |
|
22 |
|
23 // --------------------------------------------------------- |
|
24 // CCookieClientDataArray::GetInstance |
|
25 // --------------------------------------------------------- |
|
26 // |
|
27 CCookieClientDataArray* CCookieClientDataArray::GetInstance() |
|
28 { |
|
29 CLOG( ( EClient, 0, _L( "-> CCookieClientDataArray::GetInstance" ) ) ); |
|
30 CCookieClientDataArray *clientInstance = static_cast<CCookieClientDataArray*> (Dll::Tls()); |
|
31 if (!clientInstance) |
|
32 { |
|
33 clientInstance = new (ELeave) CCookieClientDataArray(); |
|
34 Dll::SetTls(clientInstance); |
|
35 } |
|
36 CLOG( ( EClient, 0, _L( "<- CCookieClientDataArray::GetInstance instance = %x" ),clientInstance ) ); |
|
37 return clientInstance; |
|
38 } |
|
39 // --------------------------------------------------------- |
|
40 // CCookieClientDataArray::DeRef |
|
41 // --------------------------------------------------------- |
|
42 // |
|
43 void CCookieClientDataArray::DeRef() |
|
44 { |
|
45 CLOG( ( EClient, 0, _L( "-> CCookieClientDataArray::Deref" ) ) ); |
|
46 --iRefCount; |
|
47 if (iRefCount <= 0) |
|
48 { |
|
49 delete iCookieClientData; |
|
50 iCookieClientData = NULL; |
|
51 Dll::SetTls(0); |
|
52 CLOG( ( EClient, 0, _L( "<- CCookieClientDataArray::Deref deletes iCookieClientData" ) ) ); |
|
53 } |
|
54 CLOG( ( EClient, 0, _L( "<- CCookieClientDataArray::Deref" ) ) ); |
|
55 } |
|
56 // --------------------------------------------------------- |
|
57 // CCookieClientDataArray::ConstructL |
|
58 // --------------------------------------------------------- |
|
59 // |
|
60 CCookieClientDataArray::CCookieClientDataArray():iRefCount(0) |
|
61 { |
|
62 CLOG( ( EClient, 0, _L( "-> CCookieClientDataArray::ConstructL" ) ) ); |
|
63 iCookieClientData = new (ELeave) RPointerArray<CCookieClientData>(KCookieArrayGranularity); |
|
64 CLOG( ( EClient, 0, _L( "<- CCookieClientDataArray::ConstructL" ) ) ); |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------- |
|
68 // CCookieClientDataArray::~CCookieClientDataArray |
|
69 // --------------------------------------------------------- |
|
70 // |
|
71 CCookieClientDataArray::~CCookieClientDataArray() |
|
72 { |
|
73 CLOG( ( EClient, 0, _L( "-> CCookieClientDataArray::~CCookieClientDataArray" ) ) ); |
|
74 if(iCookieClientData && iCookieClientData->Count()) |
|
75 { |
|
76 iCookieClientData->ResetAndDestroy(); |
|
77 iCookieClientData->Close(); |
|
78 //delete iCookieClientData; |
|
79 iCookieClientData = NULL; |
|
80 } |
|
81 CLOG( ( EClient, 0, _L( "<- CCookieClientDataArray::~CCookieClientDataArray" ) ) ); |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------- |
|
85 // CCookieClientDataArray::Count |
|
86 // --------------------------------------------------------- |
|
87 // |
|
88 TInt CCookieClientDataArray::Count()const |
|
89 { |
|
90 if (iCookieClientData) |
|
91 return iCookieClientData->Count(); |
|
92 else |
|
93 return 0; |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------- |
|
97 // CCookieClientDataArray::Compress |
|
98 // --------------------------------------------------------- |
|
99 // |
|
100 void CCookieClientDataArray::AddClientGroupDataL(CCookieClientData* aCookieClientData) |
|
101 { |
|
102 CLOG( ( EClient, 0, _L( "-> CCookieClientDataArray::AddGroupDataL" ) ) ); |
|
103 iCookieClientData->AppendL(aCookieClientData); |
|
104 CLOG( ( EClient, 0, _L( "<- CCookieClientDataArray::AddGroupDataL" ) ) ); |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------- |
|
108 // CCookieClientDataArray::Compress |
|
109 // --------------------------------------------------------- |
|
110 // |
|
111 void CCookieClientDataArray::Compress() |
|
112 { |
|
113 CLOG( ( EClient, 0, _L( "-> CCookieClientDataArray::Compress" ) ) ); |
|
114 iCookieClientData->Compress(); |
|
115 CLOG( ( EClient, 0, _L( "<- CCookieClientDataArray::Compress" ) ) ); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------- |
|
119 // CCookieClientDataArray::operator[] |
|
120 // --------------------------------------------------------- |
|
121 // |
|
122 CCookieClientData* CCookieClientDataArray::operator[](TInt aIndex) const |
|
123 { |
|
124 return (*iCookieClientData)[aIndex]; |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------- |
|
128 // CCookieClientDataArray::At |
|
129 // --------------------------------------------------------- |
|
130 // |
|
131 CCookieClientData* CCookieClientDataArray::At(TInt aIndex) const |
|
132 { |
|
133 return (*iCookieClientData)[ aIndex ]; |
|
134 } |
|
135 // --------------------------------------------------------- |
|
136 // CCookieClientDataArray::Find |
|
137 // --------------------------------------------------------- |
|
138 // |
|
139 CCookieClientData* CCookieClientDataArray::Find(const TUint32& aGroupId, const TUint32& aWidgetUid ) |
|
140 { |
|
141 CLOG( ( EClient, 0, _L( "-> CCookieClientDataArray::Find GroupId = %x, WidgetUid = %x" ),aGroupId,aWidgetUid ) ); |
|
142 TInt total = Count(); |
|
143 TBool WidgetUidFound = EFalse; |
|
144 TInt index = 0; |
|
145 for ( TInt i = 0;i<total;i++ ) |
|
146 { |
|
147 if (At(i)->GetGroupId()== aGroupId && (At(i)->GetCookieSharableFlag())) |
|
148 { |
|
149 WidgetUidFound = ETrue; |
|
150 index = i; |
|
151 break; |
|
152 } |
|
153 else if (At(i)->GetGroupId()== aGroupId && !(At(i)->GetCookieSharableFlag()) |
|
154 && (At(i)->GetWidgetUid()== aWidgetUid)) |
|
155 { |
|
156 WidgetUidFound = ETrue; |
|
157 index = i; |
|
158 break; |
|
159 } |
|
160 } |
|
161 if ( WidgetUidFound ) |
|
162 { |
|
163 CLOG( ( EClient, 0, _L( "<- CCookieClientDataArray::Find found with index = %d" ),index ) ); |
|
164 return At(index); |
|
165 } |
|
166 else |
|
167 { |
|
168 CLOG( ( EClient, 0, _L( "<- CCookieClientDataArray::Find not found " ) ) ); |
|
169 return NULL; |
|
170 } |
|
171 } |
|
172 // --------------------------------------------------------- |
|
173 // CCookieClientDataArray::FindIndex |
|
174 // --------------------------------------------------------- |
|
175 // |
|
176 TInt CCookieClientDataArray::FindIndex(const TUint32& aGroupId, const TUint32& aWidgetUid,TInt& aIndex ) |
|
177 { |
|
178 CLOG( ( EClient, 0, _L( "-> CCookieClientDataArray::FindIndex GroupId = %x,WidgetUid = %x" ) |
|
179 ,aGroupId,aWidgetUid ) ); |
|
180 TInt total = Count(); |
|
181 TBool WidgetUidFound = EFalse; |
|
182 TInt index = 0; |
|
183 for ( TInt i = 0;i<total;i++ ) |
|
184 { |
|
185 if (At(i)->GetGroupId()== aGroupId && (At(i)->GetCookieSharableFlag())) |
|
186 { |
|
187 WidgetUidFound = ETrue; |
|
188 index = i; |
|
189 break; |
|
190 } |
|
191 else if (At(i)->GetGroupId()== aGroupId && !(At(i)->GetCookieSharableFlag()) |
|
192 && (At(i)->GetWidgetUid()== aWidgetUid)) |
|
193 { |
|
194 WidgetUidFound = ETrue; |
|
195 index = i; |
|
196 break; |
|
197 } |
|
198 } |
|
199 if ( WidgetUidFound ) |
|
200 { |
|
201 aIndex = index; |
|
202 CLOG( ( EClient, 0, _L( "<- CCookieClientDataArray::FindIndex found with index = %d" ),index ) ); |
|
203 return KErrNone; |
|
204 } |
|
205 else |
|
206 { |
|
207 CLOG( ( EClient, 0, _L( "<- CCookieClientDataArray::FindIndex not found " ) ) ); |
|
208 return KErrNotFound; |
|
209 } |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------- |
|
213 // CCookieClientDataArray::CookieArray |
|
214 // --------------------------------------------------------- |
|
215 // |
|
216 CCookieArray* CCookieClientDataArray::CookieArray(TInt aIndex) |
|
217 { |
|
218 CLOG( ( EClient, 0, _L( "-> CCookieClientDataArray::CookieArray Index =%d" ),aIndex ) ); |
|
219 CCookieClientData* cookieclientdata = At(aIndex); |
|
220 return cookieclientdata->CookieArray(); |
|
221 } |
|
222 |
|
223 |
|
224 // --------------------------------------------------------- |
|
225 // CCookieClientDataArray::Remove |
|
226 // --------------------------------------------------------- |
|
227 // |
|
228 void CCookieClientDataArray::Remove(TInt aIndex) |
|
229 { |
|
230 CLOG( ( EClient, 0, _L( "-> CCookieClientDataArray::Remove %d" ), aIndex ) ); |
|
231 delete (*iCookieClientData)[ aIndex ]; |
|
232 iCookieClientData->Remove(aIndex); |
|
233 iCookieClientData->Compress(); |
|
234 CLOG( ( EClient, 0, _L( "<- CCookieClientDataArray::Remove " )) ); |
|
235 } |
|
236 |
|
237 |
|
238 // --------------------------------------------------------- |
|
239 // CCookieClientDataArray::DestroyGroupData |
|
240 // --------------------------------------------------------- |
|
241 // |
|
242 TInt CCookieClientDataArray::DestroyClientData(const TUint32 aAppUid) |
|
243 { |
|
244 CLOG( ( EClient, 0, _L( "-> CCookieClientDataArray::DestroyClientData" ) ) ); |
|
245 TUint32 groupid = RProcess().SecureId().iId; |
|
246 TInt index = -1; |
|
247 TInt err = FindIndex(groupid,aAppUid,index); |
|
248 if ( err == KErrNone ) |
|
249 { |
|
250 Remove(index); |
|
251 } |
|
252 CLOG( ( EClient, 0, _L( "<- CCookieClientDataArray::DestroyClientData removed index = %d" ),index ) ); |
|
253 return err; |
|
254 } |
|
255 //EOF |