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

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

Issue 2376123003: [Sync] Move //components/sync to the syncer namespace. (Closed)
Patch Set: Rebase. Created 4 years, 2 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 "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 25 matching lines...) Expand all
36 using bookmarks::BookmarkModel; 36 using bookmarks::BookmarkModel;
37 using bookmarks::BookmarkNode; 37 using bookmarks::BookmarkNode;
38 using syncer::ChangeRecord; 38 using syncer::ChangeRecord;
39 using syncer::ChangeRecordList; 39 using syncer::ChangeRecordList;
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 sync_driver::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 : sync_driver::ChangeProcessor(std::move(err_handler)), 49 : syncer::ChangeProcessor(std::move(err_handler)),
50 bookmark_model_(NULL), 50 bookmark_model_(NULL),
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_)
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 // bookmark model to mark as synced. 757 // bookmark model to mark as synced.
758 model->SetNodeSyncTransactionVersion(model->root_node(), model_version); 758 model->SetNodeSyncTransactionVersion(model->root_node(), model_version);
759 } 759 }
760 760
761 // Static. 761 // Static.
762 // Update a bookmark node with specified sync data. 762 // Update a bookmark node with specified sync data.
763 void BookmarkChangeProcessor::UpdateBookmarkWithSyncData( 763 void BookmarkChangeProcessor::UpdateBookmarkWithSyncData(
764 const syncer::BaseNode& sync_node, 764 const syncer::BaseNode& sync_node,
765 BookmarkModel* model, 765 BookmarkModel* model,
766 const BookmarkNode* node, 766 const BookmarkNode* node,
767 sync_driver::SyncClient* sync_client) { 767 syncer::SyncClient* sync_client) {
768 DCHECK_EQ(sync_node.GetIsFolder(), node->is_folder()); 768 DCHECK_EQ(sync_node.GetIsFolder(), node->is_folder());
769 const sync_pb::BookmarkSpecifics& specifics = 769 const sync_pb::BookmarkSpecifics& specifics =
770 sync_node.GetBookmarkSpecifics(); 770 sync_node.GetBookmarkSpecifics();
771 if (!sync_node.GetIsFolder()) 771 if (!sync_node.GetIsFolder())
772 model->SetURL(node, GURL(specifics.url())); 772 model->SetURL(node, GURL(specifics.url()));
773 model->SetTitle(node, base::UTF8ToUTF16(sync_node.GetTitle())); 773 model->SetTitle(node, base::UTF8ToUTF16(sync_node.GetTitle()));
774 if (specifics.has_creation_time_us()) { 774 if (specifics.has_creation_time_us()) {
775 model->SetDateAdded( 775 model->SetDateAdded(
776 node, 776 node,
777 base::Time::FromInternalValue(specifics.creation_time_us())); 777 base::Time::FromInternalValue(specifics.creation_time_us()));
(...skipping 15 matching lines...) Expand all
793 } 793 }
794 } 794 }
795 795
796 // static 796 // static
797 // Creates a bookmark node under the given parent node from the given sync 797 // Creates a bookmark node under the given parent node from the given sync
798 // node. Returns the newly created node. 798 // node. Returns the newly created node.
799 const BookmarkNode* BookmarkChangeProcessor::CreateBookmarkNode( 799 const BookmarkNode* BookmarkChangeProcessor::CreateBookmarkNode(
800 const syncer::BaseNode* sync_node, 800 const syncer::BaseNode* sync_node,
801 const BookmarkNode* parent, 801 const BookmarkNode* parent,
802 BookmarkModel* model, 802 BookmarkModel* model,
803 sync_driver::SyncClient* sync_client, 803 syncer::SyncClient* sync_client,
804 int index) { 804 int index) {
805 return CreateBookmarkNode(base::UTF8ToUTF16(sync_node->GetTitle()), 805 return CreateBookmarkNode(base::UTF8ToUTF16(sync_node->GetTitle()),
806 GURL(sync_node->GetBookmarkSpecifics().url()), 806 GURL(sync_node->GetBookmarkSpecifics().url()),
807 sync_node, parent, model, sync_client, index); 807 sync_node, parent, model, sync_client, index);
808 } 808 }
809 809
810 // static 810 // static
811 // Creates a bookmark node under the given parent node from the given sync 811 // Creates a bookmark node under the given parent node from the given sync
812 // node. Returns the newly created node. 812 // node. Returns the newly created node.
813 const BookmarkNode* BookmarkChangeProcessor::CreateBookmarkNode( 813 const BookmarkNode* BookmarkChangeProcessor::CreateBookmarkNode(
814 const base::string16& title, 814 const base::string16& title,
815 const GURL& url, 815 const GURL& url,
816 const syncer::BaseNode* sync_node, 816 const syncer::BaseNode* sync_node,
817 const BookmarkNode* parent, 817 const BookmarkNode* parent,
818 BookmarkModel* model, 818 BookmarkModel* model,
819 sync_driver::SyncClient* sync_client, 819 syncer::SyncClient* sync_client,
820 int index) { 820 int index) {
821 DCHECK(parent); 821 DCHECK(parent);
822 822
823 const BookmarkNode* node; 823 const BookmarkNode* node;
824 if (sync_node->GetIsFolder()) { 824 if (sync_node->GetIsFolder()) {
825 node = model->AddFolderWithMetaInfo(parent, index, title, 825 node = model->AddFolderWithMetaInfo(parent, index, title,
826 GetBookmarkMetaInfo(sync_node).get()); 826 GetBookmarkMetaInfo(sync_node).get());
827 } else { 827 } else {
828 // 'creation_time_us' was added in m24. Assume a time of 0 means now. 828 // 'creation_time_us' was added in m24. Assume a time of 0 means now.
829 const sync_pb::BookmarkSpecifics& specifics = 829 const sync_pb::BookmarkSpecifics& specifics =
(...skipping 10 matching lines...) Expand all
840 840
841 return node; 841 return node;
842 } 842 }
843 843
844 // static 844 // static
845 // Sets the favicon of the given bookmark node from the given sync node. 845 // Sets the favicon of the given bookmark node from the given sync node.
846 bool BookmarkChangeProcessor::SetBookmarkFavicon( 846 bool BookmarkChangeProcessor::SetBookmarkFavicon(
847 const syncer::BaseNode* sync_node, 847 const syncer::BaseNode* sync_node,
848 const BookmarkNode* bookmark_node, 848 const BookmarkNode* bookmark_node,
849 BookmarkModel* bookmark_model, 849 BookmarkModel* bookmark_model,
850 sync_driver::SyncClient* sync_client) { 850 syncer::SyncClient* sync_client) {
851 const sync_pb::BookmarkSpecifics& specifics = 851 const sync_pb::BookmarkSpecifics& specifics =
852 sync_node->GetBookmarkSpecifics(); 852 sync_node->GetBookmarkSpecifics();
853 const std::string& icon_bytes_str = specifics.favicon(); 853 const std::string& icon_bytes_str = specifics.favicon();
854 if (icon_bytes_str.empty()) 854 if (icon_bytes_str.empty())
855 return false; 855 return false;
856 856
857 scoped_refptr<base::RefCountedString> icon_bytes( 857 scoped_refptr<base::RefCountedString> icon_bytes(
858 new base::RefCountedString()); 858 new base::RefCountedString());
859 icon_bytes->data().assign(icon_bytes_str); 859 icon_bytes->data().assign(icon_bytes_str);
860 GURL icon_url(specifics.icon_url()); 860 GURL icon_url(specifics.icon_url());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 meta_info->set_value(it->second); 929 meta_info->set_value(it->second);
930 } 930 }
931 } 931 }
932 932
933 sync_node->SetBookmarkSpecifics(specifics); 933 sync_node->SetBookmarkSpecifics(specifics);
934 } 934 }
935 935
936 // static 936 // static
937 void BookmarkChangeProcessor::ApplyBookmarkFavicon( 937 void BookmarkChangeProcessor::ApplyBookmarkFavicon(
938 const BookmarkNode* bookmark_node, 938 const BookmarkNode* bookmark_node,
939 sync_driver::SyncClient* sync_client, 939 syncer::SyncClient* sync_client,
940 const GURL& icon_url, 940 const GURL& icon_url,
941 const scoped_refptr<base::RefCountedMemory>& bitmap_data) { 941 const scoped_refptr<base::RefCountedMemory>& bitmap_data) {
942 history::HistoryService* history = sync_client->GetHistoryService(); 942 history::HistoryService* history = sync_client->GetHistoryService();
943 favicon::FaviconService* favicon_service = sync_client->GetFaviconService(); 943 favicon::FaviconService* favicon_service = sync_client->GetFaviconService();
944 944
945 history->AddPageNoVisitForBookmark(bookmark_node->url(), 945 history->AddPageNoVisitForBookmark(bookmark_node->url(),
946 bookmark_node->GetTitle()); 946 bookmark_node->GetTitle());
947 // The client may have cached the favicon at 2x. Use MergeFavicon() as not to 947 // The client may have cached the favicon at 2x. Use MergeFavicon() as not to
948 // overwrite the cached 2x favicon bitmap. Sync favicons are always 948 // overwrite the cached 2x favicon bitmap. Sync favicons are always
949 // gfx::kFaviconSize in width and height. Store the favicon into history 949 // gfx::kFaviconSize in width and height. Store the favicon into history
(...skipping 21 matching lines...) Expand all
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_data_type_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698