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

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

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