OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_COOKIES_TREE_MODEL_H_ | 5 #ifndef CHROME_BROWSER_COOKIES_TREE_MODEL_H_ |
6 #define CHROME_BROWSER_COOKIES_TREE_MODEL_H_ | 6 #define CHROME_BROWSER_COOKIES_TREE_MODEL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "app/tree_node_model.h" | 11 #include "app/tree_node_model.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "chrome/browser/browsing_data_appcache_helper.h" |
13 #include "chrome/browser/browsing_data_database_helper.h" | 14 #include "chrome/browser/browsing_data_database_helper.h" |
14 #include "chrome/browser/browsing_data_local_storage_helper.h" | 15 #include "chrome/browser/browsing_data_local_storage_helper.h" |
15 #include "net/base/cookie_monster.h" | 16 #include "net/base/cookie_monster.h" |
16 | 17 |
17 class CookiesTreeModel; | 18 class CookiesTreeModel; |
| 19 class CookieTreeAppCacheNode; |
| 20 class CookieTreeAppCachesNode; |
| 21 class CookieTreeCookieNode; |
| 22 class CookieTreeCookiesNode; |
| 23 class CookieTreeDatabaseNode; |
| 24 class CookieTreeDatabasesNode; |
18 class CookieTreeLocalStorageNode; | 25 class CookieTreeLocalStorageNode; |
19 class CookieTreeLocalStoragesNode; | 26 class CookieTreeLocalStoragesNode; |
20 class CookieTreeDatabaseNode; | |
21 class CookieTreeDatabasesNode; | |
22 class CookieTreeCookieNode; | |
23 class CookieTreeCookiesNode; | |
24 class CookieTreeOriginNode; | 27 class CookieTreeOriginNode; |
25 class Profile; | 28 class Profile; |
26 | 29 |
27 // CookieTreeNode ------------------------------------------------------------- | 30 // CookieTreeNode ------------------------------------------------------------- |
28 // The base node type in the Cookies, Databases, and Local Storage options | 31 // The base node type in the Cookies, Databases, and Local Storage options |
29 // view, from which all other types are derived. Specialized from TreeNode in | 32 // view, from which all other types are derived. Specialized from TreeNode in |
30 // that it has a notion of deleting objects stored in the profile, and being | 33 // that it has a notion of deleting objects stored in the profile, and being |
31 // able to have its children do the same. | 34 // able to have its children do the same. |
32 class CookieTreeNode : public TreeNode<CookieTreeNode> { | 35 class CookieTreeNode : public TreeNode<CookieTreeNode> { |
33 public: | 36 public: |
34 // Used to pull out information for the InfoView (the details display below | 37 // Used to pull out information for the InfoView (the details display below |
35 // the tree control.) | 38 // the tree control.) |
36 struct DetailedInfo { | 39 struct DetailedInfo { |
37 // NodeType corresponds to the various CookieTreeNode types. | 40 // NodeType corresponds to the various CookieTreeNode types. |
38 enum NodeType { | 41 enum NodeType { |
39 TYPE_ROOT, // This is used for CookieTreeRootNode nodes. | 42 TYPE_ROOT, // This is used for CookieTreeRootNode nodes. |
40 TYPE_ORIGIN, // This is used for CookieTreeOriginNode nodes. | 43 TYPE_ORIGIN, // This is used for CookieTreeOriginNode nodes. |
41 TYPE_COOKIES, // This is used for CookieTreeCookiesNode nodes. | 44 TYPE_COOKIES, // This is used for CookieTreeCookiesNode nodes. |
42 TYPE_COOKIE, // This is used for CookieTreeCookieNode nodes. | 45 TYPE_COOKIE, // This is used for CookieTreeCookieNode nodes. |
43 TYPE_DATABASES, // This is used for CookieTreeDatabasesNode. | 46 TYPE_DATABASES, // This is used for CookieTreeDatabasesNode. |
44 TYPE_DATABASE, // This is used for CookieTreeDatabaseNode. | 47 TYPE_DATABASE, // This is used for CookieTreeDatabaseNode. |
45 TYPE_LOCAL_STORAGES, // This is used for CookieTreeLocalStoragesNode. | 48 TYPE_LOCAL_STORAGES, // This is used for CookieTreeLocalStoragesNode. |
46 TYPE_LOCAL_STORAGE, // This is used for CookieTreeLocalStorageNode. | 49 TYPE_LOCAL_STORAGE, // This is used for CookieTreeLocalStorageNode. |
| 50 TYPE_APPCACHES, // This is used for CookieTreeAppCachesNode. |
| 51 TYPE_APPCACHE, // This is used for CookieTreeAppCacheNode. |
47 }; | 52 }; |
48 | 53 |
49 DetailedInfo(const std::wstring& origin, NodeType node_type, | 54 DetailedInfo(const std::wstring& origin, NodeType node_type, |
50 const net::CookieMonster::CookieListPair* cookie, | 55 const net::CookieMonster::CookieListPair* cookie, |
51 const BrowsingDataDatabaseHelper::DatabaseInfo* database_info, | 56 const BrowsingDataDatabaseHelper::DatabaseInfo* database_info, |
52 const BrowsingDataLocalStorageHelper::LocalStorageInfo* | 57 const BrowsingDataLocalStorageHelper::LocalStorageInfo* |
53 local_storage_info) | 58 local_storage_info, |
| 59 const BrowsingDataAppCacheHelper::AppCacheInfo* appcache_info) |
54 : origin(origin), | 60 : origin(origin), |
55 node_type(node_type), | 61 node_type(node_type), |
56 cookie(cookie), | 62 cookie(cookie), |
57 database_info(database_info), | 63 database_info(database_info), |
58 local_storage_info(local_storage_info) { | 64 local_storage_info(local_storage_info), |
59 if (node_type == TYPE_DATABASE) | 65 appcache_info(appcache_info) { |
60 DCHECK(database_info); | 66 DCHECK((node_type != TYPE_DATABASE) || database_info); |
61 if (node_type == TYPE_LOCAL_STORAGE) | 67 DCHECK((node_type != TYPE_LOCAL_STORAGE) || local_storage_info); |
62 DCHECK(local_storage_info); | 68 DCHECK((node_type != TYPE_APPCACHE) || appcache_info); |
63 } | 69 } |
64 | 70 |
65 std::wstring origin; | 71 std::wstring origin; |
66 NodeType node_type; | 72 NodeType node_type; |
67 const net::CookieMonster::CookieListPair* cookie; | 73 const net::CookieMonster::CookieListPair* cookie; |
68 const BrowsingDataDatabaseHelper::DatabaseInfo* database_info; | 74 const BrowsingDataDatabaseHelper::DatabaseInfo* database_info; |
69 const BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info; | 75 const BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info; |
| 76 const BrowsingDataAppCacheHelper::AppCacheInfo* appcache_info; |
70 }; | 77 }; |
71 | 78 |
72 CookieTreeNode() {} | 79 CookieTreeNode() {} |
73 explicit CookieTreeNode(const std::wstring& title) | 80 explicit CookieTreeNode(const std::wstring& title) |
74 : TreeNode<CookieTreeNode>(title) {} | 81 : TreeNode<CookieTreeNode>(title) {} |
| 82 virtual ~CookieTreeNode() {} |
75 | 83 |
76 // Delete backend storage for this node, and any children nodes. (E.g. delete | 84 // Delete backend storage for this node, and any children nodes. (E.g. delete |
77 // the cookie from CookieMonster, clear the database, and so forth.) | 85 // the cookie from CookieMonster, clear the database, and so forth.) |
78 virtual void DeleteStoredObjects(); | 86 virtual void DeleteStoredObjects(); |
79 | 87 |
80 // Gets a pointer back to the associated model for the tree we are in. | 88 // Gets a pointer back to the associated model for the tree we are in. |
81 virtual CookiesTreeModel* GetModel() const; | 89 virtual CookiesTreeModel* GetModel() const; |
82 | 90 |
83 // Returns a struct with detailed information used to populate the details | 91 // Returns a struct with detailed information used to populate the details |
84 // part of the view. | 92 // part of the view. |
85 virtual DetailedInfo GetDetailedInfo() const = 0; | 93 virtual DetailedInfo GetDetailedInfo() const = 0; |
86 | 94 |
| 95 protected: |
| 96 class NodeTitleComparator { |
| 97 public: |
| 98 bool operator() (const CookieTreeNode* lhs, const CookieTreeNode* rhs); |
| 99 }; |
| 100 |
| 101 void AddChildSortedByTitle(CookieTreeNode* new_child); |
| 102 |
87 private: | 103 private: |
88 | 104 |
89 DISALLOW_COPY_AND_ASSIGN(CookieTreeNode); | 105 DISALLOW_COPY_AND_ASSIGN(CookieTreeNode); |
90 }; | 106 }; |
91 | 107 |
92 // CookieTreeRootNode --------------------------------------------------------- | 108 // CookieTreeRootNode --------------------------------------------------------- |
93 // The node at the root of the CookieTree that gets inserted into the view. | 109 // The node at the root of the CookieTree that gets inserted into the view. |
94 class CookieTreeRootNode : public CookieTreeNode { | 110 class CookieTreeRootNode : public CookieTreeNode { |
95 public: | 111 public: |
96 explicit CookieTreeRootNode(CookiesTreeModel* model) : model_(model) {} | 112 explicit CookieTreeRootNode(CookiesTreeModel* model) : model_(model) {} |
97 virtual ~CookieTreeRootNode() {} | 113 virtual ~CookieTreeRootNode() {} |
98 | 114 |
99 CookieTreeOriginNode* GetOrCreateOriginNode(const std::wstring& origin); | 115 CookieTreeOriginNode* GetOrCreateOriginNode(const std::wstring& origin); |
100 | 116 |
101 // CookieTreeNode methods: | 117 // CookieTreeNode methods: |
102 virtual CookiesTreeModel* GetModel() const { return model_; } | 118 virtual CookiesTreeModel* GetModel() const { return model_; } |
103 virtual DetailedInfo GetDetailedInfo() const { | 119 virtual DetailedInfo GetDetailedInfo() const { |
104 return DetailedInfo(std::wstring(), DetailedInfo::TYPE_ROOT, NULL, NULL, | 120 return DetailedInfo(std::wstring(), DetailedInfo::TYPE_ROOT, NULL, NULL, |
105 NULL); | 121 NULL, NULL); |
106 } | 122 } |
107 private: | 123 private: |
108 | 124 |
109 CookiesTreeModel* model_; | 125 CookiesTreeModel* model_; |
110 | 126 |
111 DISALLOW_COPY_AND_ASSIGN(CookieTreeRootNode); | 127 DISALLOW_COPY_AND_ASSIGN(CookieTreeRootNode); |
112 }; | 128 }; |
113 | 129 |
114 // CookieTreeOriginNode ------------------------------------------------------- | 130 // CookieTreeOriginNode ------------------------------------------------------- |
115 class CookieTreeOriginNode : public CookieTreeNode { | 131 class CookieTreeOriginNode : public CookieTreeNode { |
116 public: | 132 public: |
117 explicit CookieTreeOriginNode(const std::wstring& origin) | 133 explicit CookieTreeOriginNode(const std::wstring& origin) |
118 : CookieTreeNode(origin), | 134 : CookieTreeNode(origin), |
119 cookies_child_(NULL), | 135 cookies_child_(NULL), |
120 databases_child_(NULL), | 136 databases_child_(NULL), |
121 local_storages_child_(NULL) {} | 137 local_storages_child_(NULL), |
| 138 appcaches_child_(NULL) {} |
122 virtual ~CookieTreeOriginNode() {} | 139 virtual ~CookieTreeOriginNode() {} |
123 | 140 |
124 // CookieTreeNode methods: | 141 // CookieTreeNode methods: |
125 virtual DetailedInfo GetDetailedInfo() const { | 142 virtual DetailedInfo GetDetailedInfo() const { |
126 return DetailedInfo(GetTitle(), DetailedInfo::TYPE_ORIGIN, NULL, NULL, | 143 return DetailedInfo(GetTitle(), DetailedInfo::TYPE_ORIGIN, NULL, NULL, |
127 NULL); | 144 NULL, NULL); |
128 } | 145 } |
129 | 146 |
130 // CookieTreeOriginNode methods: | 147 // CookieTreeOriginNode methods: |
131 CookieTreeCookiesNode* GetOrCreateCookiesNode(); | 148 CookieTreeCookiesNode* GetOrCreateCookiesNode(); |
132 CookieTreeDatabasesNode* GetOrCreateDatabasesNode(); | 149 CookieTreeDatabasesNode* GetOrCreateDatabasesNode(); |
133 CookieTreeLocalStoragesNode* GetOrCreateLocalStoragesNode(); | 150 CookieTreeLocalStoragesNode* GetOrCreateLocalStoragesNode(); |
| 151 CookieTreeAppCachesNode* GetOrCreateAppCachesNode(); |
134 | 152 |
135 private: | 153 private: |
136 | |
137 // A pointer to the COOKIES node. Eventually we will also have database, | 154 // A pointer to the COOKIES node. Eventually we will also have database, |
138 // appcache, local storage, ..., and when we build up the tree we need to | 155 // appcache, local storage, ..., and when we build up the tree we need to |
139 // quickly get a reference to the COOKIES node to add children. Checking each | 156 // quickly get a reference to the COOKIES node to add children. Checking each |
140 // child and interrogating them to see if they are a COOKIES, APPCACHES, | 157 // child and interrogating them to see if they are a COOKIES, APPCACHES, |
141 // DATABASES etc node seems less preferable than storing an extra pointer per | 158 // DATABASES etc node seems less preferable than storing an extra pointer per |
142 // origin. | 159 // origin. |
143 CookieTreeCookiesNode* cookies_child_; | 160 CookieTreeCookiesNode* cookies_child_; |
144 CookieTreeDatabasesNode* databases_child_; | 161 CookieTreeDatabasesNode* databases_child_; |
145 CookieTreeLocalStoragesNode* local_storages_child_; | 162 CookieTreeLocalStoragesNode* local_storages_child_; |
| 163 CookieTreeAppCachesNode* appcaches_child_; |
146 | 164 |
147 DISALLOW_COPY_AND_ASSIGN(CookieTreeOriginNode); | 165 DISALLOW_COPY_AND_ASSIGN(CookieTreeOriginNode); |
148 }; | 166 }; |
149 | 167 |
150 // CookieTreeCookiesNode ------------------------------------------------------ | 168 // CookieTreeCookieNode ------------------------------------------------------ |
151 class CookieTreeCookiesNode : public CookieTreeNode { | |
152 public: | |
153 CookieTreeCookiesNode(); | |
154 virtual ~CookieTreeCookiesNode() {} | |
155 | |
156 // CookieTreeNode methods: | |
157 virtual DetailedInfo GetDetailedInfo() const { | |
158 return DetailedInfo(GetParent()->GetTitle(), DetailedInfo::TYPE_COOKIES, | |
159 NULL, NULL, NULL); | |
160 } | |
161 | |
162 // CookieTreeCookiesNode methods: | |
163 void AddCookieNode(CookieTreeCookieNode* child); | |
164 | |
165 private: | |
166 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookiesNode); | |
167 }; | |
168 | |
169 class CookieTreeCookieNode : public CookieTreeNode { | 169 class CookieTreeCookieNode : public CookieTreeNode { |
170 public: | 170 public: |
171 friend class CookieTreeCookiesNode; | 171 friend class CookieTreeCookiesNode; |
172 | 172 |
173 // Does not take ownership of cookie, and cookie should remain valid at least | 173 // Does not take ownership of cookie, and cookie should remain valid at least |
174 // as long as the CookieTreeCookieNode is valid. | 174 // as long as the CookieTreeCookieNode is valid. |
175 explicit CookieTreeCookieNode(net::CookieMonster::CookieListPair* cookie); | 175 explicit CookieTreeCookieNode(net::CookieMonster::CookieListPair* cookie); |
176 virtual ~CookieTreeCookieNode() {} | 176 virtual ~CookieTreeCookieNode() {} |
177 | 177 |
178 // CookieTreeNode methods: | 178 // CookieTreeNode methods: |
179 virtual void DeleteStoredObjects(); | 179 virtual void DeleteStoredObjects(); |
180 virtual DetailedInfo GetDetailedInfo() const { | 180 virtual DetailedInfo GetDetailedInfo() const { |
181 return DetailedInfo(GetParent()->GetParent()->GetTitle(), | 181 return DetailedInfo(GetParent()->GetParent()->GetTitle(), |
182 DetailedInfo::TYPE_COOKIE, cookie_, NULL, NULL); | 182 DetailedInfo::TYPE_COOKIE, cookie_, NULL, NULL, NULL); |
183 } | 183 } |
184 | 184 |
185 private: | 185 private: |
186 // Comparator functor, takes CookieTreeNode so that we can use it in | |
187 // lower_bound using children()'s iterators, which are CookieTreeNode*. | |
188 class CookieNodeComparator { | |
189 public: | |
190 bool operator() (const CookieTreeNode* lhs, const CookieTreeNode* rhs); | |
191 }; | |
192 | |
193 // Cookie_ is not owned by the node, and is expected to remain valid as long | 186 // Cookie_ is not owned by the node, and is expected to remain valid as long |
194 // as the CookieTreeCookieNode is valid. | 187 // as the CookieTreeCookieNode is valid. |
195 net::CookieMonster::CookieListPair* cookie_; | 188 net::CookieMonster::CookieListPair* cookie_; |
196 | 189 |
197 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookieNode); | 190 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookieNode); |
198 }; | 191 }; |
199 | 192 |
200 // CookieTreeDatabasesNode ----------------------------------------------------- | 193 class CookieTreeCookiesNode : public CookieTreeNode { |
201 class CookieTreeDatabasesNode : public CookieTreeNode { | |
202 public: | 194 public: |
203 CookieTreeDatabasesNode(); | 195 CookieTreeCookiesNode(); |
204 virtual ~CookieTreeDatabasesNode() {} | 196 virtual ~CookieTreeCookiesNode() {} |
205 | 197 |
206 // CookieTreeNode methods: | 198 virtual DetailedInfo GetDetailedInfo() const { |
| 199 return DetailedInfo(GetParent()->GetTitle(), DetailedInfo::TYPE_COOKIES, |
| 200 NULL, NULL, NULL, NULL); |
| 201 } |
| 202 |
| 203 void AddCookieNode(CookieTreeCookieNode* child) { |
| 204 AddChildSortedByTitle(child); |
| 205 } |
| 206 |
| 207 private: |
| 208 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookiesNode); |
| 209 }; |
| 210 |
| 211 // CookieTreeAppCacheNode ----------------------------------------------------- |
| 212 class CookieTreeAppCacheNode : public CookieTreeNode { |
| 213 public: |
| 214 friend class CookieTreeAppCachesNode; |
| 215 |
| 216 // Does not take ownership of appcache_info, and appcache_info should remain |
| 217 // valid at least as long as the CookieTreeAppCacheNode is valid. |
| 218 explicit CookieTreeAppCacheNode( |
| 219 const BrowsingDataAppCacheHelper::AppCacheInfo* appcache_info); |
| 220 virtual ~CookieTreeAppCacheNode() {} |
| 221 |
| 222 virtual void DeleteStoredObjects(); |
| 223 virtual DetailedInfo GetDetailedInfo() const { |
| 224 return DetailedInfo(GetParent()->GetParent()->GetTitle(), |
| 225 DetailedInfo::TYPE_APPCACHE, |
| 226 NULL, NULL, NULL, appcache_info_); |
| 227 } |
| 228 |
| 229 private: |
| 230 const BrowsingDataAppCacheHelper::AppCacheInfo* appcache_info_; |
| 231 DISALLOW_COPY_AND_ASSIGN(CookieTreeAppCacheNode); |
| 232 }; |
| 233 |
| 234 class CookieTreeAppCachesNode : public CookieTreeNode { |
| 235 public: |
| 236 CookieTreeAppCachesNode(); |
| 237 virtual ~CookieTreeAppCachesNode() {} |
| 238 |
207 virtual DetailedInfo GetDetailedInfo() const { | 239 virtual DetailedInfo GetDetailedInfo() const { |
208 return DetailedInfo(GetParent()->GetTitle(), | 240 return DetailedInfo(GetParent()->GetTitle(), |
209 DetailedInfo::TYPE_DATABASES, | 241 DetailedInfo::TYPE_APPCACHES, |
210 NULL, NULL, NULL); | 242 NULL, NULL, NULL, NULL); |
211 } | 243 } |
212 | 244 |
213 // CookieTreeDatabases methods: | 245 void AddAppCacheNode(CookieTreeAppCacheNode* child) { |
214 void AddDatabaseNode(CookieTreeDatabaseNode* child); | 246 AddChildSortedByTitle(child); |
| 247 } |
215 | 248 |
216 private: | 249 private: |
217 DISALLOW_COPY_AND_ASSIGN(CookieTreeDatabasesNode); | 250 DISALLOW_COPY_AND_ASSIGN(CookieTreeAppCachesNode); |
218 }; | 251 }; |
219 | 252 |
| 253 // CookieTreeDatabaseNode ----------------------------------------------------- |
220 class CookieTreeDatabaseNode : public CookieTreeNode { | 254 class CookieTreeDatabaseNode : public CookieTreeNode { |
221 public: | 255 public: |
222 friend class CookieTreeDatabasesNode; | 256 friend class CookieTreeDatabasesNode; |
223 | 257 |
224 // Does not take ownership of database_info, and database_info should remain | 258 // Does not take ownership of database_info, and database_info should remain |
225 // valid at least as long as the CookieTreeDatabaseNode is valid. | 259 // valid at least as long as the CookieTreeDatabaseNode is valid. |
226 explicit CookieTreeDatabaseNode( | 260 explicit CookieTreeDatabaseNode( |
227 BrowsingDataDatabaseHelper::DatabaseInfo* database_info); | 261 BrowsingDataDatabaseHelper::DatabaseInfo* database_info); |
228 virtual ~CookieTreeDatabaseNode() {} | 262 virtual ~CookieTreeDatabaseNode() {} |
229 | 263 |
230 // CookieTreeStorageNode methods: | |
231 virtual void DeleteStoredObjects(); | 264 virtual void DeleteStoredObjects(); |
232 virtual DetailedInfo GetDetailedInfo() const { | 265 virtual DetailedInfo GetDetailedInfo() const { |
233 return DetailedInfo(GetParent()->GetParent()->GetTitle(), | 266 return DetailedInfo(GetParent()->GetParent()->GetTitle(), |
234 DetailedInfo::TYPE_DATABASE, NULL, database_info_, | 267 DetailedInfo::TYPE_DATABASE, NULL, database_info_, |
235 NULL); | 268 NULL, NULL); |
236 } | 269 } |
237 | 270 |
238 private: | 271 private: |
239 // Comparator functor, takes CookieTreeNode so that we can use it in | |
240 // lower_bound using children()'s iterators, which are CookieTreeNode*. | |
241 class CookieNodeComparator { | |
242 public: | |
243 bool operator() (const CookieTreeNode* lhs, const CookieTreeNode* rhs); | |
244 }; | |
245 | |
246 // database_info_ is not owned by the node, and is expected to remain | 272 // database_info_ is not owned by the node, and is expected to remain |
247 // valid as long as the CookieTreeDatabaseNode is valid. | 273 // valid as long as the CookieTreeDatabaseNode is valid. |
248 BrowsingDataDatabaseHelper::DatabaseInfo* database_info_; | 274 BrowsingDataDatabaseHelper::DatabaseInfo* database_info_; |
249 | 275 |
250 DISALLOW_COPY_AND_ASSIGN(CookieTreeDatabaseNode); | 276 DISALLOW_COPY_AND_ASSIGN(CookieTreeDatabaseNode); |
251 }; | 277 }; |
252 | 278 |
253 // CookieTreeLocalStoragesNode ------------------------------------------------- | 279 class CookieTreeDatabasesNode : public CookieTreeNode { |
254 class CookieTreeLocalStoragesNode : public CookieTreeNode { | |
255 public: | 280 public: |
256 CookieTreeLocalStoragesNode(); | 281 CookieTreeDatabasesNode(); |
257 virtual ~CookieTreeLocalStoragesNode() {} | 282 virtual ~CookieTreeDatabasesNode() {} |
258 | 283 |
259 // CookieTreeNode methods: | |
260 virtual DetailedInfo GetDetailedInfo() const { | 284 virtual DetailedInfo GetDetailedInfo() const { |
261 return DetailedInfo(GetParent()->GetTitle(), | 285 return DetailedInfo(GetParent()->GetTitle(), |
262 DetailedInfo::TYPE_LOCAL_STORAGES, | 286 DetailedInfo::TYPE_DATABASES, |
263 NULL, NULL, NULL); | 287 NULL, NULL, NULL, NULL); |
264 } | 288 } |
265 | 289 |
266 // CookieTreeStoragesNode methods: | 290 void AddDatabaseNode(CookieTreeDatabaseNode* child) { |
267 void AddLocalStorageNode(CookieTreeLocalStorageNode* child); | 291 AddChildSortedByTitle(child); |
| 292 } |
268 | 293 |
269 private: | 294 private: |
270 DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStoragesNode); | 295 DISALLOW_COPY_AND_ASSIGN(CookieTreeDatabasesNode); |
271 }; | 296 }; |
272 | 297 |
| 298 |
| 299 // CookieTreeLocalStorageNode ------------------------------------------------- |
273 class CookieTreeLocalStorageNode : public CookieTreeNode { | 300 class CookieTreeLocalStorageNode : public CookieTreeNode { |
274 public: | 301 public: |
275 friend class CookieTreeLocalStoragesNode; | 302 friend class CookieTreeLocalStoragesNode; |
276 | 303 |
277 // Does not take ownership of local_storage_info, and local_storage_info | 304 // Does not take ownership of local_storage_info, and local_storage_info |
278 // should remain valid at least as long as the CookieTreeStorageNode is valid. | 305 // should remain valid at least as long as the CookieTreeStorageNode is valid. |
279 explicit CookieTreeLocalStorageNode( | 306 explicit CookieTreeLocalStorageNode( |
280 BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info); | 307 BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info); |
281 virtual ~CookieTreeLocalStorageNode() {} | 308 virtual ~CookieTreeLocalStorageNode() {} |
282 | 309 |
283 // CookieTreeStorageNode methods: | 310 // CookieTreeStorageNode methods: |
284 virtual void DeleteStoredObjects(); | 311 virtual void DeleteStoredObjects(); |
285 virtual DetailedInfo GetDetailedInfo() const { | 312 virtual DetailedInfo GetDetailedInfo() const { |
286 return DetailedInfo(GetParent()->GetParent()->GetTitle(), | 313 return DetailedInfo(GetParent()->GetParent()->GetTitle(), |
287 DetailedInfo::TYPE_LOCAL_STORAGE, NULL, NULL, | 314 DetailedInfo::TYPE_LOCAL_STORAGE, NULL, NULL, |
288 local_storage_info_); | 315 local_storage_info_, NULL); |
289 } | 316 } |
290 | 317 |
291 private: | 318 private: |
292 // Comparator functor, takes CookieTreeNode so that we can use it in | |
293 // lower_bound using children()'s iterators, which are CookieTreeNode*. | |
294 class CookieNodeComparator { | |
295 public: | |
296 bool operator() (const CookieTreeNode* lhs, const CookieTreeNode* rhs); | |
297 }; | |
298 | |
299 // local_storage_info_ is not owned by the node, and is expected to remain | 319 // local_storage_info_ is not owned by the node, and is expected to remain |
300 // valid as long as the CookieTreeLocalStorageNode is valid. | 320 // valid as long as the CookieTreeLocalStorageNode is valid. |
301 BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info_; | 321 BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info_; |
302 | 322 |
303 DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStorageNode); | 323 DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStorageNode); |
304 }; | 324 }; |
305 | 325 |
| 326 class CookieTreeLocalStoragesNode : public CookieTreeNode { |
| 327 public: |
| 328 CookieTreeLocalStoragesNode(); |
| 329 virtual ~CookieTreeLocalStoragesNode() {} |
| 330 |
| 331 virtual DetailedInfo GetDetailedInfo() const { |
| 332 return DetailedInfo(GetParent()->GetTitle(), |
| 333 DetailedInfo::TYPE_LOCAL_STORAGES, |
| 334 NULL, NULL, NULL, NULL); |
| 335 } |
| 336 |
| 337 void AddLocalStorageNode(CookieTreeLocalStorageNode* child) { |
| 338 AddChildSortedByTitle(child); |
| 339 } |
| 340 |
| 341 private: |
| 342 DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStoragesNode); |
| 343 }; |
| 344 |
306 class CookiesTreeModel : public TreeNodeModel<CookieTreeNode> { | 345 class CookiesTreeModel : public TreeNodeModel<CookieTreeNode> { |
307 public: | 346 public: |
308 CookiesTreeModel( | 347 CookiesTreeModel( |
309 Profile* profile, | 348 Profile* profile, |
310 BrowsingDataDatabaseHelper* browsing_data_database_helper, | 349 BrowsingDataDatabaseHelper* database_helper, |
311 BrowsingDataLocalStorageHelper* browsing_data_local_storage_helper); | 350 BrowsingDataLocalStorageHelper* local_storage_helper, |
| 351 BrowsingDataAppCacheHelper* appcache_helper); |
312 virtual ~CookiesTreeModel(); | 352 virtual ~CookiesTreeModel(); |
313 | 353 |
314 // TreeModel methods: | 354 // TreeModel methods: |
315 // Returns the set of icons for the nodes in the tree. You only need override | 355 // Returns the set of icons for the nodes in the tree. You only need override |
316 // this if you don't want to use the default folder icons. | 356 // this if you don't want to use the default folder icons. |
317 virtual void GetIcons(std::vector<SkBitmap>* icons); | 357 virtual void GetIcons(std::vector<SkBitmap>* icons); |
318 | 358 |
319 // Returns the index of the icon to use for |node|. Return -1 to use the | 359 // Returns the index of the icon to use for |node|. Return -1 to use the |
320 // default icon. The index is relative to the list of icons returned from | 360 // default icon. The index is relative to the list of icons returned from |
321 // GetIcons. | 361 // GetIcons. |
322 virtual int GetIconIndex(TreeModelNode* node); | 362 virtual int GetIconIndex(TreeModelNode* node); |
323 | 363 |
324 // CookiesTreeModel methods: | 364 // CookiesTreeModel methods: |
325 void DeleteAllStoredObjects(); | 365 void DeleteAllStoredObjects(); |
326 void DeleteCookieNode(CookieTreeNode* cookie_node); | 366 void DeleteCookieNode(CookieTreeNode* cookie_node); |
327 | 367 |
328 // Filter the origins to only display matched results. | 368 // Filter the origins to only display matched results. |
329 void UpdateSearchResults(const std::wstring& filter); | 369 void UpdateSearchResults(const std::wstring& filter); |
330 | 370 |
331 private: | 371 private: |
332 enum CookieIconIndex { | 372 enum CookieIconIndex { |
333 ORIGIN = 0, | 373 ORIGIN = 0, |
334 COOKIE = 1, | 374 COOKIE = 1, |
335 DATABASE = 2, | 375 DATABASE = 2 |
336 LOCAL_STORAGE = 3, | |
337 }; | 376 }; |
338 typedef net::CookieMonster::CookieList CookieList; | 377 typedef net::CookieMonster::CookieList CookieList; |
339 typedef std::vector<net::CookieMonster::CookieListPair*> CookiePtrList; | 378 typedef std::vector<net::CookieMonster::CookieListPair*> CookiePtrList; |
| 379 typedef std::vector<BrowsingDataAppCacheHelper::AppCacheInfo> |
| 380 AppCacheInfoList; |
340 typedef std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> | 381 typedef std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> |
341 DatabaseInfoList; | 382 DatabaseInfoList; |
342 typedef std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> | 383 typedef std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> |
343 LocalStorageInfoList; | 384 LocalStorageInfoList; |
344 | 385 |
345 void LoadCookies(); | 386 void LoadCookies(); |
346 void LoadCookiesWithFilter(const std::wstring& filter); | 387 void LoadCookiesWithFilter(const std::wstring& filter); |
347 | 388 |
| 389 void OnAppCacheModelInfoLoaded(); |
348 void OnDatabaseModelInfoLoaded(const DatabaseInfoList& database_info); | 390 void OnDatabaseModelInfoLoaded(const DatabaseInfoList& database_info); |
349 | |
350 void OnStorageModelInfoLoaded(const LocalStorageInfoList& local_storage_info); | 391 void OnStorageModelInfoLoaded(const LocalStorageInfoList& local_storage_info); |
351 | 392 |
| 393 void PopulateAppCacheInfoWithFilter(const std::wstring& filter); |
352 void PopulateDatabaseInfoWithFilter(const std::wstring& filter); | 394 void PopulateDatabaseInfoWithFilter(const std::wstring& filter); |
353 | |
354 void PopulateLocalStorageInfoWithFilter(const std::wstring& filter); | 395 void PopulateLocalStorageInfoWithFilter(const std::wstring& filter); |
355 | 396 |
356 // The profile from which this model sources cookies. | 397 // The profile from which this model sources cookies. |
357 Profile* profile_; | 398 Profile* profile_; |
358 CookieList all_cookies_; | 399 CookieList all_cookies_; |
359 | 400 |
| 401 scoped_refptr<BrowsingDataAppCacheHelper> appcache_helper_; |
360 scoped_refptr<BrowsingDataDatabaseHelper> database_helper_; | 402 scoped_refptr<BrowsingDataDatabaseHelper> database_helper_; |
361 DatabaseInfoList database_info_list_; | 403 DatabaseInfoList database_info_list_; |
362 | 404 |
363 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper_; | 405 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper_; |
364 LocalStorageInfoList local_storage_info_list_; | 406 LocalStorageInfoList local_storage_info_list_; |
365 | 407 |
| 408 friend class CookieTreeAppCacheNode; |
366 friend class CookieTreeCookieNode; | 409 friend class CookieTreeCookieNode; |
367 friend class CookieTreeDatabaseNode; | 410 friend class CookieTreeDatabaseNode; |
368 friend class CookieTreeLocalStorageNode; | 411 friend class CookieTreeLocalStorageNode; |
369 | 412 |
370 DISALLOW_COPY_AND_ASSIGN(CookiesTreeModel); | 413 DISALLOW_COPY_AND_ASSIGN(CookiesTreeModel); |
371 }; | 414 }; |
372 | 415 |
373 #endif // CHROME_BROWSER_COOKIES_TREE_MODEL_H_ | 416 #endif // CHROME_BROWSER_COOKIES_TREE_MODEL_H_ |
OLD | NEW |