| OLD | NEW |
| 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 Loading... |
| 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 |
| 471 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( | 476 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( |
| 472 BookmarkModel* model, | 477 BookmarkModel* model, |
| 473 size_t max_count) { | 478 size_t max_count) { |
| 474 std::vector<const BookmarkNode*> nodes; | 479 std::vector<const BookmarkNode*> nodes; |
| 475 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node()); | 480 ui::TreeNodeIterator<const BookmarkNode> |
| 481 iterator(model->root_node(), PruneInvisibleFolders); |
| 476 | 482 |
| 477 while (iterator.has_next()) { | 483 while (iterator.has_next()) { |
| 478 const BookmarkNode* parent = iterator.Next(); | 484 const BookmarkNode* parent = iterator.Next(); |
| 479 if (parent->is_folder() && parent->date_folder_modified() > base::Time()) { | 485 if (parent->is_folder() && parent->date_folder_modified() > base::Time()) { |
| 480 if (max_count == 0) { | 486 if (max_count == 0) { |
| 481 nodes.push_back(parent); | 487 nodes.push_back(parent); |
| 482 } else { | 488 } else { |
| 483 std::vector<const BookmarkNode*>::iterator i = | 489 std::vector<const BookmarkNode*>::iterator i = |
| 484 std::upper_bound(nodes.begin(), nodes.end(), parent, | 490 std::upper_bound(nodes.begin(), nodes.end(), parent, |
| 485 &MoreRecentlyModified); | 491 &MoreRecentlyModified); |
| 486 if (nodes.size() < max_count || i != nodes.end()) { | 492 if (nodes.size() < max_count || i != nodes.end()) { |
| 487 nodes.insert(i, parent); | 493 nodes.insert(i, parent); |
| 488 while (nodes.size() > max_count) | 494 while (nodes.size() > max_count) |
| 489 nodes.pop_back(); | 495 nodes.pop_back(); |
| 490 } | 496 } |
| 491 } | 497 } |
| 492 } // else case, the root node, which we don't care about or imported nodes | 498 } // else case, the root node, which we don't care about or imported nodes |
| 493 // (which have a time of 0). | 499 // (which have a time of 0). |
| 494 } | 500 } |
| 495 | 501 |
| 496 if (nodes.size() < max_count) { | 502 if (nodes.size() < max_count) { |
| 497 // Add the permanent nodes if there is space. The permanent nodes are the | 503 // Add the permanent nodes if there is space. The permanent nodes are the |
| 498 // only children of the root_node. | 504 // only children of the root_node. |
| 499 const BookmarkNode* root_node = model->root_node(); | 505 const BookmarkNode* root_node = model->root_node(); |
| 500 | 506 |
| 501 for (int i = 0; i < root_node->child_count(); ++i) { | 507 for (int i = 0; i < root_node->child_count(); ++i) { |
| 502 const BookmarkNode* node = root_node->GetChild(i); | 508 const BookmarkNode* node = root_node->GetChild(i); |
| 503 if (find(nodes.begin(), nodes.end(), node) == nodes.end()) { | 509 if (node->IsVisible() && |
| 510 find(nodes.begin(), nodes.end(), node) == nodes.end()) { |
| 504 nodes.push_back(node); | 511 nodes.push_back(node); |
| 505 | 512 |
| 506 if (nodes.size() == max_count) | 513 if (nodes.size() == max_count) |
| 507 break; | 514 break; |
| 508 } | 515 } |
| 509 } | 516 } |
| 510 } | 517 } |
| 511 return nodes; | 518 return nodes; |
| 512 } | 519 } |
| 513 | 520 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 void RecordBookmarkLaunch(BookmarkLaunchLocation location) { | 777 void RecordBookmarkLaunch(BookmarkLaunchLocation location) { |
| 771 #if defined(OS_WIN) | 778 #if defined(OS_WIN) |
| 772 // TODO(estade): do this on other platforms too. For now it's compiled out | 779 // TODO(estade): do this on other platforms too. For now it's compiled out |
| 773 // so that stats from platforms for which this is incompletely implemented | 780 // so that stats from platforms for which this is incompletely implemented |
| 774 // don't mix in with Windows, where it should be implemented exhaustively. | 781 // don't mix in with Windows, where it should be implemented exhaustively. |
| 775 UMA_HISTOGRAM_ENUMERATION("Bookmarks.LaunchLocation", location, LAUNCH_LIMIT); | 782 UMA_HISTOGRAM_ENUMERATION("Bookmarks.LaunchLocation", location, LAUNCH_LIMIT); |
| 776 #endif | 783 #endif |
| 777 } | 784 } |
| 778 | 785 |
| 779 } // namespace bookmark_utils | 786 } // namespace bookmark_utils |
| OLD | NEW |