OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/favicon_cache.h" | 5 #include "chrome/browser/sync/glue/favicon_cache.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "chrome/browser/favicon/favicon_service.h" | 9 #include "chrome/browser/favicon/favicon_service.h" |
10 #include "chrome/browser/favicon/favicon_service_factory.h" | 10 #include "chrome/browser/favicon/favicon_service_factory.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 bitmap_result.bitmap_data = temp_string; | 131 bitmap_result.bitmap_data = temp_string; |
132 bitmap_result.pixel_size.set_height(favicon_data.height()); | 132 bitmap_result.pixel_size.set_height(favicon_data.height()); |
133 bitmap_result.pixel_size.set_width(favicon_data.width()); | 133 bitmap_result.pixel_size.set_width(favicon_data.width()); |
134 return bitmap_result; | 134 return bitmap_result; |
135 } | 135 } |
136 | 136 |
137 // Convert a FaviconBitmapResult into protobuf image data. | 137 // Convert a FaviconBitmapResult into protobuf image data. |
138 void FillSpecificsWithImageData( | 138 void FillSpecificsWithImageData( |
139 const chrome::FaviconBitmapResult& bitmap_result, | 139 const chrome::FaviconBitmapResult& bitmap_result, |
140 sync_pb::FaviconData* favicon_data) { | 140 sync_pb::FaviconData* favicon_data) { |
141 if (!bitmap_result.bitmap_data) | 141 if (!bitmap_result.bitmap_data.get()) |
142 return; | 142 return; |
143 favicon_data->set_height(bitmap_result.pixel_size.height()); | 143 favicon_data->set_height(bitmap_result.pixel_size.height()); |
144 favicon_data->set_width(bitmap_result.pixel_size.width()); | 144 favicon_data->set_width(bitmap_result.pixel_size.width()); |
145 favicon_data->set_favicon(bitmap_result.bitmap_data->front(), | 145 favicon_data->set_favicon(bitmap_result.bitmap_data->front(), |
146 bitmap_result.bitmap_data->size()); | 146 bitmap_result.bitmap_data->size()); |
147 } | 147 } |
148 | 148 |
149 // Build a FaviconImageSpecifics from a SyncedFaviconInfo. | 149 // Build a FaviconImageSpecifics from a SyncedFaviconInfo. |
150 void BuildImageSpecifics( | 150 void BuildImageSpecifics( |
151 const SyncedFaviconInfo* favicon_info, | 151 const SyncedFaviconInfo* favicon_info, |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 if (!favicon_url.is_valid()) | 493 if (!favicon_url.is_valid()) |
494 return false; | 494 return false; |
495 FaviconMap::const_iterator iter = synced_favicons_.find(favicon_url); | 495 FaviconMap::const_iterator iter = synced_favicons_.find(favicon_url); |
496 | 496 |
497 UMA_HISTOGRAM_BOOLEAN("Sync.FaviconCacheLookupSucceeded", | 497 UMA_HISTOGRAM_BOOLEAN("Sync.FaviconCacheLookupSucceeded", |
498 iter != synced_favicons_.end()); | 498 iter != synced_favicons_.end()); |
499 if (iter == synced_favicons_.end()) | 499 if (iter == synced_favicons_.end()) |
500 return false; | 500 return false; |
501 | 501 |
502 // TODO(zea): support getting other resolutions. | 502 // TODO(zea): support getting other resolutions. |
503 if (!iter->second->bitmap_data[SIZE_16].bitmap_data) | 503 if (!iter->second->bitmap_data[SIZE_16].bitmap_data.get()) |
504 return false; | 504 return false; |
505 | 505 |
506 *favicon_png = iter->second->bitmap_data[SIZE_16].bitmap_data; | 506 *favicon_png = iter->second->bitmap_data[SIZE_16].bitmap_data; |
507 return true; | 507 return true; |
508 } | 508 } |
509 | 509 |
510 bool FaviconCache::GetSyncedFaviconForPageURL( | 510 bool FaviconCache::GetSyncedFaviconForPageURL( |
511 const GURL& page_url, | 511 const GURL& page_url, |
512 scoped_refptr<base::RefCountedMemory>* favicon_png) const { | 512 scoped_refptr<base::RefCountedMemory>* favicon_png) const { |
513 if (!page_url.is_valid()) | 513 if (!page_url.is_valid()) |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 sync_favicon.GetSpecifics().favicon_image(); | 837 sync_favicon.GetSpecifics().favicon_image(); |
838 FaviconMap::const_iterator iter = synced_favicons_.find(favicon_url); | 838 FaviconMap::const_iterator iter = synced_favicons_.find(favicon_url); |
839 DCHECK(iter != synced_favicons_.end()); | 839 DCHECK(iter != synced_favicons_.end()); |
840 SyncedFaviconInfo* favicon_info = iter->second.get(); | 840 SyncedFaviconInfo* favicon_info = iter->second.get(); |
841 | 841 |
842 // Remote image data always clobbers local image data. | 842 // Remote image data always clobbers local image data. |
843 bool needs_update = false; | 843 bool needs_update = false; |
844 if (image_specifics.has_favicon_web()) { | 844 if (image_specifics.has_favicon_web()) { |
845 favicon_info->bitmap_data[SIZE_16] = GetImageDataFromSpecifics( | 845 favicon_info->bitmap_data[SIZE_16] = GetImageDataFromSpecifics( |
846 image_specifics.favicon_web()); | 846 image_specifics.favicon_web()); |
847 } else if (favicon_info->bitmap_data[SIZE_16].bitmap_data) { | 847 } else if (favicon_info->bitmap_data[SIZE_16].bitmap_data.get()) { |
848 needs_update = true; | 848 needs_update = true; |
849 } | 849 } |
850 if (image_specifics.has_favicon_web_32()) { | 850 if (image_specifics.has_favicon_web_32()) { |
851 favicon_info->bitmap_data[SIZE_32] = GetImageDataFromSpecifics( | 851 favicon_info->bitmap_data[SIZE_32] = GetImageDataFromSpecifics( |
852 image_specifics.favicon_web_32()); | 852 image_specifics.favicon_web_32()); |
853 } else if (favicon_info->bitmap_data[SIZE_32].bitmap_data) { | 853 } else if (favicon_info->bitmap_data[SIZE_32].bitmap_data.get()) { |
854 needs_update = true; | 854 needs_update = true; |
855 } | 855 } |
856 if (image_specifics.has_favicon_touch_64()) { | 856 if (image_specifics.has_favicon_touch_64()) { |
857 favicon_info->bitmap_data[SIZE_64] = GetImageDataFromSpecifics( | 857 favicon_info->bitmap_data[SIZE_64] = GetImageDataFromSpecifics( |
858 image_specifics.favicon_touch_64()); | 858 image_specifics.favicon_touch_64()); |
859 } else if (favicon_info->bitmap_data[SIZE_64].bitmap_data) { | 859 } else if (favicon_info->bitmap_data[SIZE_64].bitmap_data.get()) { |
860 needs_update = true; | 860 needs_update = true; |
861 } | 861 } |
862 | 862 |
863 if (needs_update) | 863 if (needs_update) |
864 BuildImageSpecifics(favicon_info, new_specifics.mutable_favicon_image()); | 864 BuildImageSpecifics(favicon_info, new_specifics.mutable_favicon_image()); |
865 } else { | 865 } else { |
866 sync_pb::FaviconTrackingSpecifics tracking_specifics = | 866 sync_pb::FaviconTrackingSpecifics tracking_specifics = |
867 sync_favicon.GetSpecifics().favicon_tracking(); | 867 sync_favicon.GetSpecifics().favicon_tracking(); |
868 FaviconMap::const_iterator iter = synced_favicons_.find(favicon_url); | 868 FaviconMap::const_iterator iter = synced_favicons_.find(favicon_url); |
869 DCHECK(iter != synced_favicons_.end()); | 869 DCHECK(iter != synced_favicons_.end()); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 | 1020 |
1021 size_t FaviconCache::NumFaviconsForTest() const { | 1021 size_t FaviconCache::NumFaviconsForTest() const { |
1022 return synced_favicons_.size(); | 1022 return synced_favicons_.size(); |
1023 } | 1023 } |
1024 | 1024 |
1025 size_t FaviconCache::NumTasksForTest() const { | 1025 size_t FaviconCache::NumTasksForTest() const { |
1026 return page_task_map_.size(); | 1026 return page_task_map_.size(); |
1027 } | 1027 } |
1028 | 1028 |
1029 } // namespace browser_sync | 1029 } // namespace browser_sync |
OLD | NEW |