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

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

Issue 7012005: Revert "Revert 84829 - Initial implementation of "Synced Bookmarks" folder." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Trying to set .json eol-style Created 9 years, 7 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/recently_used_folders_combo_model.h" 5 #include "chrome/browser/bookmarks/recently_used_folders_combo_model.h"
6 6
7 #include "chrome/browser/bookmarks/bookmark_utils.h" 7 #include "chrome/browser/bookmarks/bookmark_utils.h"
8 #include "grit/generated_resources.h" 8 #include "grit/generated_resources.h"
9 #include "ui/base/l10n/l10n_util.h" 9 #include "ui/base/l10n/l10n_util.h"
10 10
11 namespace { 11 namespace {
12 12
13 // Max number of most recently used folders. 13 // Max number of most recently used folders.
14 const size_t kMaxMRUFolders = 5; 14 const size_t kMaxMRUFolders = 5;
15 15
16 } // namespace 16 } // namespace
17 17
18 RecentlyUsedFoldersComboModel::RecentlyUsedFoldersComboModel( 18 RecentlyUsedFoldersComboModel::RecentlyUsedFoldersComboModel(
19 BookmarkModel* model, const BookmarkNode* node) 19 BookmarkModel* model, const BookmarkNode* node)
20 // Use + 2 to account for bookmark bar and other node. 20 // Use + 2 to account for bookmark bar and other node.
21 : nodes_(bookmark_utils::GetMostRecentlyModifiedFolders( 21 : nodes_(bookmark_utils::GetMostRecentlyModifiedFolders(
22 model, kMaxMRUFolders + 2)), 22 model, kMaxMRUFolders + 2)),
23 node_parent_index_(0) { 23 node_parent_index_(0) {
24 // TODO(sky): bug 1173415 add a separator in the combobox here. 24 // TODO(sky): bug 1173415 add a separator in the combobox here.
25 25
26 // We special case the placement of these, so remove them from the list, then 26 // We special case the placement of these, so remove them from the list, then
27 // fix up the order. 27 // fix up the order.
28 RemoveNode(model->GetBookmarkBarNode()); 28 RemoveNode(model->GetBookmarkBarNode());
29 RemoveNode(model->synced_node());
29 RemoveNode(model->other_node()); 30 RemoveNode(model->other_node());
30 RemoveNode(node->parent()); 31 RemoveNode(node->parent());
31 32
32 // Make the parent the first item, unless it's the bookmark bar or other node. 33 // Make the parent the first item, unless it's the bookmark bar or other node.
33 if (node->parent() != model->GetBookmarkBarNode() && 34 if (!model->is_permanent_node(node)) {
34 node->parent() != model->other_node()) {
35 nodes_.insert(nodes_.begin(), node->parent()); 35 nodes_.insert(nodes_.begin(), node->parent());
36 } 36 }
37 37
38 // Make sure we only have kMaxMRUFolders in the first chunk. 38 // Make sure we only have kMaxMRUFolders in the first chunk.
39 if (nodes_.size() > kMaxMRUFolders) 39 if (nodes_.size() > kMaxMRUFolders)
40 nodes_.erase(nodes_.begin() + kMaxMRUFolders, nodes_.end()); 40 nodes_.erase(nodes_.begin() + kMaxMRUFolders, nodes_.end());
41 41
42 // And put the bookmark bar and other nodes at the end of the list. 42 // And put the bookmark bar and other nodes at the end of the list.
43 nodes_.push_back(model->GetBookmarkBarNode()); 43 nodes_.push_back(model->GetBookmarkBarNode());
44 nodes_.push_back(model->other_node()); 44 nodes_.push_back(model->other_node());
45 if (model->synced_node()->IsVisible()) {
46 nodes_.push_back(model->synced_node());
47 }
45 48
46 std::vector<const BookmarkNode*>::iterator it = std::find(nodes_.begin(), 49 std::vector<const BookmarkNode*>::iterator it = std::find(nodes_.begin(),
47 nodes_.end(), 50 nodes_.end(),
48 node->parent()); 51 node->parent());
49 node_parent_index_ = static_cast<int>(it - nodes_.begin()); 52 node_parent_index_ = static_cast<int>(it - nodes_.begin());
50 } 53 }
51 54
52 RecentlyUsedFoldersComboModel::~RecentlyUsedFoldersComboModel() {} 55 RecentlyUsedFoldersComboModel::~RecentlyUsedFoldersComboModel() {}
53 56
54 int RecentlyUsedFoldersComboModel::GetItemCount() { 57 int RecentlyUsedFoldersComboModel::GetItemCount() {
(...skipping 12 matching lines...) Expand all
67 return nodes_[index]; 70 return nodes_[index];
68 } 71 }
69 72
70 void RecentlyUsedFoldersComboModel::RemoveNode(const BookmarkNode* node) { 73 void RecentlyUsedFoldersComboModel::RemoveNode(const BookmarkNode* node) {
71 std::vector<const BookmarkNode*>::iterator it = std::find(nodes_.begin(), 74 std::vector<const BookmarkNode*>::iterator it = std::find(nodes_.begin(),
72 nodes_.end(), 75 nodes_.end(),
73 node); 76 node);
74 if (it != nodes_.end()) 77 if (it != nodes_.end())
75 nodes_.erase(it); 78 nodes_.erase(it);
76 } 79 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_utils.cc ('k') | chrome/browser/extensions/extension_bookmark_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698