Chromium Code Reviews| 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 if (base::ContainsValue(primary_nodes, node)) { |
|
sdefresne
2017/06/23 14:31:21
This can be changed to the following:
return ba
Tripta
2017/06/27 06:41:28
Done.
| |
| 76 primary_nodes.end()) { | |
| 77 return true; | 77 return true; |
| 78 } | 78 } |
| 79 return false; | 79 return false; |
| 80 } | 80 } |
| 81 | 81 |
| 82 const BookmarkNode* RootLevelFolderForNode(const BookmarkNode* node, | 82 const BookmarkNode* RootLevelFolderForNode(const BookmarkNode* node, |
| 83 BookmarkModel* model) { | 83 BookmarkModel* model) { |
| 84 // This helper function doesn't work for managed bookmarks. This checks that | 84 // 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 | 85 // |node| is editable by the user, which currently covers all the other |
| 86 // bookmarks except the managed bookmarks. | 86 // bookmarks except the managed bookmarks. |
| 87 DCHECK(model->client()->CanBeEditedByUser(node)); | 87 DCHECK(model->client()->CanBeEditedByUser(node)); |
| 88 | 88 |
| 89 const std::vector<const BookmarkNode*> root_folders(RootLevelFolders(model)); | 89 const std::vector<const BookmarkNode*> root_folders(RootLevelFolders(model)); |
| 90 const BookmarkNode* top = node; | 90 const BookmarkNode* top = node; |
| 91 while (top && | 91 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(); | 92 top = top->parent(); |
| 95 } | 93 } |
| 96 return top; | 94 return top; |
| 97 } | 95 } |
| OLD | NEW |