| 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 "components/bookmarks/managed/managed_bookmark_service.h" | 5 #include "components/bookmarks/managed/managed_bookmark_service.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "components/bookmarks/browser/bookmark_model.h" | 20 #include "components/bookmarks/browser/bookmark_model.h" |
| 21 #include "components/bookmarks/browser/bookmark_utils.h" | 21 #include "components/bookmarks/browser/bookmark_utils.h" |
| 22 #include "components/bookmarks/managed/managed_bookmarks_tracker.h" | 22 #include "components/bookmarks/managed/managed_bookmarks_tracker.h" |
| 23 #include "grit/components_strings.h" | 23 #include "grit/components_strings.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 25 | 25 |
| 26 namespace bookmarks { | 26 namespace bookmarks { |
| 27 namespace { | 27 namespace { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 std::unique_ptr<base::ListValue> initial_bookmarks_; | 59 std::unique_ptr<base::ListValue> initial_bookmarks_; |
| 60 int title_id_; | 60 int title_id_; |
| 61 | 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(BookmarkPermanentNodeLoader); | 62 DISALLOW_COPY_AND_ASSIGN(BookmarkPermanentNodeLoader); |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 // Returns a list of initialized BookmarkPermanentNodes using |next_node_id| to | 65 // Returns a list of initialized BookmarkPermanentNodes using |next_node_id| to |
| 66 // start assigning id. |next_node_id| is updated as a side effect of calling | 66 // start assigning id. |next_node_id| is updated as a side effect of calling |
| 67 // this method. | 67 // this method. |
| 68 BookmarkPermanentNodeList LoadExtraNodes( | 68 BookmarkPermanentNodeList LoadExtraNodes( |
| 69 ScopedVector<BookmarkPermanentNodeLoader> loaders, | 69 std::vector<std::unique_ptr<BookmarkPermanentNodeLoader>> loaders, |
| 70 int64_t* next_node_id) { | 70 int64_t* next_node_id) { |
| 71 BookmarkPermanentNodeList extra_nodes; | 71 BookmarkPermanentNodeList extra_nodes; |
| 72 for (auto* loader : loaders) | 72 for (auto& loader : loaders) |
| 73 extra_nodes.push_back(loader->Load(next_node_id)); | 73 extra_nodes.push_back(loader->Load(next_node_id)); |
| 74 return extra_nodes; | 74 return extra_nodes; |
| 75 } | 75 } |
| 76 | 76 |
| 77 } // namespace | 77 } // namespace |
| 78 | 78 |
| 79 ManagedBookmarkService::ManagedBookmarkService( | 79 ManagedBookmarkService::ManagedBookmarkService( |
| 80 PrefService* prefs, | 80 PrefService* prefs, |
| 81 const GetManagementDomainCallback& callback) | 81 const GetManagementDomainCallback& callback) |
| 82 : prefs_(prefs), | 82 : prefs_(prefs), |
| (...skipping 26 matching lines...) Expand all Loading... |
| 109 // Create two BookmarkPermanentNode with a temporary id of 0. They will be | 109 // Create two BookmarkPermanentNode with a temporary id of 0. They will be |
| 110 // populated and assigned proper ids in the LoadExtraNodes callback. Until | 110 // populated and assigned proper ids in the LoadExtraNodes callback. Until |
| 111 // then, they are owned by the returned closure. | 111 // then, they are owned by the returned closure. |
| 112 std::unique_ptr<BookmarkPermanentNode> managed(new BookmarkPermanentNode(0)); | 112 std::unique_ptr<BookmarkPermanentNode> managed(new BookmarkPermanentNode(0)); |
| 113 std::unique_ptr<BookmarkPermanentNode> supervised( | 113 std::unique_ptr<BookmarkPermanentNode> supervised( |
| 114 new BookmarkPermanentNode(0)); | 114 new BookmarkPermanentNode(0)); |
| 115 | 115 |
| 116 managed_node_ = managed.get(); | 116 managed_node_ = managed.get(); |
| 117 supervised_node_ = supervised.get(); | 117 supervised_node_ = supervised.get(); |
| 118 | 118 |
| 119 ScopedVector<BookmarkPermanentNodeLoader> loaders; | 119 std::vector<std::unique_ptr<BookmarkPermanentNodeLoader>> loaders; |
| 120 loaders.push_back(new BookmarkPermanentNodeLoader( | 120 loaders.push_back(base::MakeUnique<BookmarkPermanentNodeLoader>( |
| 121 std::move(managed), | 121 std::move(managed), |
| 122 managed_bookmarks_tracker_->GetInitialManagedBookmarks(), | 122 managed_bookmarks_tracker_->GetInitialManagedBookmarks(), |
| 123 IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME)); | 123 IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME)); |
| 124 loaders.push_back(new BookmarkPermanentNodeLoader( | 124 loaders.push_back(base::MakeUnique<BookmarkPermanentNodeLoader>( |
| 125 std::move(supervised), | 125 std::move(supervised), |
| 126 supervised_bookmarks_tracker_->GetInitialManagedBookmarks(), | 126 supervised_bookmarks_tracker_->GetInitialManagedBookmarks(), |
| 127 IDS_BOOKMARK_BAR_SUPERVISED_FOLDER_DEFAULT_NAME)); | 127 IDS_BOOKMARK_BAR_SUPERVISED_FOLDER_DEFAULT_NAME)); |
| 128 | 128 |
| 129 return base::Bind(&LoadExtraNodes, base::Passed(&loaders)); | 129 return base::Bind(&LoadExtraNodes, base::Passed(&loaders)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool ManagedBookmarkService::CanSetPermanentNodeTitle( | 132 bool ManagedBookmarkService::CanSetPermanentNodeTitle( |
| 133 const BookmarkNode* node) { | 133 const BookmarkNode* node) { |
| 134 // |managed_node_| can have its title updated if the user signs in or out, | 134 // |managed_node_| can have its title updated if the user signs in or out, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 180 } |
| 181 | 181 |
| 182 managed_bookmarks_tracker_.reset(); | 182 managed_bookmarks_tracker_.reset(); |
| 183 supervised_bookmarks_tracker_.reset(); | 183 supervised_bookmarks_tracker_.reset(); |
| 184 | 184 |
| 185 managed_node_ = nullptr; | 185 managed_node_ = nullptr; |
| 186 supervised_node_ = nullptr; | 186 supervised_node_ = nullptr; |
| 187 } | 187 } |
| 188 | 188 |
| 189 } // namespace bookmarks | 189 } // namespace bookmarks |
| OLD | NEW |