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

Side by Side Diff: chrome/browser/ui/webui/cookies_tree_model_util.cc

Issue 2476753002: [MD settings] get cookie details from site without transfering cookie tree (Closed)
Patch Set: closure fix Created 4 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/cookies_tree_model_util.h" 5 #include "chrome/browser/ui/webui/cookies_tree_model_util.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 app_info->SetString(kKeyName, (*it)->name()); 332 app_info->SetString(kKeyName, (*it)->name());
333 app_infos->Append(std::move(app_info)); 333 app_infos->Append(std::move(app_info));
334 } 334 }
335 dict->Set(kKeyAppsProtectingThis, app_infos); 335 dict->Set(kKeyAppsProtectingThis, app_infos);
336 } 336 }
337 #endif 337 #endif
338 338
339 return true; 339 return true;
340 } 340 }
341 341
342 void CookiesTreeModelUtil::GetChildNodeDetails(const CookieTreeNode* parent,
343 int start,
344 int count,
345 bool include_quota_nodes,
346 base::ListValue* list) {
347 std::string id_path = GetTreeNodeId(parent);
348 for (int i = 0; i < count; ++i) {
349 const CookieTreeNode* child = parent->GetChild(start + i);
350 int cookie_count = child->child_count();
351 std::string cookie_id_path = id_path + "," + GetTreeNodeId(child) + ",";
352 for (int k = 0; k < cookie_count; ++k) {
353 const CookieTreeNode* details = child->GetChild(k);
354 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
355 if (GetCookieTreeNodeDictionary(*details, include_quota_nodes,
356 dict.get())) {
357 // TODO(dschuyler): This ID path is an artifact from using tree nodes to
358 // hold the cookies. Can this be changed to a dictionary with a key
359 // lookup (and remove use of id_map_)?
360 dict->SetString("idPath", cookie_id_path + GetTreeNodeId(details));
361 list->Append(std::move(dict));
362 }
363 }
364 }
365 }
366
342 void CookiesTreeModelUtil::GetChildNodeList(const CookieTreeNode* parent, 367 void CookiesTreeModelUtil::GetChildNodeList(const CookieTreeNode* parent,
343 int start, 368 int start,
344 int count, 369 int count,
345 bool include_quota_nodes, 370 bool include_quota_nodes,
346 base::ListValue* nodes) { 371 base::ListValue* nodes) {
347 for (int i = 0; i < count; ++i) { 372 for (int i = 0; i < count; ++i) {
348 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 373 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
349 const CookieTreeNode* child = parent->GetChild(start + i); 374 const CookieTreeNode* child = parent->GetChild(start + i);
350 if (GetCookieTreeNodeDictionary(*child, include_quota_nodes, dict.get())) 375 if (GetCookieTreeNodeDictionary(*child, include_quota_nodes, dict.get()))
351 nodes->Append(std::move(dict)); 376 nodes->Append(std::move(dict));
(...skipping 17 matching lines...) Expand all
369 child = id_map_.Lookup(node_id); 394 child = id_map_.Lookup(node_id);
370 child_index = parent->GetIndexOf(child); 395 child_index = parent->GetIndexOf(child);
371 if (child_index == -1) 396 if (child_index == -1)
372 break; 397 break;
373 398
374 parent = child; 399 parent = child;
375 } 400 }
376 401
377 return child_index >= 0 ? child : NULL; 402 return child_index >= 0 ? child : NULL;
378 } 403 }
404
405 const CookieTreeNode* CookiesTreeModelUtil::GetTreeNodeFromTitle(
406 const CookieTreeNode* root,
407 const base::string16& title) {
408 // TODO(dschuyler): This method reduces an old O(n^2) lookup with an O(n)
409 // lookup for O(1) space, but it could be further improved to O(1) lookup if
410 // desired (by trading O(n) space for the time improvement).
411 int site_count = root->child_count();
412 for (int i = 0; i < site_count; ++i) {
413 const CookieTreeNode* child = root->GetChild(i);
414 if (title == child->GetTitle())
415 return child;
416 }
417 return nullptr;
418 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/cookies_tree_model_util.h ('k') | chrome/browser/ui/webui/settings/settings_cookies_view_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698