OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/bookmarks/bookmarks_utils.h" | 5 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/stl_util.h" |
9 #include "components/bookmarks/browser/bookmark_model.h" | 10 #include "components/bookmarks/browser/bookmark_model.h" |
10 #include "components/prefs/pref_service.h" | 11 #include "components/prefs/pref_service.h" |
11 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" | 12 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" |
12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
13 #include "ios/chrome/browser/pref_names.h" | 14 #include "ios/chrome/browser/pref_names.h" |
14 | 15 |
15 using bookmarks::BookmarkModel; | 16 using bookmarks::BookmarkModel; |
16 using bookmarks::BookmarkNode; | 17 using bookmarks::BookmarkNode; |
17 | 18 |
18 void RecordBookmarkLaunch(BookmarkLaunchLocation launch_location) { | 19 void RecordBookmarkLaunch(BookmarkLaunchLocation launch_location) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 const BookmarkNode* node = parent->GetChild(i); | 66 const BookmarkNode* node = parent->GetChild(i); |
66 if (node->is_folder() && node->IsVisible()) | 67 if (node->is_folder() && node->IsVisible()) |
67 root_level_folders.push_back(node); | 68 root_level_folders.push_back(node); |
68 } | 69 } |
69 } | 70 } |
70 return root_level_folders; | 71 return root_level_folders; |
71 } | 72 } |
72 | 73 |
73 bool IsPrimaryPermanentNode(const BookmarkNode* node, BookmarkModel* model) { | 74 bool IsPrimaryPermanentNode(const BookmarkNode* node, BookmarkModel* model) { |
74 std::vector<const BookmarkNode*> primary_nodes(PrimaryPermanentNodes(model)); | 75 std::vector<const BookmarkNode*> primary_nodes(PrimaryPermanentNodes(model)); |
75 if (std::find(primary_nodes.begin(), primary_nodes.end(), node) != | 76 return base::ContainsValue(primary_nodes, node); |
76 primary_nodes.end()) { | |
77 return true; | |
78 } | |
79 return false; | |
80 } | 77 } |
81 | 78 |
82 const BookmarkNode* RootLevelFolderForNode(const BookmarkNode* node, | 79 const BookmarkNode* RootLevelFolderForNode(const BookmarkNode* node, |
83 BookmarkModel* model) { | 80 BookmarkModel* model) { |
84 // This helper function doesn't work for managed bookmarks. This checks that | 81 // This helper function doesn't work for managed bookmarks. This checks that |
85 // |node| is editable by the user, which currently covers all the other | 82 // |node| is editable by the user, which currently covers all the other |
86 // bookmarks except the managed bookmarks. | 83 // bookmarks except the managed bookmarks. |
87 DCHECK(model->client()->CanBeEditedByUser(node)); | 84 DCHECK(model->client()->CanBeEditedByUser(node)); |
88 | 85 |
89 const std::vector<const BookmarkNode*> root_folders(RootLevelFolders(model)); | 86 const std::vector<const BookmarkNode*> root_folders(RootLevelFolders(model)); |
90 const BookmarkNode* top = node; | 87 const BookmarkNode* top = node; |
91 while (top && | 88 while (top && !base::ContainsValue(root_folders, top)) { |
92 std::find(root_folders.begin(), root_folders.end(), top) == | |
93 root_folders.end()) { | |
94 top = top->parent(); | 89 top = top->parent(); |
95 } | 90 } |
96 return top; | 91 return top; |
97 } | 92 } |
OLD | NEW |