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

Side by Side Diff: components/sync_bookmarks/bookmark_change_processor.cc

Issue 2461463002: [Sync] Replacing NULL with nullptr/null throughout sync code. (Closed)
Patch Set: Reverted PROFILE_nullptr mistake. Created 4 years, 1 month 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 "components/sync_bookmarks/bookmark_change_processor.h" 5 #include "components/sync_bookmarks/bookmark_change_processor.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <stack> 10 #include <stack>
(...skipping 29 matching lines...) Expand all
40 40
41 namespace sync_bookmarks { 41 namespace sync_bookmarks {
42 42
43 static const char kMobileBookmarksTag[] = "synced_bookmarks"; 43 static const char kMobileBookmarksTag[] = "synced_bookmarks";
44 44
45 BookmarkChangeProcessor::BookmarkChangeProcessor( 45 BookmarkChangeProcessor::BookmarkChangeProcessor(
46 syncer::SyncClient* sync_client, 46 syncer::SyncClient* sync_client,
47 BookmarkModelAssociator* model_associator, 47 BookmarkModelAssociator* model_associator,
48 std::unique_ptr<syncer::DataTypeErrorHandler> err_handler) 48 std::unique_ptr<syncer::DataTypeErrorHandler> err_handler)
49 : syncer::ChangeProcessor(std::move(err_handler)), 49 : syncer::ChangeProcessor(std::move(err_handler)),
50 bookmark_model_(NULL), 50 bookmark_model_(nullptr),
51 sync_client_(sync_client), 51 sync_client_(sync_client),
52 model_associator_(model_associator) { 52 model_associator_(model_associator) {
53 DCHECK(model_associator); 53 DCHECK(model_associator);
54 DCHECK(sync_client); 54 DCHECK(sync_client);
55 DCHECK(error_handler()); 55 DCHECK(error_handler());
56 } 56 }
57 57
58 BookmarkChangeProcessor::~BookmarkChangeProcessor() { 58 BookmarkChangeProcessor::~BookmarkChangeProcessor() {
59 if (bookmark_model_) 59 if (bookmark_model_)
60 bookmark_model_->RemoveObserver(this); 60 bookmark_model_->RemoveObserver(this);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 } 273 }
274 } 274 }
275 275
276 void BookmarkChangeProcessor::BookmarkModelLoaded(BookmarkModel* model, 276 void BookmarkChangeProcessor::BookmarkModelLoaded(BookmarkModel* model,
277 bool ids_reassigned) { 277 bool ids_reassigned) {
278 NOTREACHED(); 278 NOTREACHED();
279 } 279 }
280 280
281 void BookmarkChangeProcessor::BookmarkModelBeingDeleted(BookmarkModel* model) { 281 void BookmarkChangeProcessor::BookmarkModelBeingDeleted(BookmarkModel* model) {
282 NOTREACHED(); 282 NOTREACHED();
283 bookmark_model_ = NULL; 283 bookmark_model_ = nullptr;
284 } 284 }
285 285
286 void BookmarkChangeProcessor::BookmarkNodeAdded(BookmarkModel* model, 286 void BookmarkChangeProcessor::BookmarkNodeAdded(BookmarkModel* model,
287 const BookmarkNode* parent, 287 const BookmarkNode* parent,
288 int index) { 288 int index) {
289 DCHECK(share_handle()); 289 DCHECK(share_handle());
290 const BookmarkNode* node = parent->GetChild(index); 290 const BookmarkNode* node = parent->GetChild(index);
291 if (CanSyncNode(node)) 291 if (CanSyncNode(node))
292 CreateOrUpdateSyncNode(node); 292 CreateOrUpdateSyncNode(node);
293 } 293 }
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 syncer::WriteNode* dst, BookmarkModelAssociator* associator) { 516 syncer::WriteNode* dst, BookmarkModelAssociator* associator) {
517 syncer::ReadNode sync_parent(trans); 517 syncer::ReadNode sync_parent(trans);
518 if (!associator->InitSyncNodeFromChromeId(parent->id(), &sync_parent)) { 518 if (!associator->InitSyncNodeFromChromeId(parent->id(), &sync_parent)) {
519 LOG(WARNING) << "Parent lookup failed"; 519 LOG(WARNING) << "Parent lookup failed";
520 return false; 520 return false;
521 } 521 }
522 522
523 bool success = false; 523 bool success = false;
524 if (index == 0) { 524 if (index == 0) {
525 // Insert into first position. 525 // Insert into first position.
526 success = (operation == CREATE) ? 526 success = (operation == CREATE)
527 dst->InitBookmarkByCreation(sync_parent, NULL) : 527 ? dst->InitBookmarkByCreation(sync_parent, nullptr)
528 dst->SetPosition(sync_parent, NULL); 528 : dst->SetPosition(sync_parent, nullptr);
529 if (success) { 529 if (success) {
530 DCHECK_EQ(dst->GetParentId(), sync_parent.GetId()); 530 DCHECK_EQ(dst->GetParentId(), sync_parent.GetId());
531 DCHECK_EQ(dst->GetId(), sync_parent.GetFirstChildId()); 531 DCHECK_EQ(dst->GetId(), sync_parent.GetFirstChildId());
532 DCHECK_EQ(dst->GetPredecessorId(), syncer::kInvalidId); 532 DCHECK_EQ(dst->GetPredecessorId(), syncer::kInvalidId);
533 } 533 }
534 } else { 534 } else {
535 // Find the bookmark model predecessor, and insert after it. 535 // Find the bookmark model predecessor, and insert after it.
536 const BookmarkNode* prev = parent->GetChild(index - 1); 536 const BookmarkNode* prev = parent->GetChild(index - 1);
537 syncer::ReadNode sync_prev(trans); 537 syncer::ReadNode sync_prev(trans);
538 if (!associator->InitSyncNodeFromChromeId(prev->id(), &sync_prev)) { 538 if (!associator->InitSyncNodeFromChromeId(prev->id(), &sync_prev)) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 sync_client_->GetBookmarkUndoServiceIfExists()); 587 sync_client_->GetBookmarkUndoServiceIfExists());
588 588
589 // Notify UI intensive observers of BookmarkModel that we are about to make 589 // Notify UI intensive observers of BookmarkModel that we are about to make
590 // potentially significant changes to it, so the updates may be batched. For 590 // potentially significant changes to it, so the updates may be batched. For
591 // example, on Mac, the bookmarks bar displays animations when bookmark items 591 // example, on Mac, the bookmarks bar displays animations when bookmark items
592 // are added or deleted. 592 // are added or deleted.
593 model->BeginExtensiveChanges(); 593 model->BeginExtensiveChanges();
594 594
595 // A parent to hold nodes temporarily orphaned by parent deletion. It is 595 // A parent to hold nodes temporarily orphaned by parent deletion. It is
596 // created only if it is needed. 596 // created only if it is needed.
597 const BookmarkNode* foster_parent = NULL; 597 const BookmarkNode* foster_parent = nullptr;
598 598
599 // Iterate over the deletions, which are always at the front of the list. 599 // Iterate over the deletions, which are always at the front of the list.
600 ChangeRecordList::const_iterator it; 600 ChangeRecordList::const_iterator it;
601 for (it = changes.Get().begin(); 601 for (it = changes.Get().begin();
602 it != changes.Get().end() && it->action == ChangeRecord::ACTION_DELETE; 602 it != changes.Get().end() && it->action == ChangeRecord::ACTION_DELETE;
603 ++it) { 603 ++it) {
604 const BookmarkNode* dst = 604 const BookmarkNode* dst =
605 model_associator_->GetChromeNodeFromSyncId(it->id); 605 model_associator_->GetChromeNodeFromSyncId(it->id);
606 606
607 // Ignore changes to the permanent top-level nodes. We only care about 607 // Ignore changes to the permanent top-level nodes. We only care about
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 model_associator_->GetChromeNodeFromSyncId(it->id); 660 model_associator_->GetChromeNodeFromSyncId(it->id);
661 661
662 // Ignore changes to the permanent top-level nodes. We only care about 662 // Ignore changes to the permanent top-level nodes. We only care about
663 // their children. 663 // their children.
664 if (model->is_permanent_node(dst)) 664 if (model->is_permanent_node(dst))
665 continue; 665 continue;
666 666
667 // Because the Synced Bookmarks node can be created server side, it's 667 // Because the Synced Bookmarks node can be created server side, it's
668 // possible it'll arrive at the client as an update. In that case it won't 668 // possible it'll arrive at the client as an update. In that case it won't
669 // have been associated at startup, the GetChromeNodeFromSyncId call above 669 // have been associated at startup, the GetChromeNodeFromSyncId call above
670 // will return NULL, and we won't detect it as a permanent node, resulting 670 // will return null, and we won't detect it as a permanent node, resulting
671 // in us trying to create it here (which will fail). Therefore, we add 671 // in us trying to create it here (which will fail). Therefore, we add
672 // special logic here just to detect the Synced Bookmarks folder. 672 // special logic here just to detect the Synced Bookmarks folder.
673 if (synced_bookmarks_id != syncer::kInvalidId && 673 if (synced_bookmarks_id != syncer::kInvalidId &&
674 it->id == synced_bookmarks_id) { 674 it->id == synced_bookmarks_id) {
675 // This is a newly created Synced Bookmarks node. Associate it. 675 // This is a newly created Synced Bookmarks node. Associate it.
676 model_associator_->Associate(model->mobile_node(), synced_bookmarks); 676 model_associator_->Associate(model->mobile_node(), synced_bookmarks);
677 continue; 677 continue;
678 } 678 }
679 679
680 DCHECK_NE(it->action, ChangeRecord::ACTION_DELETE) 680 DCHECK_NE(it->action, ChangeRecord::ACTION_DELETE)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 to_reposition.begin(); it != to_reposition.end(); ++it) { 734 to_reposition.begin(); it != to_reposition.end(); ++it) {
735 const BookmarkNode* parent = it->second->parent(); 735 const BookmarkNode* parent = it->second->parent();
736 model->Move(it->second, parent, it->first); 736 model->Move(it->second, parent, it->first);
737 } 737 }
738 738
739 // Clean up the temporary node. 739 // Clean up the temporary node.
740 if (foster_parent) { 740 if (foster_parent) {
741 // There should be no nodes left under the foster parent. 741 // There should be no nodes left under the foster parent.
742 DCHECK_EQ(foster_parent->child_count(), 0); 742 DCHECK_EQ(foster_parent->child_count(), 0);
743 model->Remove(foster_parent); 743 model->Remove(foster_parent);
744 foster_parent = NULL; 744 foster_parent = nullptr;
745 } 745 }
746 746
747 // Notify UI intensive observers of BookmarkModel that all updates have been 747 // Notify UI intensive observers of BookmarkModel that all updates have been
748 // applied, and that they may now be consumed. This prevents issues like the 748 // applied, and that they may now be consumed. This prevents issues like the
749 // one described in crbug.com/281562, where old and new items on the bookmarks 749 // one described in crbug.com/281562, where old and new items on the bookmarks
750 // bar would overlap. 750 // bar would overlap.
751 model->EndExtensiveChanges(); 751 model->EndExtensiveChanges();
752 752
753 // We are now ready to hear about bookmarks changes again. 753 // We are now ready to hear about bookmarks changes again.
754 model->AddObserver(this); 754 model->AddObserver(this);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 favicon_base::FAVICON, 954 favicon_base::FAVICON,
955 bitmap_data, 955 bitmap_data,
956 pixel_size); 956 pixel_size);
957 } 957 }
958 958
959 // static 959 // static
960 void BookmarkChangeProcessor::SetSyncNodeFavicon( 960 void BookmarkChangeProcessor::SetSyncNodeFavicon(
961 const BookmarkNode* bookmark_node, 961 const BookmarkNode* bookmark_node,
962 BookmarkModel* model, 962 BookmarkModel* model,
963 syncer::WriteNode* sync_node) { 963 syncer::WriteNode* sync_node) {
964 scoped_refptr<base::RefCountedMemory> favicon_bytes(NULL); 964 scoped_refptr<base::RefCountedMemory> favicon_bytes(nullptr);
965 EncodeFavicon(bookmark_node, model, &favicon_bytes); 965 EncodeFavicon(bookmark_node, model, &favicon_bytes);
966 if (favicon_bytes.get() && favicon_bytes->size()) { 966 if (favicon_bytes.get() && favicon_bytes->size()) {
967 sync_pb::BookmarkSpecifics updated_specifics( 967 sync_pb::BookmarkSpecifics updated_specifics(
968 sync_node->GetBookmarkSpecifics()); 968 sync_node->GetBookmarkSpecifics());
969 updated_specifics.set_favicon(favicon_bytes->front(), 969 updated_specifics.set_favicon(favicon_bytes->front(),
970 favicon_bytes->size()); 970 favicon_bytes->size());
971 updated_specifics.set_icon_url(bookmark_node->icon_url().spec()); 971 updated_specifics.set_icon_url(bookmark_node->icon_url().spec());
972 sync_node->SetBookmarkSpecifics(updated_specifics); 972 sync_node->SetBookmarkSpecifics(updated_specifics);
973 } 973 }
974 } 974 }
975 975
976 bool BookmarkChangeProcessor::CanSyncNode(const BookmarkNode* node) { 976 bool BookmarkChangeProcessor::CanSyncNode(const BookmarkNode* node) {
977 return bookmark_model_->client()->CanSyncNode(node); 977 return bookmark_model_->client()->CanSyncNode(node);
978 } 978 }
979 979
980 } // namespace sync_bookmarks 980 } // namespace sync_bookmarks
OLDNEW
« no previous file with comments | « components/sync_bookmarks/bookmark_change_processor.h ('k') | components/sync_bookmarks/bookmark_model_associator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698