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

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

Issue 769153007: Managed bookmarks for supervised users (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chrome_bookmark_client.h" 5 #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 23 matching lines...) Expand all
34 if (bitmap_result.is_valid()) { 34 if (bitmap_result.is_valid()) {
35 result.image = gfx::Image::CreateFrom1xPNGBytes( 35 result.image = gfx::Image::CreateFrom1xPNGBytes(
36 bitmap_result.bitmap_data->front(), bitmap_result.bitmap_data->size()); 36 bitmap_result.bitmap_data->front(), bitmap_result.bitmap_data->size());
37 result.icon_url = bitmap_result.icon_url; 37 result.icon_url = bitmap_result.icon_url;
38 callback.Run(result); 38 callback.Run(result);
39 return; 39 return;
40 } 40 }
41 callback.Run(result); 41 callback.Run(result);
42 } 42 }
43 43
44 bool IsDescendantOf(const BookmarkNode* node, const BookmarkNode* root) {
45 return node && node->HasAncestor(root);
46 }
47
48 bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list,
Pam (message me for reviews) 2015/01/14 14:03:36 This name is a little misleading, so a quick comme
Marc Treib 2015/01/14 16:40:49 Done.
49 const BookmarkNode* root) {
50 for (size_t i = 0; i < list.size(); ++i) {
51 if (IsDescendantOf(list[i], root))
52 return true;
53 }
54 return false;
55 }
56
57 void LoadInitialContents(BookmarkPermanentNode* node,
58 base::ListValue* initial_bookmarks,
59 int64* next_node_id) {
60 // Load the initial contents of the |node| now, and assign it an unused ID.
Pam (message me for reviews) 2015/01/14 14:03:36 What are "initial" contents, as opposed to any oth
Marc Treib 2015/01/14 16:40:50 AIUI, the "initial contents" are just "whatever's
61 int64 id = *next_node_id;
62 node->set_id(id);
63 *next_node_id = policy::ManagedBookmarksTracker::LoadInitial(
64 node, initial_bookmarks, id + 1);
Pam (message me for reviews) 2015/01/14 14:03:37 I suppose this object is profile-keyed and not mul
Marc Treib 2015/01/14 16:40:49 "this object" meaning what, exactly? LoadInitial i
Pam (message me for reviews) 2015/01/15 11:37:03 OK, then, I suppose there's nothing to do here...
65 node->set_visible(!node->empty());
66 }
67
44 } // namespace 68 } // namespace
45 69
46 ChromeBookmarkClient::ChromeBookmarkClient(Profile* profile) 70 ChromeBookmarkClient::ChromeBookmarkClient(Profile* profile)
47 : profile_(profile), 71 : profile_(profile),
48 history_service_(NULL), 72 history_service_(NULL),
49 model_(NULL), 73 model_(NULL),
50 managed_node_(NULL) { 74 managed_node_(NULL),
75 supervised_node_(NULL) {
51 } 76 }
52 77
53 ChromeBookmarkClient::~ChromeBookmarkClient() { 78 ChromeBookmarkClient::~ChromeBookmarkClient() {
54 } 79 }
55 80
56 void ChromeBookmarkClient::Init(BookmarkModel* model) { 81 void ChromeBookmarkClient::Init(BookmarkModel* model) {
57 DCHECK(model); 82 DCHECK(model);
58 DCHECK(!model_); 83 DCHECK(!model_);
59 model_ = model; 84 model_ = model;
60 model_->AddObserver(this); 85 model_->AddObserver(this);
61 86
62 managed_bookmarks_tracker_.reset(new policy::ManagedBookmarksTracker( 87 managed_bookmarks_tracker_.reset(new policy::ManagedBookmarksTracker(
63 model_, 88 model_,
64 profile_->GetPrefs(), 89 profile_->GetPrefs(),
90 false,
65 base::Bind(&ChromeBookmarkClient::GetManagedBookmarksDomain, 91 base::Bind(&ChromeBookmarkClient::GetManagedBookmarksDomain,
66 base::Unretained(this)))); 92 base::Unretained(this))));
93 supervised_bookmarks_tracker_.reset(new policy::ManagedBookmarksTracker(
94 model_,
95 profile_->GetPrefs(),
96 true,
97 base::Callback<std::string()>()));
67 } 98 }
68 99
69 void ChromeBookmarkClient::Shutdown() { 100 void ChromeBookmarkClient::Shutdown() {
70 favicon_changed_subscription_.reset(); 101 favicon_changed_subscription_.reset();
71 if (model_) { 102 if (model_) {
72 model_->RemoveObserver(this); 103 model_->RemoveObserver(this);
73 model_ = NULL; 104 model_ = NULL;
74 } 105 }
75 BookmarkClient::Shutdown(); 106 BookmarkClient::Shutdown();
76 } 107 }
77 108
78 bool ChromeBookmarkClient::IsDescendantOfManagedNode(const BookmarkNode* node) { 109 bool ChromeBookmarkClient::IsDescendantOfManagedNode(const BookmarkNode* node) {
79 return node && node->HasAncestor(managed_node_); 110 return IsDescendantOf(node, managed_node_);
80 } 111 }
81 112
82 bool ChromeBookmarkClient::HasDescendantsOfManagedNode( 113 bool ChromeBookmarkClient::HasDescendantsOfManagedNode(
83 const std::vector<const BookmarkNode*>& list) { 114 const std::vector<const BookmarkNode*>& list) {
84 for (size_t i = 0; i < list.size(); ++i) { 115 return HasDescendantsOf(list, managed_node_);
85 if (IsDescendantOfManagedNode(list[i])) 116 }
86 return true; 117
87 } 118 bool ChromeBookmarkClient::IsDescendantOfSupervisedNode(
88 return false; 119 const BookmarkNode* node) {
120 return IsDescendantOf(node, supervised_node_);
121 }
122
123 bool ChromeBookmarkClient::HasDescendantsOfSupervisedNode(
124 const std::vector<const BookmarkNode*>& list) {
125 return HasDescendantsOf(list, supervised_node_);
126 }
127
128 bool ChromeBookmarkClient::IsDescendantOfManagedOrSupervisedNode(
129 const BookmarkNode* node) {
130 return IsDescendantOfManagedNode(node) || IsDescendantOfSupervisedNode(node);
131 }
132
133 bool ChromeBookmarkClient::HasDescendantsOfManagedOrSupervisedNode(
134 const std::vector<const BookmarkNode*>& list) {
135 return HasDescendantsOfManagedNode(list) ||
136 HasDescendantsOfSupervisedNode(list);
89 } 137 }
90 138
91 bool ChromeBookmarkClient::PreferTouchIcon() { 139 bool ChromeBookmarkClient::PreferTouchIcon() {
92 #if !defined(OS_IOS) 140 #if !defined(OS_IOS)
93 return false; 141 return false;
94 #else 142 #else
95 return true; 143 return true;
96 #endif 144 #endif
97 } 145 }
98 146
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 NodeTypedCountPair pair(*i, typed_count); 189 NodeTypedCountPair pair(*i, typed_count);
142 node_typed_count_pairs->push_back(pair); 190 node_typed_count_pairs->push_back(pair);
143 } 191 }
144 } 192 }
145 193
146 bool ChromeBookmarkClient::IsPermanentNodeVisible( 194 bool ChromeBookmarkClient::IsPermanentNodeVisible(
147 const BookmarkPermanentNode* node) { 195 const BookmarkPermanentNode* node) {
148 DCHECK(node->type() == BookmarkNode::BOOKMARK_BAR || 196 DCHECK(node->type() == BookmarkNode::BOOKMARK_BAR ||
149 node->type() == BookmarkNode::OTHER_NODE || 197 node->type() == BookmarkNode::OTHER_NODE ||
150 node->type() == BookmarkNode::MOBILE || 198 node->type() == BookmarkNode::MOBILE ||
151 node == managed_node_); 199 node == managed_node_ ||
152 if (node == managed_node_) 200 node == supervised_node_);
201 if (node == managed_node_ || node == supervised_node_)
153 return false; 202 return false;
154 #if !defined(OS_IOS) 203 #if !defined(OS_IOS)
155 return node->type() != BookmarkNode::MOBILE; 204 return node->type() != BookmarkNode::MOBILE;
156 #else 205 #else
157 return node->type() == BookmarkNode::MOBILE; 206 return node->type() == BookmarkNode::MOBILE;
158 #endif 207 #endif
159 } 208 }
160 209
161 void ChromeBookmarkClient::RecordAction(const base::UserMetricsAction& action) { 210 void ChromeBookmarkClient::RecordAction(const base::UserMetricsAction& action) {
162 content::RecordAction(action); 211 content::RecordAction(action);
163 } 212 }
164 213
165 bookmarks::LoadExtraCallback ChromeBookmarkClient::GetLoadExtraNodesCallback() { 214 bookmarks::LoadExtraCallback ChromeBookmarkClient::GetLoadExtraNodesCallback() {
166 // Create the managed_node now; it will be populated in the LoadExtraNodes 215 // Create the managed_node_ and supervised_node_ now; they will be populated
167 // callback. 216 // in the LoadExtraNodes callback.
168 // The ownership of managed_node_ is in limbo until LoadExtraNodes runs, 217 // The ownership of managed_node_ and supervised_node_ is in limbo until
169 // so we leave it in the care of the closure meanwhile. 218 // LoadExtraNodes runs, so we leave them in the care of the closure meanwhile.
170 scoped_ptr<BookmarkPermanentNode> managed(new BookmarkPermanentNode(0)); 219 scoped_ptr<BookmarkPermanentNode> managed(new BookmarkPermanentNode(0));
171 managed_node_ = managed.get(); 220 managed_node_ = managed.get();
221 scoped_ptr<BookmarkPermanentNode> supervised(new BookmarkPermanentNode(1));
222 supervised_node_ = supervised.get();
172 223
173 return base::Bind( 224 return base::Bind(
174 &ChromeBookmarkClient::LoadExtraNodes, 225 &ChromeBookmarkClient::LoadExtraNodes,
175 base::Passed(&managed), 226 base::Passed(&managed),
176 base::Passed(managed_bookmarks_tracker_->GetInitialManagedBookmarks())); 227 base::Passed(managed_bookmarks_tracker_->GetInitialManagedBookmarks()),
228 base::Passed(&supervised),
229 base::Passed(
230 supervised_bookmarks_tracker_->GetInitialManagedBookmarks()));
177 } 231 }
178 232
179 bool ChromeBookmarkClient::CanSetPermanentNodeTitle( 233 bool ChromeBookmarkClient::CanSetPermanentNodeTitle(
180 const BookmarkNode* permanent_node) { 234 const BookmarkNode* permanent_node) {
181 // The |managed_node_| can have its title updated if the user signs in or 235 // The |managed_node_| can have its title updated if the user signs in or
Pam (message me for reviews) 2015/01/14 14:03:36 Please explain why |managed_node_| (that is, the t
Marc Treib 2015/01/14 16:40:49 Done.
182 // out. 236 // out.
183 return !IsDescendantOfManagedNode(permanent_node) || 237 return !IsDescendantOfManagedOrSupervisedNode(permanent_node) ||
184 permanent_node == managed_node_; 238 permanent_node == managed_node_;
185 } 239 }
186 240
187 bool ChromeBookmarkClient::CanSyncNode(const BookmarkNode* node) { 241 bool ChromeBookmarkClient::CanSyncNode(const BookmarkNode* node) {
188 return !IsDescendantOfManagedNode(node); 242 return !IsDescendantOfManagedOrSupervisedNode(node);
189 } 243 }
190 244
191 bool ChromeBookmarkClient::CanBeEditedByUser(const BookmarkNode* node) { 245 bool ChromeBookmarkClient::CanBeEditedByUser(const BookmarkNode* node) {
192 return !IsDescendantOfManagedNode(node); 246 return !IsDescendantOfManagedOrSupervisedNode(node);
193 } 247 }
194 248
195 void ChromeBookmarkClient::SetHistoryService(HistoryService* history_service) { 249 void ChromeBookmarkClient::SetHistoryService(HistoryService* history_service) {
196 DCHECK(history_service); 250 DCHECK(history_service);
197 history_service_ = history_service; 251 history_service_ = history_service;
198 favicon_changed_subscription_ = history_service_->AddFaviconChangedCallback( 252 favicon_changed_subscription_ = history_service_->AddFaviconChangedCallback(
199 base::Bind(&BookmarkModel::OnFaviconChanged, base::Unretained(model_))); 253 base::Bind(&BookmarkModel::OnFaviconChanged, base::Unretained(model_)));
200 } 254 }
201 255
202 void ChromeBookmarkClient::BookmarkModelChanged() { 256 void ChromeBookmarkClient::BookmarkModelChanged() {
(...skipping 11 matching lines...) Expand all
214 268
215 void ChromeBookmarkClient::BookmarkAllUserNodesRemoved( 269 void ChromeBookmarkClient::BookmarkAllUserNodesRemoved(
216 BookmarkModel* model, 270 BookmarkModel* model,
217 const std::set<GURL>& removed_urls) { 271 const std::set<GURL>& removed_urls) {
218 if (history_service_) 272 if (history_service_)
219 history_service_->URLsNoLongerBookmarked(removed_urls); 273 history_service_->URLsNoLongerBookmarked(removed_urls);
220 } 274 }
221 275
222 void ChromeBookmarkClient::BookmarkModelLoaded(BookmarkModel* model, 276 void ChromeBookmarkClient::BookmarkModelLoaded(BookmarkModel* model,
223 bool ids_reassigned) { 277 bool ids_reassigned) {
224 // Start tracking the managed bookmarks. This will detect any changes that 278 // Start tracking the managed bookmarks. This will detect any changes that
Pam (message me for reviews) 2015/01/14 14:03:37 "managed and supervised" x 2
Marc Treib 2015/01/14 16:40:50 Done.
225 // may have occurred while the initial managed bookmarks were being loaded 279 // may have occurred while the initial managed bookmarks were being loaded
226 // on the background. 280 // on the background.
227 managed_bookmarks_tracker_->Init(managed_node_); 281 managed_bookmarks_tracker_->Init(managed_node_);
282 supervised_bookmarks_tracker_->Init(supervised_node_);
228 } 283 }
229 284
230 // static 285 // static
231 bookmarks::BookmarkPermanentNodeList ChromeBookmarkClient::LoadExtraNodes( 286 bookmarks::BookmarkPermanentNodeList ChromeBookmarkClient::LoadExtraNodes(
232 scoped_ptr<BookmarkPermanentNode> managed_node, 287 scoped_ptr<BookmarkPermanentNode> managed_node,
233 scoped_ptr<base::ListValue> initial_managed_bookmarks, 288 scoped_ptr<base::ListValue> initial_managed_bookmarks,
289 scoped_ptr<BookmarkPermanentNode> supervised_node,
290 scoped_ptr<base::ListValue> initial_supervised_bookmarks,
234 int64* next_node_id) { 291 int64* next_node_id) {
235 // Load the initial contents of the |managed_node| now, and assign it an 292 LoadInitialContents(
236 // unused ID. 293 managed_node.get(), initial_managed_bookmarks.get(), next_node_id);
237 int64 managed_id = *next_node_id; 294 managed_node->SetTitle(l10n_util::GetStringUTF16(
238 managed_node->set_id(managed_id); 295 IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME));
239 *next_node_id = policy::ManagedBookmarksTracker::LoadInitial( 296
240 managed_node.get(), initial_managed_bookmarks.get(), managed_id + 1); 297 LoadInitialContents(
241 managed_node->set_visible(!managed_node->empty()); 298 supervised_node.get(), initial_supervised_bookmarks.get(), next_node_id);
242 managed_node->SetTitle( 299 supervised_node->SetTitle(l10n_util::GetStringUTF16(
243 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME)); 300 IDS_BOOKMARK_BAR_SUPERVISED_FOLDER_DEFAULT_NAME));
244 301
245 bookmarks::BookmarkPermanentNodeList extra_nodes; 302 bookmarks::BookmarkPermanentNodeList extra_nodes;
246 // Ownership of the managed node passed to the caller. 303 // Ownership of the managed and supervised nodes passed to the caller.
247 extra_nodes.push_back(managed_node.release()); 304 extra_nodes.push_back(managed_node.release());
305 extra_nodes.push_back(supervised_node.release());
248 306
249 return extra_nodes.Pass(); 307 return extra_nodes.Pass();
250 } 308 }
251 309
252 std::string ChromeBookmarkClient::GetManagedBookmarksDomain() { 310 std::string ChromeBookmarkClient::GetManagedBookmarksDomain() {
253 policy::ProfilePolicyConnector* connector = 311 policy::ProfilePolicyConnector* connector =
254 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_); 312 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_);
255 if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks)) 313 if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks))
256 return connector->GetManagementDomain(); 314 return connector->GetManagementDomain();
257 return std::string(); 315 return std::string();
258 } 316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698