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

Side by Side Diff: chrome/browser/bookmarks/bookmark_utils.cc

Issue 8273041: Permanent folders changes (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 2 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/bookmarks/bookmark_utils.h" 5 #include "chrome/browser/bookmarks/bookmark_utils.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 } 462 }
463 463
464 string16 GetNameForURL(const GURL& url) { 464 string16 GetNameForURL(const GURL& url) {
465 if (url.is_valid()) { 465 if (url.is_valid()) {
466 return net::GetSuggestedFilename(url, "", "", "", "", string16()); 466 return net::GetSuggestedFilename(url, "", "", "", "", string16());
467 } else { 467 } else {
468 return l10n_util::GetStringUTF16(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME); 468 return l10n_util::GetStringUTF16(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME);
469 } 469 }
470 } 470 }
471 471
472 // This is used with a tree iterator to skip subtrees which are not visible.
473 static bool PruneInvisibleFolders(const BookmarkNode* node) {
474 return !node->IsVisible();
475 }
476
472 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( 477 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders(
473 BookmarkModel* model, 478 BookmarkModel* model,
474 size_t max_count) { 479 size_t max_count) {
475 std::vector<const BookmarkNode*> nodes; 480 std::vector<const BookmarkNode*> nodes;
476 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node()); 481 ui::TreeNodeIterator<const BookmarkNode>
482 iterator(model->root_node(), PruneInvisibleFolders);
483
477 while (iterator.has_next()) { 484 while (iterator.has_next()) {
478 const BookmarkNode* parent = iterator.Next(); 485 const BookmarkNode* parent = iterator.Next();
479 if (parent->is_folder() && parent->date_folder_modified() > base::Time()) { 486 if (parent->is_folder() && parent->date_folder_modified() > base::Time()) {
480 if (max_count == 0) { 487 if (max_count == 0) {
481 nodes.push_back(parent); 488 nodes.push_back(parent);
482 } else { 489 } else {
483 std::vector<const BookmarkNode*>::iterator i = 490 std::vector<const BookmarkNode*>::iterator i =
484 std::upper_bound(nodes.begin(), nodes.end(), parent, 491 std::upper_bound(nodes.begin(), nodes.end(), parent,
485 &MoreRecentlyModified); 492 &MoreRecentlyModified);
486 if (nodes.size() < max_count || i != nodes.end()) { 493 if (nodes.size() < max_count || i != nodes.end()) {
487 nodes.insert(i, parent); 494 nodes.insert(i, parent);
488 while (nodes.size() > max_count) 495 while (nodes.size() > max_count)
489 nodes.pop_back(); 496 nodes.pop_back();
490 } 497 }
491 } 498 }
492 } // else case, the root node, which we don't care about or imported nodes 499 } // else case, the root node, which we don't care about or imported nodes
493 // (which have a time of 0). 500 // (which have a time of 0).
494 } 501 }
495 502
496 if (nodes.size() < max_count) { 503 if (nodes.size() < max_count) {
497 // Add the bookmark bar and other nodes if there is space. 504 // Add the permanent nodes if there is space. The permanent nodes are the
498 if (find(nodes.begin(), nodes.end(), model->bookmark_bar_node()) == 505 // only children of the root_node.
499 nodes.end()) { 506 const BookmarkNode* root_node = model->root_node();
500 nodes.push_back(model->bookmark_bar_node());
501 }
502 507
503 if (nodes.size() < max_count && 508 for (int i = 0; i < root_node->child_count(); ++i) {
504 find(nodes.begin(), nodes.end(), model->other_node()) == nodes.end()) { 509 const BookmarkNode* node = root_node->GetChild(i);
505 nodes.push_back(model->other_node()); 510 if (node->IsVisible() &&
506 } 511 find(nodes.begin(), nodes.end(), node) == nodes.end()) {
512 nodes.push_back(node);
507 513
508 if (nodes.size() < max_count && model->synced_node()->IsVisible() && 514 if (nodes.size() == max_count)
509 find(nodes.begin(), nodes.end(), 515 break;
510 model->synced_node()) == nodes.end()) { 516 }
511 nodes.push_back(model->synced_node());
512 } 517 }
513 } 518 }
514 return nodes; 519 return nodes;
515 } 520 }
516 521
517 void GetMostRecentlyAddedEntries(BookmarkModel* model, 522 void GetMostRecentlyAddedEntries(BookmarkModel* model,
518 size_t count, 523 size_t count,
519 std::vector<const BookmarkNode*>* nodes) { 524 std::vector<const BookmarkNode*>* nodes) {
520 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node()); 525 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node());
521 while (iterator.has_next()) { 526 while (iterator.has_next()) {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 // Remove all the bookmarks. 776 // Remove all the bookmarks.
772 for (size_t i = 0; i < bookmarks.size(); ++i) { 777 for (size_t i = 0; i < bookmarks.size(); ++i) {
773 const BookmarkNode* node = bookmarks[i]; 778 const BookmarkNode* node = bookmarks[i];
774 int index = node->parent()->GetIndexOf(node); 779 int index = node->parent()->GetIndexOf(node);
775 if (index > -1) 780 if (index > -1)
776 model->Remove(node->parent(), index); 781 model->Remove(node->parent(), index);
777 } 782 }
778 } 783 }
779 784
780 } // namespace bookmark_utils 785 } // namespace bookmark_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698