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

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

Issue 8759017: BookmarkModel cleanup. synced_node is now mobile_node and I'm nuking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to trunk fix sync_integration_tests and extension test Created 9 years 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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 } 461 }
462 462
463 string16 GetNameForURL(const GURL& url) { 463 string16 GetNameForURL(const GURL& url) {
464 if (url.is_valid()) { 464 if (url.is_valid()) {
465 return net::GetSuggestedFilename(url, "", "", "", "", std::string()); 465 return net::GetSuggestedFilename(url, "", "", "", "", std::string());
466 } else { 466 } else {
467 return l10n_util::GetStringUTF16(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME); 467 return l10n_util::GetStringUTF16(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME);
468 } 468 }
469 } 469 }
470 470
471 // This is used with a tree iterator to skip subtrees which are not visible.
472 static bool PruneInvisibleFolders(const BookmarkNode* node) {
473 return !node->IsVisible();
474 }
475
476 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( 471 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders(
477 BookmarkModel* model, 472 BookmarkModel* model,
478 size_t max_count) { 473 size_t max_count) {
479 std::vector<const BookmarkNode*> nodes; 474 std::vector<const BookmarkNode*> nodes;
480 ui::TreeNodeIterator<const BookmarkNode> 475 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node());
481 iterator(model->root_node(), PruneInvisibleFolders);
482 476
483 while (iterator.has_next()) { 477 while (iterator.has_next()) {
484 const BookmarkNode* parent = iterator.Next(); 478 const BookmarkNode* parent = iterator.Next();
485 if (parent->is_folder() && parent->date_folder_modified() > base::Time()) { 479 if (parent->is_folder() && parent->date_folder_modified() > base::Time()) {
486 if (max_count == 0) { 480 if (max_count == 0) {
487 nodes.push_back(parent); 481 nodes.push_back(parent);
488 } else { 482 } else {
489 std::vector<const BookmarkNode*>::iterator i = 483 std::vector<const BookmarkNode*>::iterator i =
490 std::upper_bound(nodes.begin(), nodes.end(), parent, 484 std::upper_bound(nodes.begin(), nodes.end(), parent,
491 &MoreRecentlyModified); 485 &MoreRecentlyModified);
492 if (nodes.size() < max_count || i != nodes.end()) { 486 if (nodes.size() < max_count || i != nodes.end()) {
493 nodes.insert(i, parent); 487 nodes.insert(i, parent);
494 while (nodes.size() > max_count) 488 while (nodes.size() > max_count)
495 nodes.pop_back(); 489 nodes.pop_back();
496 } 490 }
497 } 491 }
498 } // else case, the root node, which we don't care about or imported nodes 492 } // else case, the root node, which we don't care about or imported nodes
499 // (which have a time of 0). 493 // (which have a time of 0).
500 } 494 }
501 495
502 if (nodes.size() < max_count) { 496 if (nodes.size() < max_count) {
503 // Add the permanent nodes if there is space. The permanent nodes are the 497 // Add the permanent nodes if there is space. The permanent nodes are the
504 // only children of the root_node. 498 // only children of the root_node.
505 const BookmarkNode* root_node = model->root_node(); 499 const BookmarkNode* root_node = model->root_node();
506 500
507 for (int i = 0; i < root_node->child_count(); ++i) { 501 for (int i = 0; i < root_node->child_count(); ++i) {
508 const BookmarkNode* node = root_node->GetChild(i); 502 const BookmarkNode* node = root_node->GetChild(i);
509 if (node->IsVisible() && 503 if (find(nodes.begin(), nodes.end(), node) == nodes.end()) {
510 find(nodes.begin(), nodes.end(), node) == nodes.end()) {
511 nodes.push_back(node); 504 nodes.push_back(node);
512 505
513 if (nodes.size() == max_count) 506 if (nodes.size() == max_count)
514 break; 507 break;
515 } 508 }
516 } 509 }
517 } 510 }
518 return nodes; 511 return nodes;
519 } 512 }
520 513
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 void RecordBookmarkLaunch(BookmarkLaunchLocation location) { 770 void RecordBookmarkLaunch(BookmarkLaunchLocation location) {
778 #if defined(OS_WIN) 771 #if defined(OS_WIN)
779 // TODO(estade): do this on other platforms too. For now it's compiled out 772 // TODO(estade): do this on other platforms too. For now it's compiled out
780 // so that stats from platforms for which this is incompletely implemented 773 // so that stats from platforms for which this is incompletely implemented
781 // don't mix in with Windows, where it should be implemented exhaustively. 774 // don't mix in with Windows, where it should be implemented exhaustively.
782 UMA_HISTOGRAM_ENUMERATION("Bookmarks.LaunchLocation", location, LAUNCH_LIMIT); 775 UMA_HISTOGRAM_ENUMERATION("Bookmarks.LaunchLocation", location, LAUNCH_LIMIT);
783 #endif 776 #endif
784 } 777 }
785 778
786 } // namespace bookmark_utils 779 } // namespace bookmark_utils
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_storage.cc ('k') | chrome/browser/bookmarks/recently_used_folders_combo_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698