Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/favicon/core/large_icon_service.h" | 5 #include "components/favicon/core/large_icon_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 7 #include <memory> | 8 #include <memory> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/feature_list.h" | |
| 10 #include "base/location.h" | 12 #include "base/location.h" |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/macros.h" | 14 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/strings/stringprintf.h" | |
| 14 #include "base/task_runner.h" | 17 #include "base/task_runner.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
| 19 #include "components/data_use_measurement/core/data_use_user_data.h" | |
| 16 #include "components/favicon/core/favicon_service.h" | 20 #include "components/favicon/core/favicon_service.h" |
| 21 #include "components/favicon/core/features.h" | |
| 17 #include "components/favicon_base/fallback_icon_style.h" | 22 #include "components/favicon_base/fallback_icon_style.h" |
| 18 #include "components/favicon_base/favicon_types.h" | 23 #include "components/favicon_base/favicon_types.h" |
| 24 #include "components/favicon_base/favicon_util.h" | |
| 25 #include "components/image_fetcher/image_fetcher.h" | |
| 19 #include "skia/ext/image_operations.h" | 26 #include "skia/ext/image_operations.h" |
| 20 #include "ui/gfx/codec/png_codec.h" | 27 #include "ui/gfx/codec/png_codec.h" |
| 21 #include "ui/gfx/geometry/size.h" | 28 #include "ui/gfx/geometry/size.h" |
| 22 | 29 |
| 30 using image_fetcher::ImageFetcher; | |
| 31 | |
| 32 namespace favicon { | |
| 33 | |
| 23 namespace { | 34 namespace { |
| 24 | 35 |
| 36 const double kGoogleServerDefaultDesiredSize = 128; | |
| 37 const double kGoogleServerMinSizeToDesiredSizeFactor = 2.0; | |
| 38 const double kGoogleServerDesiredSizeToMaxSizeFactor = 2.0; | |
| 39 | |
| 40 const char kGoogleServer1RequestFormat[] = | |
| 41 "https://s2.googleusercontent.com/s2/" | |
| 42 "favicons?domain=%s&src=chrome_large_icons&sz=%d&alt=404"; | |
| 43 const int kGoogleServer1SupportedSizes[] = {16, 24, 32, 48, 64}; | |
| 44 | |
| 45 // Type APPLE_TOUCH includes TOUCH_ICONs as well as FAVICONs as fallback. | |
| 46 const char kGoogleServer2RequestFormat[] = | |
| 47 "https://t0.gstatic.com/" | |
| 48 "faviconV2?url=%s&type=APPLE_TOUCH&size=%d&min_size=%d&max_size=%d"; | |
|
pkotwicz
2017/02/10 20:44:34
Doesn't chrome want to prioritize FAVICONS over AP
jkrcal
2017/02/13 14:39:46
The code for FaviconService also prioritizes APPLE
| |
| 49 | |
| 50 int GetClosestSizeSupportedByGoogleServer1(int arbitrary_size) { | |
| 51 // Take the smallest size larger than |arbitrary_size|. | |
| 52 for (int size : kGoogleServer1SupportedSizes) { | |
| 53 if (size >= arbitrary_size) | |
| 54 return size; | |
| 55 } | |
| 56 // Or at least the largest available size. | |
| 57 return kGoogleServer1SupportedSizes[arraysize(kGoogleServer1SupportedSizes) - | |
| 58 1]; | |
| 59 } | |
| 60 | |
| 25 // Processes the bitmap data returned from the FaviconService as part of a | 61 // Processes the bitmap data returned from the FaviconService as part of a |
| 26 // LargeIconService request. | 62 // LargeIconService request. |
| 27 class LargeIconWorker : public base::RefCountedThreadSafe<LargeIconWorker> { | 63 class LargeIconWorker : public base::RefCountedThreadSafe<LargeIconWorker> { |
| 28 public: | 64 public: |
| 29 LargeIconWorker(int min_source_size_in_pixel, | 65 LargeIconWorker(const GURL& page_url, |
| 66 int min_source_size_in_pixel, | |
| 30 int desired_size_in_pixel, | 67 int desired_size_in_pixel, |
| 31 favicon_base::LargeIconCallback callback, | 68 favicon_base::LargeIconCallback callback, |
| 32 scoped_refptr<base::TaskRunner> background_task_runner, | 69 scoped_refptr<base::TaskRunner> background_task_runner, |
| 33 base::CancelableTaskTracker* tracker); | 70 base::CancelableTaskTracker* tracker, |
| 71 FaviconService* favicon_service, | |
| 72 ImageFetcher* image_fetcher); | |
| 34 | 73 |
| 35 // Must run on the owner (UI) thread in production. | 74 // Must run on the owner (UI) thread in production. |
| 36 // Intermediate callback for GetLargeIconOrFallbackStyle(). Invokes | 75 // Intermediate callback for GetLargeIconOrFallbackStyle(). Invokes |
| 37 // ProcessIconOnBackgroundThread() so we do not perform complex image | 76 // ProcessIconOnBackgroundThread() so we do not perform complex image |
| 38 // operations on the UI thread. | 77 // operations on the UI thread. |
| 39 void OnIconLookupComplete( | 78 void OnCachedIconLookupComplete( |
| 40 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 79 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
| 41 | 80 |
| 42 private: | 81 private: |
| 43 friend class base::RefCountedThreadSafe<LargeIconWorker>; | 82 friend class base::RefCountedThreadSafe<LargeIconWorker>; |
| 44 | 83 |
| 45 ~LargeIconWorker(); | 84 ~LargeIconWorker(); |
| 46 | 85 |
| 47 // Must run on a background thread in production. | 86 // Must run on a background thread in production. |
| 48 // Tries to resize |bitmap_result_| and pass the output to |callback_|. If | 87 // Tries to resize |bitmap_result_| and pass the output to |callback_|. If |
| 49 // that does not work, computes the icon fallback style and uses it to | 88 // that does not work, computes the icon fallback style and uses it to |
| 50 // invoke |callback_|. This must be run on a background thread because image | 89 // invoke |callback_|. This must be run on a background thread because image |
| 51 // resizing and dominant color extraction can be expensive. | 90 // resizing and dominant color extraction can be expensive. |
| 52 void ProcessIconOnBackgroundThread(); | 91 void ProcessCachedIconOnBackgroundThread(); |
| 53 | 92 |
| 54 // Must run on a background thread in production. | 93 // Must run on a background thread in production. |
| 55 // If |bitmap_result_| is square and large enough (>= |min_source_in_pixel_|), | 94 // If |bitmap_result_| is square and large enough (>= |min_source_in_pixel_|), |
| 56 // resizes it to |desired_size_in_pixel_| (but if |desired_size_in_pixel_| is | 95 // resizes it to |desired_size_in_pixel_| (but if |desired_size_in_pixel_| is |
| 57 // 0 then don't resize). If successful, stores the resulting bitmap data | 96 // 0 then don't resize). If successful, stores the resulting bitmap data |
| 58 // into |resized_bitmap_result| and returns true. | 97 // into |resized_bitmap_result| and returns true. |
| 59 bool ResizeLargeIconOnBackgroundThreadIfValid( | 98 bool ResizeCachedIconOnBackgroundThreadIfValid( |
| 60 favicon_base::FaviconRawBitmapResult* resized_bitmap_result); | 99 favicon_base::FaviconRawBitmapResult* resized_bitmap_result); |
| 61 | 100 |
| 62 // Must run on the owner (UI) thread in production. | 101 // Must run on the owner (UI) thread in production. |
| 63 // Invoked when ProcessIconOnBackgroundThread() is done. | 102 // Invoked when ProcessIconOnBackgroundThread() is done. |
| 64 void OnIconProcessingComplete(); | 103 void OnCachedIconProcessingComplete(); |
| 65 | 104 |
| 105 // Create the GET URL that requests the desired favicon from a Google favicon | |
| 106 // server (version 1 / version 2). | |
| 107 GURL GetIconUrlForGoogleServer1() const; | |
| 108 GURL GetIconUrlForGoogleServer2() const; | |
| 109 | |
| 110 // Fetches an icon for the given |icon_url| and stores it in the favicon DB. | |
| 111 void FetchIconFromGoogleServer(const GURL& icon_url); | |
| 112 void OnFetchIconFromGoogleServerComplete(const std::string& icon_url, | |
| 113 const gfx::Image& image); | |
| 114 | |
| 115 // Must run on a background thread in production. | |
| 116 void ProcessAndStoreIconFromGoogleServerOnBackgroundThread( | |
| 117 const GURL& icon_url, | |
| 118 const gfx::Image& image); | |
| 119 | |
| 120 GURL page_url_; | |
| 66 int min_source_size_in_pixel_; | 121 int min_source_size_in_pixel_; |
| 67 int desired_size_in_pixel_; | 122 int desired_size_in_pixel_; |
| 68 favicon_base::LargeIconCallback callback_; | 123 favicon_base::LargeIconCallback callback_; |
| 69 scoped_refptr<base::TaskRunner> background_task_runner_; | 124 scoped_refptr<base::TaskRunner> background_task_runner_; |
| 70 base::CancelableTaskTracker* tracker_; | 125 base::CancelableTaskTracker* tracker_; |
| 126 FaviconService* favicon_service_; | |
| 127 ImageFetcher* image_fetcher_; | |
| 128 | |
| 129 bool icon_found_; | |
| 130 bool large_icon_found_; | |
| 71 favicon_base::FaviconRawBitmapResult bitmap_result_; | 131 favicon_base::FaviconRawBitmapResult bitmap_result_; |
| 72 std::unique_ptr<favicon_base::LargeIconResult> result_; | 132 std::unique_ptr<favicon_base::LargeIconResult> result_; |
| 73 | 133 |
| 74 DISALLOW_COPY_AND_ASSIGN(LargeIconWorker); | 134 DISALLOW_COPY_AND_ASSIGN(LargeIconWorker); |
| 75 }; | 135 }; |
| 76 | 136 |
| 77 LargeIconWorker::LargeIconWorker( | 137 LargeIconWorker::LargeIconWorker( |
| 138 const GURL& page_url, | |
| 78 int min_source_size_in_pixel, | 139 int min_source_size_in_pixel, |
| 79 int desired_size_in_pixel, | 140 int desired_size_in_pixel, |
| 80 favicon_base::LargeIconCallback callback, | 141 favicon_base::LargeIconCallback callback, |
| 81 scoped_refptr<base::TaskRunner> background_task_runner, | 142 scoped_refptr<base::TaskRunner> background_task_runner, |
| 82 base::CancelableTaskTracker* tracker) | 143 base::CancelableTaskTracker* tracker, |
| 83 : min_source_size_in_pixel_(min_source_size_in_pixel), | 144 FaviconService* favicon_service, |
| 145 ImageFetcher* image_fetcher) | |
| 146 : page_url_(page_url), | |
| 147 min_source_size_in_pixel_(min_source_size_in_pixel), | |
| 84 desired_size_in_pixel_(desired_size_in_pixel), | 148 desired_size_in_pixel_(desired_size_in_pixel), |
| 85 callback_(callback), | 149 callback_(callback), |
| 86 background_task_runner_(background_task_runner), | 150 background_task_runner_(background_task_runner), |
| 87 tracker_(tracker) { | 151 tracker_(tracker), |
| 88 } | 152 favicon_service_(favicon_service), |
| 153 image_fetcher_(image_fetcher), | |
| 154 icon_found_(false), | |
| 155 large_icon_found_(false) {} | |
| 89 | 156 |
| 90 LargeIconWorker::~LargeIconWorker() { | 157 LargeIconWorker::~LargeIconWorker() { |
| 91 } | 158 } |
| 92 | 159 |
| 93 void LargeIconWorker::OnIconLookupComplete( | 160 void LargeIconWorker::OnCachedIconLookupComplete( |
| 94 const favicon_base::FaviconRawBitmapResult& bitmap_result) { | 161 const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
| 95 bitmap_result_ = bitmap_result; | 162 bitmap_result_ = bitmap_result; |
| 163 icon_found_ = bitmap_result_.is_valid(); | |
| 96 tracker_->PostTaskAndReply( | 164 tracker_->PostTaskAndReply( |
| 97 background_task_runner_.get(), FROM_HERE, | 165 background_task_runner_.get(), FROM_HERE, |
| 98 base::Bind(&LargeIconWorker::ProcessIconOnBackgroundThread, this), | 166 base::Bind(&LargeIconWorker::ProcessCachedIconOnBackgroundThread, this), |
| 99 base::Bind(&LargeIconWorker::OnIconProcessingComplete, this)); | 167 base::Bind(&LargeIconWorker::OnCachedIconProcessingComplete, this)); |
| 100 } | 168 } |
| 101 | 169 |
| 102 void LargeIconWorker::ProcessIconOnBackgroundThread() { | 170 void LargeIconWorker::ProcessCachedIconOnBackgroundThread() { |
| 103 favicon_base::FaviconRawBitmapResult resized_bitmap_result; | 171 favicon_base::FaviconRawBitmapResult resized_bitmap_result; |
| 104 if (ResizeLargeIconOnBackgroundThreadIfValid(&resized_bitmap_result)) { | 172 if (ResizeCachedIconOnBackgroundThreadIfValid(&resized_bitmap_result)) { |
| 105 result_.reset( | 173 result_.reset( |
| 106 new favicon_base::LargeIconResult(resized_bitmap_result)); | 174 new favicon_base::LargeIconResult(resized_bitmap_result)); |
| 175 large_icon_found_ = true; | |
| 107 } else { | 176 } else { |
| 108 // Failed to resize |bitmap_result_|, so compute fallback icon style. | 177 // Failed to resize |bitmap_result_|, so compute fallback icon style. |
| 109 std::unique_ptr<favicon_base::FallbackIconStyle> fallback_icon_style( | 178 std::unique_ptr<favicon_base::FallbackIconStyle> fallback_icon_style( |
| 110 new favicon_base::FallbackIconStyle()); | 179 new favicon_base::FallbackIconStyle()); |
| 111 if (bitmap_result_.is_valid()) { | 180 if (bitmap_result_.is_valid()) { |
| 112 favicon_base::SetDominantColorAsBackground( | 181 favicon_base::SetDominantColorAsBackground( |
| 113 bitmap_result_.bitmap_data, fallback_icon_style.get()); | 182 bitmap_result_.bitmap_data, fallback_icon_style.get()); |
| 114 } | 183 } |
| 115 result_.reset( | 184 result_.reset( |
| 116 new favicon_base::LargeIconResult(fallback_icon_style.release())); | 185 new favicon_base::LargeIconResult(std::move(fallback_icon_style))); |
| 117 } | 186 } |
| 118 } | 187 } |
| 119 | 188 |
| 120 bool LargeIconWorker::ResizeLargeIconOnBackgroundThreadIfValid( | 189 bool LargeIconWorker::ResizeCachedIconOnBackgroundThreadIfValid( |
| 121 favicon_base::FaviconRawBitmapResult* resized_bitmap_result) { | 190 favicon_base::FaviconRawBitmapResult* resized_bitmap_result) { |
| 122 // Require bitmap to be valid and square. | 191 // Require bitmap to be valid and square. |
| 123 if (!bitmap_result_.is_valid() || | 192 if (!bitmap_result_.is_valid() || |
| 124 bitmap_result_.pixel_size.width() != bitmap_result_.pixel_size.height()) | 193 bitmap_result_.pixel_size.width() != bitmap_result_.pixel_size.height()) |
| 125 return false; | 194 return false; |
| 126 | 195 |
| 127 // Require bitmap to be large enough. It's square, so just check width. | 196 // Require bitmap to be large enough. It's square, so just check width. |
| 128 if (bitmap_result_.pixel_size.width() < min_source_size_in_pixel_) | 197 if (bitmap_result_.pixel_size.width() < min_source_size_in_pixel_) |
| 129 return false; | 198 return false; |
| 130 | 199 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 149 if (!gfx::PNGCodec::EncodeBGRASkBitmap(resized_bitmap, false, &bitmap_data)) | 218 if (!gfx::PNGCodec::EncodeBGRASkBitmap(resized_bitmap, false, &bitmap_data)) |
| 150 return false; | 219 return false; |
| 151 | 220 |
| 152 resized_bitmap_result->pixel_size = | 221 resized_bitmap_result->pixel_size = |
| 153 gfx::Size(desired_size_in_pixel_, desired_size_in_pixel_); | 222 gfx::Size(desired_size_in_pixel_, desired_size_in_pixel_); |
| 154 resized_bitmap_result->bitmap_data = | 223 resized_bitmap_result->bitmap_data = |
| 155 base::RefCountedBytes::TakeVector(&bitmap_data); | 224 base::RefCountedBytes::TakeVector(&bitmap_data); |
| 156 return true; | 225 return true; |
| 157 } | 226 } |
| 158 | 227 |
| 159 void LargeIconWorker::OnIconProcessingComplete() { | 228 void LargeIconWorker::OnCachedIconProcessingComplete() { |
| 160 callback_.Run(*result_); | 229 callback_.Run(*result_); |
|
pkotwicz
2017/02/10 20:44:34
If we go and fetch results from the Google server
jkrcal
2017/02/13 14:39:46
This is conceptually a UX question to me.
The wa
pkotwicz
2017/02/13 21:33:31
Given how you are planning on using this, I'd rath
jkrcal
2017/02/27 17:31:19
Okay, the new functionality now does not get trigg
| |
| 230 | |
| 231 // If there is a large icon in the cache, we do not need to download anything. | |
| 232 if (large_icon_found_) | |
| 233 return; | |
| 234 // No fetcher available (e.g. in unittests), we cannot download anything. | |
| 235 if (!image_fetcher_) | |
| 236 return; | |
| 237 | |
| 238 // No favicon in the cache. Download it from the server. | |
| 239 | |
| 240 if (desired_size_in_pixel_ == 0) { | |
| 241 // We need to fix a concrete desired size if none is provided. | |
| 242 if (min_source_size_in_pixel_ > 0) { | |
| 243 desired_size_in_pixel_ = | |
| 244 min_source_size_in_pixel_ * kGoogleServerMinSizeToDesiredSizeFactor; | |
| 245 } else { | |
| 246 desired_size_in_pixel_ = kGoogleServerDefaultDesiredSize; | |
| 247 } | |
| 248 } | |
| 249 | |
| 250 if (base::FeatureList::IsEnabled(kFaviconFetchLargeIconFromGoogleServer2)) { | |
| 251 FetchIconFromGoogleServer(GetIconUrlForGoogleServer2()); | |
| 252 } else if (min_source_size_in_pixel_ <= 16 && | |
| 253 base::FeatureList::IsEnabled( | |
| 254 kFaviconFetchLargeIconFromGoogleServer1)) { | |
| 255 FetchIconFromGoogleServer(GetIconUrlForGoogleServer1()); | |
| 256 } | |
| 257 } | |
| 258 | |
| 259 GURL LargeIconWorker::GetIconUrlForGoogleServer1() const { | |
| 260 int supported_size = | |
| 261 GetClosestSizeSupportedByGoogleServer1(desired_size_in_pixel_); | |
| 262 return GURL(base::StringPrintf(kGoogleServer1RequestFormat, | |
| 263 page_url_.spec().c_str(), supported_size)); | |
| 264 } | |
| 265 | |
| 266 GURL LargeIconWorker::GetIconUrlForGoogleServer2() const { | |
|
pkotwicz
2017/02/10 20:44:34
Different bits of UI want differently sized favico
jkrcal
2017/02/13 14:39:46
Good point! I've fixed min, max, and desired sizes
pkotwicz
2017/02/13 21:33:32
Thank you for pointing this out. I didn't see the
| |
| 267 int max_source_size_in_pixel = | |
| 268 desired_size_in_pixel_ * kGoogleServerDesiredSizeToMaxSizeFactor; | |
| 269 return GURL( | |
| 270 base::StringPrintf(kGoogleServer2RequestFormat, page_url_.spec().c_str(), | |
| 271 desired_size_in_pixel_, min_source_size_in_pixel_, | |
| 272 max_source_size_in_pixel)); | |
| 273 } | |
| 274 | |
| 275 void LargeIconWorker::FetchIconFromGoogleServer(const GURL& icon_url) { | |
| 276 // Do not retry if there is a previous cache miss recorded for |icon_url|. | |
| 277 if (favicon_service_->WasUnableToDownloadFavicon(icon_url)) | |
| 278 return; | |
| 279 | |
| 280 // TODO(jkrcal): Create a large icon service tag. | |
| 281 image_fetcher_->SetDataUseServiceName( | |
| 282 data_use_measurement::DataUseUserData::NOT_TAGGED); | |
| 283 image_fetcher_->StartOrQueueNetworkRequest( | |
| 284 icon_url.spec(), icon_url, | |
| 285 base::Bind(&LargeIconWorker::OnFetchIconFromGoogleServerComplete, | |
| 286 base::Unretained(this))); | |
|
pkotwicz
2017/02/10 20:44:34
Don't use base::Unretained(). LargeIconWorker is r
jkrcal
2017/02/13 14:39:46
Done.
| |
| 287 } | |
| 288 | |
| 289 void LargeIconWorker::OnFetchIconFromGoogleServerComplete( | |
| 290 const std::string& icon_url, | |
| 291 const gfx::Image& image) { | |
| 292 if (image.IsEmpty()) { | |
| 293 favicon_service_->UnableToDownloadFavicon(GURL(icon_url)); | |
| 294 return; | |
| 295 } | |
| 296 | |
| 297 tracker_->PostTask( | |
| 298 background_task_runner_.get(), FROM_HERE, | |
| 299 base::Bind(&LargeIconWorker:: | |
| 300 ProcessAndStoreIconFromGoogleServerOnBackgroundThread, | |
| 301 base::Unretained(this), GURL(icon_url), image)); | |
|
pkotwicz
2017/02/10 20:44:34
Don't use base::Unretained(). LargeIconWorker is r
jkrcal
2017/02/13 14:39:46
Done.
| |
| 302 } | |
| 303 | |
| 304 void LargeIconWorker::ProcessAndStoreIconFromGoogleServerOnBackgroundThread( | |
| 305 const GURL& icon_url, | |
| 306 const gfx::Image& image) { | |
| 307 SkBitmap icon = image.AsBitmap(); | |
|
pkotwicz
2017/02/10 20:44:34
I think that it would be better to store the non-r
jkrcal
2017/02/13 14:39:45
Done.
| |
| 308 SkBitmap resized_icon = favicon_base::ResizeBitmapByDownsamplingIfPossible( | |
| 309 {icon}, desired_size_in_pixel_); | |
| 310 gfx::Image resized_image = gfx::Image::CreateFrom1xBitmap(resized_icon); | |
| 311 favicon_base::SetFaviconColorSpace(&resized_image); | |
| 312 | |
| 313 // We must make sure we do not overwrite the FAVICON if there is any icon in | |
| 314 // the cache (due to sync). | |
| 315 favicon_base::IconType store_as_type = | |
| 316 icon_found_ ? favicon_base::IconType::TOUCH_ICON | |
| 317 : favicon_base::IconType::FAVICON; | |
| 318 | |
| 319 favicon_service_->SetFavicons(page_url_, icon_url, store_as_type, | |
| 320 resized_image); | |
| 321 // Mark the icons as out-of-date so that they are refetched when we visit the | |
| 322 // original page any time in the future. | |
| 323 favicon_service_->SetFaviconOutOfDateForPage(page_url_); | |
| 161 } | 324 } |
| 162 | 325 |
| 163 } // namespace | 326 } // namespace |
| 164 | 327 |
| 165 namespace favicon { | |
| 166 | |
| 167 LargeIconService::LargeIconService( | 328 LargeIconService::LargeIconService( |
| 168 FaviconService* favicon_service, | 329 FaviconService* favicon_service, |
| 169 const scoped_refptr<base::TaskRunner>& background_task_runner) | 330 const scoped_refptr<base::TaskRunner>& background_task_runner, |
| 331 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher) | |
| 170 : favicon_service_(favicon_service), | 332 : favicon_service_(favicon_service), |
| 171 background_task_runner_(background_task_runner) { | 333 background_task_runner_(background_task_runner), |
| 334 image_fetcher_(std::move(image_fetcher)) { | |
| 172 large_icon_types_.push_back(favicon_base::IconType::FAVICON); | 335 large_icon_types_.push_back(favicon_base::IconType::FAVICON); |
| 173 large_icon_types_.push_back(favicon_base::IconType::TOUCH_ICON); | 336 large_icon_types_.push_back(favicon_base::IconType::TOUCH_ICON); |
| 174 large_icon_types_.push_back(favicon_base::IconType::TOUCH_PRECOMPOSED_ICON); | 337 large_icon_types_.push_back(favicon_base::IconType::TOUCH_PRECOMPOSED_ICON); |
| 175 } | 338 } |
| 176 | 339 |
| 177 LargeIconService::~LargeIconService() { | 340 LargeIconService::~LargeIconService() { |
| 178 } | 341 } |
| 179 | 342 |
| 180 base::CancelableTaskTracker::TaskId | 343 base::CancelableTaskTracker::TaskId |
| 181 LargeIconService::GetLargeIconOrFallbackStyle( | 344 LargeIconService::GetLargeIconOrFallbackStyle( |
| 182 const GURL& page_url, | 345 const GURL& page_url, |
| 183 int min_source_size_in_pixel, | 346 int min_source_size_in_pixel, |
| 184 int desired_size_in_pixel, | 347 int desired_size_in_pixel, |
| 185 const favicon_base::LargeIconCallback& callback, | 348 const favicon_base::LargeIconCallback& callback, |
| 186 base::CancelableTaskTracker* tracker) { | 349 base::CancelableTaskTracker* tracker) { |
| 187 DCHECK_LE(1, min_source_size_in_pixel); | 350 DCHECK_LE(0, min_source_size_in_pixel); |
| 188 DCHECK_LE(0, desired_size_in_pixel); | 351 DCHECK_LE(0, desired_size_in_pixel); |
| 189 | 352 |
| 190 scoped_refptr<LargeIconWorker> worker = | 353 scoped_refptr<LargeIconWorker> worker = new LargeIconWorker( |
| 191 new LargeIconWorker(min_source_size_in_pixel, desired_size_in_pixel, | 354 page_url, min_source_size_in_pixel, desired_size_in_pixel, callback, |
| 192 callback, background_task_runner_, tracker); | 355 background_task_runner_, tracker, favicon_service_, image_fetcher_.get()); |
| 193 | 356 |
| 194 // TODO(beaudoin): For now this is just a wrapper around | 357 // TODO(jkrcal): For now this is just a wrapper around |
| 195 // GetLargestRawFaviconForPageURL. Add the logic required to select the best | 358 // GetLargestRawFaviconForPageURL. Consider extending |
| 196 // possible large icon. Also add logic to fetch-on-demand when the URL of | 359 // GetRawFaviconForPageURL() by min_original_size_in_pixel and migrating |
| 197 // a large icon is known but its bitmap is not available. | 360 // there. Otherwise, add the logic required to select the best possible large |
| 361 // icon. | |
|
pkotwicz
2017/02/10 20:44:34
You should use CancelableTaskTracker::NewTrackedTa
jkrcal
2017/02/13 14:39:45
Well, I noticed this function would give me what I
pkotwicz
2017/02/13 21:33:31
I didn't see that comment. Looks like the author o
| |
| 198 return favicon_service_->GetLargestRawFaviconForPageURL( | 362 return favicon_service_->GetLargestRawFaviconForPageURL( |
|
pkotwicz
2017/02/10 20:44:34
You can't use GetLargestRawFaviconForPageURL() her
jkrcal
2017/02/13 14:39:46
I am fine with using GetRawFaviconForPageURL() and
pkotwicz
2017/02/13 21:33:31
I have forgotten about the filtering in ThumbnailD
jkrcal
2017/02/27 17:31:19
Can we leave that for a further CL?
pkotwicz
2017/02/28 01:51:56
Doing this in a follow up CL is OK
| |
| 199 page_url, large_icon_types_, min_source_size_in_pixel, | 363 page_url, large_icon_types_, min_source_size_in_pixel, |
| 200 base::Bind(&LargeIconWorker::OnIconLookupComplete, worker), | 364 base::Bind(&LargeIconWorker::OnCachedIconLookupComplete, worker), |
| 201 tracker); | 365 tracker); |
| 202 } | 366 } |
| 203 | 367 |
| 204 } // namespace favicon | 368 } // namespace favicon |
| OLD | NEW |