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

Side by Side Diff: chrome/browser/sync/glue/bookmark_change_processor.cc

Issue 549193002: Skip managed bookmarks at the BookmarkChangeProcessor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test Created 6 years, 3 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/sync/glue/bookmark_change_processor.h" 5 #include "chrome/browser/sync/glue/bookmark_change_processor.h"
6 6
7 #include <map> 7 #include <map>
8 #include <stack> 8 #include <stack>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 16 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
17 #include "chrome/browser/favicon/favicon_service.h" 17 #include "chrome/browser/favicon/favicon_service.h"
18 #include "chrome/browser/favicon/favicon_service_factory.h" 18 #include "chrome/browser/favicon/favicon_service_factory.h"
19 #include "chrome/browser/history/history_service.h" 19 #include "chrome/browser/history/history_service.h"
20 #include "chrome/browser/history/history_service_factory.h" 20 #include "chrome/browser/history/history_service_factory.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/sync/profile_sync_service.h" 22 #include "chrome/browser/sync/profile_sync_service.h"
23 #include "chrome/browser/undo/bookmark_undo_service.h" 23 #include "chrome/browser/undo/bookmark_undo_service.h"
24 #include "chrome/browser/undo/bookmark_undo_service_factory.h" 24 #include "chrome/browser/undo/bookmark_undo_service_factory.h"
25 #include "chrome/browser/undo/bookmark_undo_utils.h" 25 #include "chrome/browser/undo/bookmark_undo_utils.h"
26 #include "components/bookmarks/browser/bookmark_client.h"
26 #include "components/bookmarks/browser/bookmark_model.h" 27 #include "components/bookmarks/browser/bookmark_model.h"
27 #include "components/bookmarks/browser/bookmark_utils.h" 28 #include "components/bookmarks/browser/bookmark_utils.h"
28 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
29 #include "sync/internal_api/public/change_record.h" 30 #include "sync/internal_api/public/change_record.h"
30 #include "sync/internal_api/public/read_node.h" 31 #include "sync/internal_api/public/read_node.h"
31 #include "sync/internal_api/public/write_node.h" 32 #include "sync/internal_api/public/write_node.h"
32 #include "sync/internal_api/public/write_transaction.h" 33 #include "sync/internal_api/public/write_transaction.h"
33 #include "sync/syncable/entry.h" // TODO(tim): Investigating bug 121587. 34 #include "sync/syncable/entry.h" // TODO(tim): Investigating bug 121587.
34 #include "sync/syncable/syncable_write_transaction.h" 35 #include "sync/syncable/syncable_write_transaction.h"
35 #include "ui/gfx/favicon_size.h" 36 #include "ui/gfx/favicon_size.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } else { 208 } else {
208 int64 child_id = node.GetFirstChildId(); 209 int64 child_id = node.GetFirstChildId();
209 if (child_id != syncer::kInvalidId) { 210 if (child_id != syncer::kInvalidId) {
210 dfs_sync_id_stack.push(child_id); 211 dfs_sync_id_stack.push(child_id);
211 } 212 }
212 } 213 }
213 } 214 }
214 } 215 }
215 216
216 void BookmarkChangeProcessor::CreateOrUpdateSyncNode(const BookmarkNode* node) { 217 void BookmarkChangeProcessor::CreateOrUpdateSyncNode(const BookmarkNode* node) {
218 if (!CanSyncNode(node)) {
219 NOTREACHED();
220 return;
221 }
222
217 const BookmarkNode* parent = node->parent(); 223 const BookmarkNode* parent = node->parent();
218 int index = node->parent()->GetIndexOf(node); 224 int index = node->parent()->GetIndexOf(node);
219 225
220 int64 new_version = syncer::syncable::kInvalidTransactionVersion; 226 int64 new_version = syncer::syncable::kInvalidTransactionVersion;
221 int64 sync_id = syncer::kInvalidId; 227 int64 sync_id = syncer::kInvalidId;
222 { 228 {
223 // Acquire a scoped write lock via a transaction. 229 // Acquire a scoped write lock via a transaction.
224 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); 230 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version);
225 sync_id = model_associator_->GetSyncIdFromChromeId(node->id()); 231 sync_id = model_associator_->GetSyncIdFromChromeId(node->id());
226 if (sync_id != syncer::kInvalidId) { 232 if (sync_id != syncer::kInvalidId) {
(...skipping 28 matching lines...) Expand all
255 261
256 void BookmarkChangeProcessor::BookmarkModelBeingDeleted(BookmarkModel* model) { 262 void BookmarkChangeProcessor::BookmarkModelBeingDeleted(BookmarkModel* model) {
257 NOTREACHED(); 263 NOTREACHED();
258 bookmark_model_ = NULL; 264 bookmark_model_ = NULL;
259 } 265 }
260 266
261 void BookmarkChangeProcessor::BookmarkNodeAdded(BookmarkModel* model, 267 void BookmarkChangeProcessor::BookmarkNodeAdded(BookmarkModel* model,
262 const BookmarkNode* parent, 268 const BookmarkNode* parent,
263 int index) { 269 int index) {
264 DCHECK(share_handle()); 270 DCHECK(share_handle());
265 CreateOrUpdateSyncNode(parent->GetChild(index)); 271 const BookmarkNode* node = parent->GetChild(index);
272 if (CanSyncNode(node))
273 CreateOrUpdateSyncNode(node);
266 } 274 }
267 275
268 // static 276 // static
269 int64 BookmarkChangeProcessor::CreateSyncNode(const BookmarkNode* parent, 277 int64 BookmarkChangeProcessor::CreateSyncNode(const BookmarkNode* parent,
270 BookmarkModel* model, int index, syncer::WriteTransaction* trans, 278 BookmarkModel* model, int index, syncer::WriteTransaction* trans,
271 BookmarkModelAssociator* associator, 279 BookmarkModelAssociator* associator,
272 sync_driver::DataTypeErrorHandler* error_handler) { 280 sync_driver::DataTypeErrorHandler* error_handler) {
273 const BookmarkNode* child = parent->GetChild(index); 281 const BookmarkNode* child = parent->GetChild(index);
274 DCHECK(child); 282 DCHECK(child);
275 283
(...skipping 18 matching lines...) Expand all
294 302
295 return sync_child.GetId(); 303 return sync_child.GetId();
296 } 304 }
297 305
298 void BookmarkChangeProcessor::BookmarkNodeRemoved( 306 void BookmarkChangeProcessor::BookmarkNodeRemoved(
299 BookmarkModel* model, 307 BookmarkModel* model,
300 const BookmarkNode* parent, 308 const BookmarkNode* parent,
301 int index, 309 int index,
302 const BookmarkNode* node, 310 const BookmarkNode* node,
303 const std::set<GURL>& removed_urls) { 311 const std::set<GURL>& removed_urls) {
304 RemoveSyncNodeHierarchy(node); 312 if (CanSyncNode(node))
313 RemoveSyncNodeHierarchy(node);
305 } 314 }
306 315
307 void BookmarkChangeProcessor::BookmarkAllUserNodesRemoved( 316 void BookmarkChangeProcessor::BookmarkAllUserNodesRemoved(
308 BookmarkModel* model, 317 BookmarkModel* model,
309 const std::set<GURL>& removed_urls) { 318 const std::set<GURL>& removed_urls) {
310 RemoveAllSyncNodes(); 319 RemoveAllSyncNodes();
311 } 320 }
312 321
313 void BookmarkChangeProcessor::BookmarkNodeChanged(BookmarkModel* model, 322 void BookmarkChangeProcessor::BookmarkNodeChanged(BookmarkModel* model,
314 const BookmarkNode* node) { 323 const BookmarkNode* node) {
324 if (!CanSyncNode(node))
325 return;
315 // We shouldn't see changes to the top-level nodes. 326 // We shouldn't see changes to the top-level nodes.
316 if (model->is_permanent_node(node)) { 327 if (model->is_permanent_node(node)) {
317 NOTREACHED() << "Saw update to permanent node!"; 328 NOTREACHED() << "Saw update to permanent node!";
318 return; 329 return;
319 } 330 }
320 CreateOrUpdateSyncNode(node); 331 CreateOrUpdateSyncNode(node);
321 } 332 }
322 333
323 // Static. 334 // Static.
324 int64 BookmarkChangeProcessor::UpdateSyncNode( 335 int64 BookmarkChangeProcessor::UpdateSyncNode(
(...skipping 22 matching lines...) Expand all
347 358
348 void BookmarkChangeProcessor::BookmarkMetaInfoChanged( 359 void BookmarkChangeProcessor::BookmarkMetaInfoChanged(
349 BookmarkModel* model, const BookmarkNode* node) { 360 BookmarkModel* model, const BookmarkNode* node) {
350 BookmarkNodeChanged(model, node); 361 BookmarkNodeChanged(model, node);
351 } 362 }
352 363
353 void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, 364 void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model,
354 const BookmarkNode* old_parent, int old_index, 365 const BookmarkNode* old_parent, int old_index,
355 const BookmarkNode* new_parent, int new_index) { 366 const BookmarkNode* new_parent, int new_index) {
356 const BookmarkNode* child = new_parent->GetChild(new_index); 367 const BookmarkNode* child = new_parent->GetChild(new_index);
368
369 if (!CanSyncNode(child))
370 return;
371
357 // We shouldn't see changes to the top-level nodes. 372 // We shouldn't see changes to the top-level nodes.
358 if (model->is_permanent_node(child)) { 373 if (model->is_permanent_node(child)) {
359 NOTREACHED() << "Saw update to permanent node!"; 374 NOTREACHED() << "Saw update to permanent node!";
360 return; 375 return;
361 } 376 }
362 377
363 int64 new_version = syncer::syncable::kInvalidTransactionVersion; 378 int64 new_version = syncer::syncable::kInvalidTransactionVersion;
364 { 379 {
365 // Acquire a scoped write lock via a transaction. 380 // Acquire a scoped write lock via a transaction.
366 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); 381 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version);
(...skipping 25 matching lines...) Expand all
392 } 407 }
393 408
394 void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( 409 void BookmarkChangeProcessor::BookmarkNodeFaviconChanged(
395 BookmarkModel* model, 410 BookmarkModel* model,
396 const BookmarkNode* node) { 411 const BookmarkNode* node) {
397 BookmarkNodeChanged(model, node); 412 BookmarkNodeChanged(model, node);
398 } 413 }
399 414
400 void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( 415 void BookmarkChangeProcessor::BookmarkNodeChildrenReordered(
401 BookmarkModel* model, const BookmarkNode* node) { 416 BookmarkModel* model, const BookmarkNode* node) {
417 if (!CanSyncNode(node))
418 return;
402 int64 new_version = syncer::syncable::kInvalidTransactionVersion; 419 int64 new_version = syncer::syncable::kInvalidTransactionVersion;
403 std::vector<const BookmarkNode*> children; 420 std::vector<const BookmarkNode*> children;
404 { 421 {
405 // Acquire a scoped write lock via a transaction. 422 // Acquire a scoped write lock via a transaction.
406 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); 423 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version);
407 424
408 // The given node's children got reordered. We need to reorder all the 425 // The given node's children got reordered. We need to reorder all the
409 // children of the corresponding sync node. 426 // children of the corresponding sync node.
410 for (int i = 0; i < node->child_count(); ++i) { 427 for (int i = 0; i < node->child_count(); ++i) {
411 const BookmarkNode* child = node->GetChild(i); 428 const BookmarkNode* child = node->GetChild(i);
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 if (favicon_bytes.get() && favicon_bytes->size()) { 884 if (favicon_bytes.get() && favicon_bytes->size()) {
868 sync_pb::BookmarkSpecifics updated_specifics( 885 sync_pb::BookmarkSpecifics updated_specifics(
869 sync_node->GetBookmarkSpecifics()); 886 sync_node->GetBookmarkSpecifics());
870 updated_specifics.set_favicon(favicon_bytes->front(), 887 updated_specifics.set_favicon(favicon_bytes->front(),
871 favicon_bytes->size()); 888 favicon_bytes->size());
872 updated_specifics.set_icon_url(bookmark_node->icon_url().spec()); 889 updated_specifics.set_icon_url(bookmark_node->icon_url().spec());
873 sync_node->SetBookmarkSpecifics(updated_specifics); 890 sync_node->SetBookmarkSpecifics(updated_specifics);
874 } 891 }
875 } 892 }
876 893
894 bool BookmarkChangeProcessor::CanSyncNode(const BookmarkNode* node) {
895 return bookmark_model_->client()->CanSyncNode(node);
896 }
897
877 } // namespace browser_sync 898 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/bookmark_change_processor.h ('k') | chrome/browser/sync/test/integration/bookmarks_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698