Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: chrome/browser/cookies_tree_model.cc

Issue 650110: Teach the cookie tree view / model about appcaches. Not hooked up to real dat... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/cookies_tree_model.h ('k') | chrome/browser/cookies_tree_model_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/cookies_tree_model.h" 5 #include "chrome/browser/cookies_tree_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 namespace { 69 namespace {
70 // comparison functor, for use in CookieTreeRootNode 70 // comparison functor, for use in CookieTreeRootNode
71 class OriginNodeComparator { 71 class OriginNodeComparator {
72 public: 72 public:
73 bool operator() (const CookieTreeNode* lhs, 73 bool operator() (const CookieTreeNode* lhs,
74 const CookieTreeNode* rhs) { 74 const CookieTreeNode* rhs) {
75 // We want to order by registry controlled domain, so we would get 75 // We want to order by registry controlled domain, so we would get
76 // google.com, ad.google.com, www.google.com, 76 // google.com, ad.google.com, www.google.com,
77 // microsoft.com, ad.microsoft.com. CanonicalizeHost transforms the origins 77 // microsoft.com, ad.microsoft.com. CanonicalizeHost transforms the origins
78 // into a form like google.com.www so that string comparisons work. 78 // into a form like google.com.www so that string comparisons work.
79 return (CanonicalizeHost(lhs->GetTitle()) < 79 return (CanonicalizeHost(lhs->GetTitleAsString16()) <
80 CanonicalizeHost(rhs->GetTitle())); 80 CanonicalizeHost(rhs->GetTitleAsString16()));
81 } 81 }
82 82
83 private: 83 private:
84 static std::string CanonicalizeHost(const std::wstring& host_w) { 84 static std::string CanonicalizeHost(const string16& host16) {
85 // The canonicalized representation makes the registry controlled domain 85 // The canonicalized representation makes the registry controlled domain
86 // come first, and then adds subdomains in reverse order, e.g. 86 // come first, and then adds subdomains in reverse order, e.g.
87 // 1.mail.google.com would become google.com.mail.1, and then a standard 87 // 1.mail.google.com would become google.com.mail.1, and then a standard
88 // string comparison works to order hosts by registry controlled domain 88 // string comparison works to order hosts by registry controlled domain
89 // first. Leading dots are ignored, ".google.com" is the same as 89 // first. Leading dots are ignored, ".google.com" is the same as
90 // "google.com". 90 // "google.com".
91 91
92 std::string host = WideToUTF8(host_w); 92 std::string host = UTF16ToUTF8(host16);
93 std::string retval = net::RegistryControlledDomainService:: 93 std::string retval = net::RegistryControlledDomainService::
94 GetDomainAndRegistry(host); 94 GetDomainAndRegistry(host);
95 if (!retval.length()) // Is an IP address or other special origin. 95 if (!retval.length()) // Is an IP address or other special origin.
96 return host; 96 return host;
97 97
98 std::string::size_type position = host.rfind(retval); 98 std::string::size_type position = host.rfind(retval);
99 99
100 // The host may be the registry controlled domain, in which case fail fast. 100 // The host may be the registry controlled domain, in which case fail fast.
101 if (position == 0 || position == std::string::npos) 101 if (position == 0 || position == std::string::npos)
102 return host; 102 return host;
(...skipping 16 matching lines...) Expand all
119 retval += host.substr(next_dot + 1, position - (next_dot + 1)); 119 retval += host.substr(next_dot + 1, position - (next_dot + 1));
120 position = next_dot; 120 position = next_dot;
121 } 121 }
122 return retval; 122 return retval;
123 } 123 }
124 }; 124 };
125 125
126 } // namespace 126 } // namespace
127 127
128 /////////////////////////////////////////////////////////////////////////////// 128 ///////////////////////////////////////////////////////////////////////////////
129 // CookieTreeAppCacheNode, public:
130
131 CookieTreeAppCacheNode::CookieTreeAppCacheNode(
132 const BrowsingDataAppCacheHelper::AppCacheInfo* appcache_info)
133 : CookieTreeNode(UTF8ToWide(appcache_info->manifest_url.spec())),
134 appcache_info_(appcache_info) {
135 }
136
137 void CookieTreeAppCacheNode::DeleteStoredObjects() {
138 DCHECK(GetModel()->appcache_helper_);
139 GetModel()->appcache_helper_->DeleteAppCache(appcache_info_->group_id);
140 }
141
142 ///////////////////////////////////////////////////////////////////////////////
129 // CookieTreeDatabaseNode, public: 143 // CookieTreeDatabaseNode, public:
130 144
131 CookieTreeDatabaseNode::CookieTreeDatabaseNode( 145 CookieTreeDatabaseNode::CookieTreeDatabaseNode(
132 BrowsingDataDatabaseHelper::DatabaseInfo* database_info) 146 BrowsingDataDatabaseHelper::DatabaseInfo* database_info)
133 : CookieTreeNode(UTF8ToWide(database_info->database_name.empty() ? 147 : CookieTreeNode(database_info->database_name.empty() ?
134 database_info->origin_identifier : 148 l10n_util::GetString(IDS_COOKIES_WEB_DATABASE_UNNAMED_NAME) :
135 database_info->database_name)), 149 UTF8ToWide(database_info->database_name)),
136 database_info_(database_info) { 150 database_info_(database_info) {
137 } 151 }
138 152
139 void CookieTreeDatabaseNode::DeleteStoredObjects() { 153 void CookieTreeDatabaseNode::DeleteStoredObjects() {
140 GetModel()->database_helper_->DeleteDatabase( 154 GetModel()->database_helper_->DeleteDatabase(
141 database_info_->origin_identifier, database_info_->database_name); 155 database_info_->origin_identifier, database_info_->database_name);
142 } 156 }
143 157
144 /////////////////////////////////////////////////////////////////////////////// 158 ///////////////////////////////////////////////////////////////////////////////
145 // CookieTreeLocalStorageNode, public: 159 // CookieTreeLocalStorageNode, public:
146 160
147 CookieTreeLocalStorageNode::CookieTreeLocalStorageNode( 161 CookieTreeLocalStorageNode::CookieTreeLocalStorageNode(
148 BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info) 162 BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info)
149 : CookieTreeNode(UTF8ToWide( 163 : CookieTreeNode(UTF8ToWide(
150 local_storage_info->origin.empty() ? 164 local_storage_info->origin.empty() ?
151 local_storage_info->database_identifier : 165 local_storage_info->database_identifier :
152 local_storage_info->origin)), 166 local_storage_info->origin)),
153 local_storage_info_(local_storage_info) { 167 local_storage_info_(local_storage_info) {
154 } 168 }
155 169
156 void CookieTreeLocalStorageNode::DeleteStoredObjects() { 170 void CookieTreeLocalStorageNode::DeleteStoredObjects() {
157 GetModel()->local_storage_helper_->DeleteLocalStorageFile( 171 GetModel()->local_storage_helper_->DeleteLocalStorageFile(
158 local_storage_info_->file_path); 172 local_storage_info_->file_path);
159 } 173 }
160 174
161 /////////////////////////////////////////////////////////////////////////////// 175 ///////////////////////////////////////////////////////////////////////////////
162 // CookieTreeRootNode, public: 176 // CookieTreeRootNode, public:
163 CookieTreeOriginNode* CookieTreeRootNode::GetOrCreateOriginNode( 177 CookieTreeOriginNode* CookieTreeRootNode::GetOrCreateOriginNode(
164 const std::wstring& origin) { 178 const std::wstring& origin) {
165 // Strip the trailing dot if it exists. 179 // Strip the leading dot if it exists.
166 std::wstring rewritten_origin = origin; 180 std::wstring rewritten_origin = origin;
167 if (origin.length() >= 1 && origin[0] == '.') 181 if (origin.length() >= 1 && origin[0] == '.')
168 rewritten_origin = origin.substr(1); 182 rewritten_origin = origin.substr(1);
169 183
170 CookieTreeOriginNode rewritten_origin_node(rewritten_origin); 184 CookieTreeOriginNode rewritten_origin_node(rewritten_origin);
171 185
172 // First see if there is an existing match. 186 // First see if there is an existing match.
173 std::vector<CookieTreeNode*>::iterator origin_node_iterator = 187 std::vector<CookieTreeNode*>::iterator origin_node_iterator =
174 lower_bound(children().begin(), 188 lower_bound(children().begin(),
175 children().end(), 189 children().end(),
(...skipping 10 matching lines...) Expand all
186 model_->Add(this, (origin_node_iterator - children().begin()), retval); 200 model_->Add(this, (origin_node_iterator - children().begin()), retval);
187 return retval; 201 return retval;
188 } 202 }
189 203
190 /////////////////////////////////////////////////////////////////////////////// 204 ///////////////////////////////////////////////////////////////////////////////
191 // CookieTreeOriginNode, public: 205 // CookieTreeOriginNode, public:
192 206
193 CookieTreeCookiesNode* CookieTreeOriginNode::GetOrCreateCookiesNode() { 207 CookieTreeCookiesNode* CookieTreeOriginNode::GetOrCreateCookiesNode() {
194 if (cookies_child_) 208 if (cookies_child_)
195 return cookies_child_; 209 return cookies_child_;
196 // need to make a Cookies node, add it to the tree, and return it 210 cookies_child_ = new CookieTreeCookiesNode;
197 CookieTreeCookiesNode* retval = new CookieTreeCookiesNode; 211 AddChildSortedByTitle(cookies_child_);
198 GetModel()->Add(this, 0, retval); 212 return cookies_child_;
199 cookies_child_ = retval;
200 return retval;
201 } 213 }
202 214
203 CookieTreeDatabasesNode* 215 CookieTreeDatabasesNode* CookieTreeOriginNode::GetOrCreateDatabasesNode() {
204 CookieTreeOriginNode::GetOrCreateDatabasesNode() {
205 if (databases_child_) 216 if (databases_child_)
206 return databases_child_; 217 return databases_child_;
207 // Need to make a Database node, add it to the tree, and return it. 218 databases_child_ = new CookieTreeDatabasesNode;
208 CookieTreeDatabasesNode* retval = new CookieTreeDatabasesNode; 219 AddChildSortedByTitle(databases_child_);
209 GetModel()->Add(this, cookies_child_ ? 1 : 0, retval); 220 return databases_child_;
210 databases_child_ = retval;
211 return retval;
212 } 221 }
213 222
214 CookieTreeLocalStoragesNode* 223 CookieTreeLocalStoragesNode*
215 CookieTreeOriginNode::GetOrCreateLocalStoragesNode() { 224 CookieTreeOriginNode::GetOrCreateLocalStoragesNode() {
216 if (local_storages_child_) 225 if (local_storages_child_)
217 return local_storages_child_; 226 return local_storages_child_;
218 // Need to make a LocalStorages node, add it to the tree, and return it. 227 local_storages_child_ = new CookieTreeLocalStoragesNode;
219 CookieTreeLocalStoragesNode* retval = new CookieTreeLocalStoragesNode; 228 AddChildSortedByTitle(local_storages_child_);
220 int index = 0; 229 return local_storages_child_;
221 if (cookies_child_) 230 }
222 ++index; 231
223 if (databases_child_) 232 CookieTreeAppCachesNode* CookieTreeOriginNode::GetOrCreateAppCachesNode() {
224 ++index; 233 if (appcaches_child_)
225 GetModel()->Add(this, index, retval); 234 return appcaches_child_;
226 local_storages_child_ = retval; 235 appcaches_child_ = new CookieTreeAppCachesNode;
227 return retval; 236 AddChildSortedByTitle(appcaches_child_);
237 return appcaches_child_;
228 } 238 }
229 239
230 /////////////////////////////////////////////////////////////////////////////// 240 ///////////////////////////////////////////////////////////////////////////////
231 // CookieTreeCookiesNode, public: 241 // CookieTreeCookiesNode, public:
232 242
233 CookieTreeCookiesNode::CookieTreeCookiesNode() 243 CookieTreeCookiesNode::CookieTreeCookiesNode()
234 : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_COOKIES)) {} 244 : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_COOKIES)) {
235
236
237 void CookieTreeCookiesNode::AddCookieNode(
238 CookieTreeCookieNode* new_child) {
239 std::vector<CookieTreeNode*>::iterator cookie_iterator =
240 lower_bound(children().begin(),
241 children().end(),
242 new_child,
243 CookieTreeCookieNode::CookieNodeComparator());
244 GetModel()->Add(this, (cookie_iterator - children().begin()), new_child);
245 } 245 }
246 246
247 /////////////////////////////////////////////////////////////////////////////// 247 ///////////////////////////////////////////////////////////////////////////////
248 // CookieTreeAppCachesNode, public:
249
250 CookieTreeAppCachesNode::CookieTreeAppCachesNode()
251 : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_APPLICATION_CACHES)) {
252 }
253
254 ///////////////////////////////////////////////////////////////////////////////
248 // CookieTreeDatabasesNode, public: 255 // CookieTreeDatabasesNode, public:
249 256
250 CookieTreeDatabasesNode::CookieTreeDatabasesNode() 257 CookieTreeDatabasesNode::CookieTreeDatabasesNode()
251 : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_WEB_DATABASES)) { 258 : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_WEB_DATABASES)) {
252 } 259 }
253 260
254 void CookieTreeDatabasesNode::AddDatabaseNode(
255 CookieTreeDatabaseNode* new_child) {
256 std::vector<CookieTreeNode*>::iterator database_iterator =
257 lower_bound(children().begin(),
258 children().end(),
259 new_child,
260 CookieTreeDatabaseNode::CookieNodeComparator());
261 GetModel()->Add(this,
262 (database_iterator - children().begin()),
263 new_child);
264 }
265
266 /////////////////////////////////////////////////////////////////////////////// 261 ///////////////////////////////////////////////////////////////////////////////
267 // CookieTreeLocalStoragesNode, public: 262 // CookieTreeLocalStoragesNode, public:
268 263
269 CookieTreeLocalStoragesNode::CookieTreeLocalStoragesNode() 264 CookieTreeLocalStoragesNode::CookieTreeLocalStoragesNode()
270 : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE)) { 265 : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE)) {
271 } 266 }
272 267
273 void CookieTreeLocalStoragesNode::AddLocalStorageNode( 268 ///////////////////////////////////////////////////////////////////////////////
274 CookieTreeLocalStorageNode* new_child) { 269 // CookieTreeNode, protected
275 std::vector<CookieTreeNode*>::iterator local_storage_iterator = 270
271 bool CookieTreeNode::NodeTitleComparator::operator() (
272 const CookieTreeNode* lhs, const CookieTreeNode* rhs) {
273 const CookieTreeNode* left =
274 static_cast<const CookieTreeNode*>(lhs);
275 const CookieTreeNode* right =
276 static_cast<const CookieTreeNode*>(rhs);
277 return (left->GetTitleAsString16() < right->GetTitleAsString16());
278 }
279
280 void CookieTreeNode::AddChildSortedByTitle(CookieTreeNode* new_child) {
281 std::vector<CookieTreeNode*>::iterator iter =
276 lower_bound(children().begin(), 282 lower_bound(children().begin(),
277 children().end(), 283 children().end(),
278 new_child, 284 new_child,
279 CookieTreeLocalStorageNode::CookieNodeComparator()); 285 NodeTitleComparator());
280 GetModel()->Add(this, 286 GetModel()->Add(this, iter - children().begin(), new_child);
281 (local_storage_iterator - children().begin()),
282 new_child);
283 }
284
285 ///////////////////////////////////////////////////////////////////////////////
286 // CookieTreeCookieNode, private
287
288 bool CookieTreeCookieNode::CookieNodeComparator::operator() (
289 const CookieTreeNode* lhs, const CookieTreeNode* rhs) {
290 const CookieTreeCookieNode* left =
291 static_cast<const CookieTreeCookieNode*>(lhs);
292 const CookieTreeCookieNode* right =
293 static_cast<const CookieTreeCookieNode*>(rhs);
294 return (left->cookie_->second.Name() < right->cookie_->second.Name());
295 }
296
297 ///////////////////////////////////////////////////////////////////////////////
298 // CookieTreeDatabaseNode, private
299
300 bool CookieTreeDatabaseNode::CookieNodeComparator::operator() (
301 const CookieTreeNode* lhs, const CookieTreeNode* rhs) {
302 const CookieTreeDatabaseNode* left =
303 static_cast<const CookieTreeDatabaseNode*>(lhs);
304 const CookieTreeDatabaseNode* right =
305 static_cast<const CookieTreeDatabaseNode*>(rhs);
306 return (left->database_info_->database_name <
307 right->database_info_->database_name);
308 }
309
310 ///////////////////////////////////////////////////////////////////////////////
311 // CookieTreeLocalStorageNode, private
312
313 bool CookieTreeLocalStorageNode::CookieNodeComparator::operator() (
314 const CookieTreeNode* lhs, const CookieTreeNode* rhs) {
315 const CookieTreeLocalStorageNode* left =
316 static_cast<const CookieTreeLocalStorageNode*>(lhs);
317 const CookieTreeLocalStorageNode* right =
318 static_cast<const CookieTreeLocalStorageNode*>(rhs);
319 return (left->local_storage_info_->origin <
320 right->local_storage_info_->origin);
321 } 287 }
322 288
323 /////////////////////////////////////////////////////////////////////////////// 289 ///////////////////////////////////////////////////////////////////////////////
324 // CookiesTreeModel, public: 290 // CookiesTreeModel, public:
325 291
326 CookiesTreeModel::CookiesTreeModel( 292 CookiesTreeModel::CookiesTreeModel(
327 Profile* profile, 293 Profile* profile,
328 BrowsingDataDatabaseHelper* database_helper, 294 BrowsingDataDatabaseHelper* database_helper,
329 BrowsingDataLocalStorageHelper* local_storage_helper) 295 BrowsingDataLocalStorageHelper* local_storage_helper,
296 BrowsingDataAppCacheHelper* appcache_helper)
330 : ALLOW_THIS_IN_INITIALIZER_LIST(TreeNodeModel<CookieTreeNode>( 297 : ALLOW_THIS_IN_INITIALIZER_LIST(TreeNodeModel<CookieTreeNode>(
331 new CookieTreeRootNode(this))), 298 new CookieTreeRootNode(this))),
332 profile_(profile), 299 profile_(profile),
300 appcache_helper_(appcache_helper),
333 database_helper_(database_helper), 301 database_helper_(database_helper),
334 local_storage_helper_(local_storage_helper) { 302 local_storage_helper_(local_storage_helper) {
335 LoadCookies(); 303 LoadCookies();
336 DCHECK(database_helper_); 304 DCHECK(database_helper_);
337 database_helper_->StartFetching(NewCallback( 305 database_helper_->StartFetching(NewCallback(
338 this, &CookiesTreeModel::OnDatabaseModelInfoLoaded)); 306 this, &CookiesTreeModel::OnDatabaseModelInfoLoaded));
339 DCHECK(local_storage_helper_); 307 DCHECK(local_storage_helper_);
340 local_storage_helper_->StartFetching(NewCallback( 308 local_storage_helper_->StartFetching(NewCallback(
341 this, &CookiesTreeModel::OnStorageModelInfoLoaded)); 309 this, &CookiesTreeModel::OnStorageModelInfoLoaded));
310
311 // TODO(michaeln): when all of the ui impls have been updated,
312 // make this a required parameter.
313 if (appcache_helper_) {
314 appcache_helper_->StartFetching(NewCallback(
315 this, &CookiesTreeModel::OnAppCacheModelInfoLoaded));
316 }
342 } 317 }
343 318
344 CookiesTreeModel::~CookiesTreeModel() { 319 CookiesTreeModel::~CookiesTreeModel() {
345 database_helper_->CancelNotification(); 320 database_helper_->CancelNotification();
346 local_storage_helper_->CancelNotification(); 321 local_storage_helper_->CancelNotification();
322 if (appcache_helper_)
323 appcache_helper_->CancelNotification();
347 } 324 }
348 325
349 /////////////////////////////////////////////////////////////////////////////// 326 ///////////////////////////////////////////////////////////////////////////////
350 // CookiesTreeModel, TreeModel methods (public): 327 // CookiesTreeModel, TreeModel methods (public):
351 328
352 // TreeModel methods: 329 // TreeModel methods:
353 // Returns the set of icons for the nodes in the tree. You only need override 330 // Returns the set of icons for the nodes in the tree. You only need override
354 // this if you don't want to use the default folder icons. 331 // this if you don't want to use the default folder icons.
355 void CookiesTreeModel::GetIcons(std::vector<SkBitmap>* icons) { 332 void CookiesTreeModel::GetIcons(std::vector<SkBitmap>* icons) {
356 icons->push_back(*ResourceBundle::GetSharedInstance().GetBitmapNamed( 333 icons->push_back(*ResourceBundle::GetSharedInstance().GetBitmapNamed(
(...skipping 13 matching lines...) Expand all
370 case CookieTreeNode::DetailedInfo::TYPE_ORIGIN: 347 case CookieTreeNode::DetailedInfo::TYPE_ORIGIN:
371 return ORIGIN; 348 return ORIGIN;
372 break; 349 break;
373 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: 350 case CookieTreeNode::DetailedInfo::TYPE_COOKIE:
374 return COOKIE; 351 return COOKIE;
375 break; 352 break;
376 case CookieTreeNode::DetailedInfo::TYPE_DATABASE: 353 case CookieTreeNode::DetailedInfo::TYPE_DATABASE:
377 return DATABASE; 354 return DATABASE;
378 break; 355 break;
379 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE: 356 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE:
380 // The differences between local storage and HTML5 databases are semantic 357 return DATABASE; // close enough
381 // enough that the user will not likely care if they share an icon. 358 break;
382 return DATABASE; 359 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE:
360 return DATABASE; // ditto
383 break; 361 break;
384 default: 362 default:
385 return -1; 363 return -1;
386 } 364 }
387 } 365 }
388 366
389 void CookiesTreeModel::LoadCookies() { 367 void CookiesTreeModel::LoadCookies() {
390 LoadCookiesWithFilter(std::wstring()); 368 LoadCookiesWithFilter(std::wstring());
391 } 369 }
392 370
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 410 }
433 411
434 void CookiesTreeModel::UpdateSearchResults(const std::wstring& filter) { 412 void CookiesTreeModel::UpdateSearchResults(const std::wstring& filter) {
435 CookieTreeNode* root = GetRoot(); 413 CookieTreeNode* root = GetRoot();
436 int num_children = root->GetChildCount(); 414 int num_children = root->GetChildCount();
437 for (int i = num_children - 1; i >= 0; --i) 415 for (int i = num_children - 1; i >= 0; --i)
438 delete Remove(root, i); 416 delete Remove(root, i);
439 LoadCookiesWithFilter(filter); 417 LoadCookiesWithFilter(filter);
440 PopulateDatabaseInfoWithFilter(filter); 418 PopulateDatabaseInfoWithFilter(filter);
441 PopulateLocalStorageInfoWithFilter(filter); 419 PopulateLocalStorageInfoWithFilter(filter);
420 PopulateAppCacheInfoWithFilter(filter);
421 NotifyObserverTreeNodeChanged(root);
422 }
423
424 void CookiesTreeModel::OnAppCacheModelInfoLoaded() {
425 PopulateAppCacheInfoWithFilter(std::wstring());
426 }
427
428 void CookiesTreeModel::PopulateAppCacheInfoWithFilter(
429 const std::wstring& filter) {
430 if (!appcache_helper_ || appcache_helper_->info_list().empty())
431 return;
432 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot());
433 for (AppCacheInfoList::const_iterator info =
434 appcache_helper_->info_list().begin();
435 info != appcache_helper_->info_list().end(); ++info) {
436 std::wstring host = UTF8ToWide(info->manifest_url.host());
437 if (filter.empty() || (host.find(filter) != std::wstring::npos)) {
438 CookieTreeOriginNode* host_node =
439 root->GetOrCreateOriginNode(host);
440 CookieTreeAppCachesNode* appcaches_node =
441 host_node->GetOrCreateAppCachesNode();
442 appcaches_node->AddAppCacheNode(
443 new CookieTreeAppCacheNode(&(*info)));
444 }
445 }
442 NotifyObserverTreeNodeChanged(root); 446 NotifyObserverTreeNodeChanged(root);
443 } 447 }
444 448
445 void CookiesTreeModel::OnDatabaseModelInfoLoaded( 449 void CookiesTreeModel::OnDatabaseModelInfoLoaded(
446 const DatabaseInfoList& database_info) { 450 const DatabaseInfoList& database_info) {
447 database_info_list_ = database_info; 451 database_info_list_ = database_info;
448 PopulateDatabaseInfoWithFilter(std::wstring()); 452 PopulateDatabaseInfoWithFilter(std::wstring());
449 } 453 }
450 454
451 void CookiesTreeModel::PopulateDatabaseInfoWithFilter( 455 void CookiesTreeModel::PopulateDatabaseInfoWithFilter(
452 const std::wstring& filter) { 456 const std::wstring& filter) {
457 if (database_info_list_.empty())
458 return;
453 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); 459 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot());
454 for (DatabaseInfoList::iterator database_info = database_info_list_.begin(); 460 for (DatabaseInfoList::iterator database_info = database_info_list_.begin();
455 database_info != database_info_list_.end(); 461 database_info != database_info_list_.end();
456 ++database_info) { 462 ++database_info) {
457 std::string origin = database_info->host.empty() ? 463 std::string origin = database_info->host.empty() ?
458 database_info->origin_identifier : database_info->host; 464 database_info->origin_identifier : database_info->host;
459 if (!filter.size() || 465 if (!filter.size() ||
460 (UTF8ToWide(origin).find(filter) != std::wstring::npos)) { 466 (UTF8ToWide(origin).find(filter) != std::wstring::npos)) {
461 CookieTreeOriginNode* origin_node = root->GetOrCreateOriginNode( 467 CookieTreeOriginNode* origin_node = root->GetOrCreateOriginNode(
462 UTF8ToWide(database_info->host)); 468 UTF8ToWide(database_info->host));
463 CookieTreeDatabasesNode* databases_node = 469 CookieTreeDatabasesNode* databases_node =
464 origin_node->GetOrCreateDatabasesNode(); 470 origin_node->GetOrCreateDatabasesNode();
465 databases_node->AddDatabaseNode( 471 databases_node->AddDatabaseNode(
466 new CookieTreeDatabaseNode(&(*database_info))); 472 new CookieTreeDatabaseNode(&(*database_info)));
467 } 473 }
468 } 474 }
469 NotifyObserverTreeNodeChanged(root); 475 NotifyObserverTreeNodeChanged(root);
470 } 476 }
471 477
472 void CookiesTreeModel::OnStorageModelInfoLoaded( 478 void CookiesTreeModel::OnStorageModelInfoLoaded(
473 const LocalStorageInfoList& local_storage_info) { 479 const LocalStorageInfoList& local_storage_info) {
474 local_storage_info_list_ = local_storage_info; 480 local_storage_info_list_ = local_storage_info;
475 PopulateLocalStorageInfoWithFilter(std::wstring()); 481 PopulateLocalStorageInfoWithFilter(std::wstring());
476 } 482 }
477 483
478 void CookiesTreeModel::PopulateLocalStorageInfoWithFilter( 484 void CookiesTreeModel::PopulateLocalStorageInfoWithFilter(
479 const std::wstring& filter) { 485 const std::wstring& filter) {
486 if (local_storage_info_list_.empty())
487 return;
480 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); 488 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot());
481 for (LocalStorageInfoList::iterator local_storage_info = 489 for (LocalStorageInfoList::iterator local_storage_info =
482 local_storage_info_list_.begin(); 490 local_storage_info_list_.begin();
483 local_storage_info != local_storage_info_list_.end(); 491 local_storage_info != local_storage_info_list_.end();
484 ++local_storage_info) { 492 ++local_storage_info) {
485 std::string origin = local_storage_info->host.empty() ? 493 std::string origin = local_storage_info->host.empty() ?
486 local_storage_info->database_identifier : local_storage_info->host; 494 local_storage_info->database_identifier : local_storage_info->host;
487 if (!filter.size() || 495 if (!filter.size() ||
488 (UTF8ToWide(origin).find(filter) != std::wstring::npos)) { 496 (UTF8ToWide(origin).find(filter) != std::wstring::npos)) {
489 CookieTreeOriginNode* origin_node = root->GetOrCreateOriginNode( 497 CookieTreeOriginNode* origin_node = root->GetOrCreateOriginNode(
490 UTF8ToWide(local_storage_info->host)); 498 UTF8ToWide(local_storage_info->host));
491 CookieTreeLocalStoragesNode* local_storages_node = 499 CookieTreeLocalStoragesNode* local_storages_node =
492 origin_node->GetOrCreateLocalStoragesNode(); 500 origin_node->GetOrCreateLocalStoragesNode();
493 local_storages_node->AddLocalStorageNode( 501 local_storages_node->AddLocalStorageNode(
494 new CookieTreeLocalStorageNode(&(*local_storage_info))); 502 new CookieTreeLocalStorageNode(&(*local_storage_info)));
495 } 503 }
496 } 504 }
497 NotifyObserverTreeNodeChanged(root); 505 NotifyObserverTreeNodeChanged(root);
498 } 506 }
OLDNEW
« no previous file with comments | « chrome/browser/cookies_tree_model.h ('k') | chrome/browser/cookies_tree_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698