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" |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/bookmarks/bookmark_model.h" | 14 #include "chrome/browser/bookmarks/bookmark_model.h" |
15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
16 #include "chrome/browser/bookmarks/bookmark_utils.h" | 16 #include "chrome/browser/bookmarks/bookmark_utils.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_factory.h" | 19 #include "chrome/browser/history/history_service_factory.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/sync/profile_sync_service.h" | 21 #include "chrome/browser/sync/profile_sync_service.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 #include "sync/internal_api/public/change_record.h" | 23 #include "sync/internal_api/public/change_record.h" |
24 #include "sync/internal_api/public/read_node.h" | 24 #include "sync/internal_api/public/read_node.h" |
25 #include "sync/internal_api/public/write_node.h" | 25 #include "sync/internal_api/public/write_node.h" |
26 #include "sync/internal_api/public/write_transaction.h" | 26 #include "sync/internal_api/public/write_transaction.h" |
27 #include "sync/syncable/entry.h" // TODO(tim): Investigating bug 121587. | 27 #include "sync/syncable/entry.h" // TODO(tim): Investigating bug 121587. |
28 #include "ui/gfx/favicon_size.h" | |
28 #include "ui/gfx/image/image_util.h" | 29 #include "ui/gfx/image/image_util.h" |
29 | 30 |
30 using content::BrowserThread; | 31 using content::BrowserThread; |
31 | 32 |
32 namespace browser_sync { | 33 namespace browser_sync { |
33 | 34 |
34 static const char kMobileBookmarksTag[] = "synced_bookmarks"; | 35 static const char kMobileBookmarksTag[] = "synced_bookmarks"; |
35 | 36 |
36 BookmarkChangeProcessor::BookmarkChangeProcessor( | 37 BookmarkChangeProcessor::BookmarkChangeProcessor( |
37 BookmarkModelAssociator* model_associator, | 38 BookmarkModelAssociator* model_associator, |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
628 const BookmarkNode* bookmark_node, | 629 const BookmarkNode* bookmark_node, |
629 Profile* profile, | 630 Profile* profile, |
630 const std::vector<unsigned char>& icon_bytes_vector) { | 631 const std::vector<unsigned char>& icon_bytes_vector) { |
631 // Registering a favicon requires that we provide a source URL, but we | 632 // Registering a favicon requires that we provide a source URL, but we |
632 // don't know where these came from. Currently we just use the | 633 // don't know where these came from. Currently we just use the |
633 // destination URL, which is not correct, but since the favicon URL | 634 // destination URL, which is not correct, but since the favicon URL |
634 // is used as a key in the history's thumbnail DB, this gives us a value | 635 // is used as a key in the history's thumbnail DB, this gives us a value |
635 // which does not collide with others. | 636 // which does not collide with others. |
636 GURL fake_icon_url = bookmark_node->url(); | 637 GURL fake_icon_url = bookmark_node->url(); |
637 | 638 |
639 // As the favicon which is pushed to the sync service from BookmarkModel is | |
640 // gfx::kFaviconSize in width and height, use gfx::kFaviconSize as a guess of | |
Nicolas Zea
2012/09/12 23:13:20
I think it's simpler to just say
"Sync favicons ar
| |
641 // the size of the bitmap which is recieved from sync. | |
642 gfx::Size pixel_size(gfx::kFaviconSize, gfx::kFaviconSize); | |
643 | |
638 HistoryService* history = | 644 HistoryService* history = |
639 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); | 645 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); |
640 FaviconService* favicon_service = | 646 FaviconService* favicon_service = |
641 FaviconServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); | 647 FaviconServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); |
642 | 648 |
643 history->AddPageNoVisitForBookmark(bookmark_node->url(), | 649 history->AddPageNoVisitForBookmark(bookmark_node->url(), |
644 bookmark_node->GetTitle()); | 650 bookmark_node->GetTitle()); |
645 favicon_service->SetFavicon(bookmark_node->url(), | 651 // The client may have cached the favicon at 2x. Use MergeFavicon() as not to |
646 fake_icon_url, | 652 // overwrite the cached 2x favicon bitmap. |
647 icon_bytes_vector, | 653 scoped_refptr<base::RefCountedMemory> bitmap_data( |
648 history::FAVICON); | 654 new base::RefCountedBytes(icon_bytes_vector)); |
655 favicon_service->MergeFavicon(bookmark_node->url(), | |
656 fake_icon_url, | |
657 history::FAVICON, | |
658 bitmap_data, | |
659 pixel_size); | |
649 } | 660 } |
650 | 661 |
651 // static | 662 // static |
652 void BookmarkChangeProcessor::SetSyncNodeFavicon( | 663 void BookmarkChangeProcessor::SetSyncNodeFavicon( |
653 const BookmarkNode* bookmark_node, | 664 const BookmarkNode* bookmark_node, |
654 BookmarkModel* model, | 665 BookmarkModel* model, |
655 syncer::WriteNode* sync_node) { | 666 syncer::WriteNode* sync_node) { |
656 std::vector<unsigned char> favicon_bytes; | 667 std::vector<unsigned char> favicon_bytes; |
657 EncodeFavicon(bookmark_node, model, &favicon_bytes); | 668 EncodeFavicon(bookmark_node, model, &favicon_bytes); |
658 if (!favicon_bytes.empty()) | 669 if (!favicon_bytes.empty()) |
659 sync_node->SetFaviconBytes(favicon_bytes); | 670 sync_node->SetFaviconBytes(favicon_bytes); |
660 } | 671 } |
661 | 672 |
662 } // namespace browser_sync | 673 } // namespace browser_sync |
OLD | NEW |