OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <stack> | 7 #include <stack> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 } | 693 } |
694 | 694 |
695 // static | 695 // static |
696 // Sets the favicon of the given bookmark node from the given sync node. | 696 // Sets the favicon of the given bookmark node from the given sync node. |
697 bool BookmarkChangeProcessor::SetBookmarkFavicon( | 697 bool BookmarkChangeProcessor::SetBookmarkFavicon( |
698 syncer::BaseNode* sync_node, | 698 syncer::BaseNode* sync_node, |
699 const BookmarkNode* bookmark_node, | 699 const BookmarkNode* bookmark_node, |
700 BookmarkModel* bookmark_model) { | 700 BookmarkModel* bookmark_model) { |
701 const sync_pb::BookmarkSpecifics& specifics = | 701 const sync_pb::BookmarkSpecifics& specifics = |
702 sync_node->GetBookmarkSpecifics(); | 702 sync_node->GetBookmarkSpecifics(); |
703 const std::string& icon_str = specifics.favicon(); | 703 const std::string& icon_bytes_str = specifics.favicon(); |
704 if (icon_str.empty()) | 704 if (icon_bytes_str.empty()) |
705 return false; | 705 return false; |
706 | 706 |
707 scoped_refptr<base::RefCountedString> icon_bytes( | 707 scoped_refptr<base::RefCountedString> icon_bytes( |
708 new base::RefCountedString()); | 708 new base::RefCountedString()); |
709 icon_bytes->data().assign(icon_str); | 709 icon_bytes->data().assign(icon_bytes_str); |
| 710 GURL icon_url(specifics.icon_url()); |
710 | 711 |
711 ApplyBookmarkFavicon(bookmark_node, bookmark_model->profile(), | 712 // Old clients may not be syncing the favicon URL. If the icon URL is not |
| 713 // synced, use the page URL as a fake icon URL as it is guaranteed to be |
| 714 // unique. |
| 715 if (icon_url.is_empty()) |
| 716 icon_url = bookmark_node->url(); |
| 717 |
| 718 ApplyBookmarkFavicon(bookmark_node, bookmark_model->profile(), icon_url, |
712 icon_bytes); | 719 icon_bytes); |
713 | 720 |
714 return true; | 721 return true; |
715 } | 722 } |
716 | 723 |
717 // static | 724 // static |
718 void BookmarkChangeProcessor::ApplyBookmarkFavicon( | 725 void BookmarkChangeProcessor::ApplyBookmarkFavicon( |
719 const BookmarkNode* bookmark_node, | 726 const BookmarkNode* bookmark_node, |
720 Profile* profile, | 727 Profile* profile, |
| 728 const GURL& icon_url, |
721 const scoped_refptr<base::RefCountedMemory>& bitmap_data) { | 729 const scoped_refptr<base::RefCountedMemory>& bitmap_data) { |
722 HistoryService* history = | 730 HistoryService* history = |
723 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); | 731 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); |
724 FaviconService* favicon_service = | 732 FaviconService* favicon_service = |
725 FaviconServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); | 733 FaviconServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); |
726 | 734 |
727 history->AddPageNoVisitForBookmark(bookmark_node->url(), | 735 history->AddPageNoVisitForBookmark(bookmark_node->url(), |
728 bookmark_node->GetTitle()); | 736 bookmark_node->GetTitle()); |
729 // The client may have cached the favicon at 2x. Use MergeFavicon() as not to | 737 // The client may have cached the favicon at 2x. Use MergeFavicon() as not to |
730 // overwrite the cached 2x favicon bitmap. Use the page URL as a fake icon URL | 738 // overwrite the cached 2x favicon bitmap. Sync favicons are always |
731 // as it is guaranteed to be unique. Sync favicons are always | 739 // gfx::kFaviconSize in width and height. Store the favicon into history |
732 // gfx::kFaviconSize in width and height. Store the favicon into history as | 740 // as such. |
733 // such. | |
734 gfx::Size pixel_size(gfx::kFaviconSize, gfx::kFaviconSize); | 741 gfx::Size pixel_size(gfx::kFaviconSize, gfx::kFaviconSize); |
735 favicon_service->MergeFavicon(bookmark_node->url(), | 742 favicon_service->MergeFavicon(bookmark_node->url(), |
736 bookmark_node->url(), | 743 icon_url, |
737 history::FAVICON, | 744 history::FAVICON, |
738 bitmap_data, | 745 bitmap_data, |
739 pixel_size); | 746 pixel_size); |
740 } | 747 } |
741 | 748 |
742 // static | 749 // static |
743 void BookmarkChangeProcessor::SetSyncNodeFavicon( | 750 void BookmarkChangeProcessor::SetSyncNodeFavicon( |
744 const BookmarkNode* bookmark_node, | 751 const BookmarkNode* bookmark_node, |
745 BookmarkModel* model, | 752 BookmarkModel* model, |
746 syncer::WriteNode* sync_node) { | 753 syncer::WriteNode* sync_node) { |
747 std::vector<unsigned char> favicon_bytes; | 754 std::vector<unsigned char> favicon_bytes; |
748 EncodeFavicon(bookmark_node, model, &favicon_bytes); | 755 EncodeFavicon(bookmark_node, model, &favicon_bytes); |
749 if (!favicon_bytes.empty()) { | 756 if (!favicon_bytes.empty()) { |
750 sync_pb::BookmarkSpecifics updated_specifics( | 757 sync_pb::BookmarkSpecifics updated_specifics( |
751 sync_node->GetBookmarkSpecifics()); | 758 sync_node->GetBookmarkSpecifics()); |
752 updated_specifics.set_favicon(&favicon_bytes[0], favicon_bytes.size()); | 759 updated_specifics.set_favicon(&favicon_bytes[0], favicon_bytes.size()); |
| 760 updated_specifics.set_icon_url(bookmark_node->icon_url().spec()); |
753 sync_node->SetBookmarkSpecifics(updated_specifics); | 761 sync_node->SetBookmarkSpecifics(updated_specifics); |
754 } | 762 } |
755 } | 763 } |
756 | 764 |
757 } // namespace browser_sync | 765 } // namespace browser_sync |
OLD | NEW |