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

Side by Side Diff: components/favicon/core/favicon_service.cc

Issue 1092873002: [Icons NTP] Refactor large_icon_source to extract the logic shared between desktop and Android to f… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 (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 "components/favicon/core/favicon_service.h" 5 #include "components/favicon/core/favicon_service.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/hash.h" 9 #include "base/hash.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 sizes_in_pixel.push_back(std::ceil(size_in_dip * scales[i])); 44 sizes_in_pixel.push_back(std::ceil(size_in_dip * scales[i]));
45 } 45 }
46 return sizes_in_pixel; 46 return sizes_in_pixel;
47 } 47 }
48 48
49 } // namespace 49 } // namespace
50 50
51 FaviconService::FaviconService(FaviconClient* favicon_client, 51 FaviconService::FaviconService(FaviconClient* favicon_client,
52 history::HistoryService* history_service) 52 history::HistoryService* history_service)
53 : history_service_(history_service), favicon_client_(favicon_client) { 53 : history_service_(history_service), favicon_client_(favicon_client) {
54 large_icon_types_.push_back(favicon_base::IconType::FAVICON);
55 large_icon_types_.push_back(favicon_base::IconType::TOUCH_ICON);
56 large_icon_types_.push_back(favicon_base::IconType::TOUCH_PRECOMPOSED_ICON);
54 } 57 }
55 58
56 FaviconService::~FaviconService() { 59 FaviconService::~FaviconService() {
57 } 60 }
58 61
59 // static 62 // static
60 void FaviconService::FaviconResultsCallbackRunner( 63 void FaviconService::FaviconResultsCallbackRunner(
61 const favicon_base::FaviconResultsCallback& callback, 64 const favicon_base::FaviconResultsCallback& callback,
62 const std::vector<favicon_base::FaviconRawBitmapResult>* results) { 65 const std::vector<favicon_base::FaviconRawBitmapResult>* results) {
63 callback.Run(*results); 66 callback.Run(*results);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 page_url, icon_types, desired_sizes_in_pixel, 151 page_url, icon_types, desired_sizes_in_pixel,
149 base::Bind(&FaviconService::RunFaviconRawBitmapCallbackWithBitmapResults, 152 base::Bind(&FaviconService::RunFaviconRawBitmapCallbackWithBitmapResults,
150 base::Unretained(this), callback, desired_size_in_pixel), 153 base::Unretained(this), callback, desired_size_in_pixel),
151 tracker); 154 tracker);
152 } 155 }
153 156
154 base::CancelableTaskTracker::TaskId 157 base::CancelableTaskTracker::TaskId
155 FaviconService::GetLargestRawFaviconForPageURL( 158 FaviconService::GetLargestRawFaviconForPageURL(
156 const GURL& page_url, 159 const GURL& page_url,
157 const std::vector<int>& icon_types, 160 const std::vector<int>& icon_types,
158 int minimum_size_in_pixels, 161 int minimum_size_in_pixel,
159 const favicon_base::FaviconRawBitmapCallback& callback, 162 const favicon_base::FaviconRawBitmapCallback& callback,
160 base::CancelableTaskTracker* tracker) { 163 base::CancelableTaskTracker* tracker) {
161 favicon_base::FaviconResultsCallback favicon_results_callback = 164 favicon_base::FaviconResultsCallback favicon_results_callback =
162 base::Bind(&FaviconService::RunFaviconRawBitmapCallbackWithBitmapResults, 165 base::Bind(&FaviconService::RunFaviconRawBitmapCallbackWithBitmapResults,
163 base::Unretained(this), callback, 0); 166 base::Unretained(this), callback, 0);
164 if (favicon_client_ && favicon_client_->IsNativeApplicationURL(page_url)) { 167 if (favicon_client_ && favicon_client_->IsNativeApplicationURL(page_url)) {
165 std::vector<int> desired_sizes_in_pixel; 168 std::vector<int> desired_sizes_in_pixel;
166 desired_sizes_in_pixel.push_back(0); 169 desired_sizes_in_pixel.push_back(0);
167 return favicon_client_->GetFaviconForNativeApplicationURL( 170 return favicon_client_->GetFaviconForNativeApplicationURL(
168 page_url, desired_sizes_in_pixel, favicon_results_callback, tracker); 171 page_url, desired_sizes_in_pixel, favicon_results_callback, tracker);
169 } 172 }
170 if (history_service_) { 173 if (history_service_) {
171 return history_service_->GetLargestFaviconForURL(page_url, icon_types, 174 return history_service_->GetLargestFaviconForURL(page_url, icon_types,
172 minimum_size_in_pixels, callback, tracker); 175 minimum_size_in_pixel, callback, tracker);
173 } 176 }
174 return RunWithEmptyResultAsync(favicon_results_callback, tracker); 177 return RunWithEmptyResultAsync(favicon_results_callback, tracker);
175 } 178 }
176 179
180 base::CancelableTaskTracker::TaskId FaviconService::GetLargeIconOrFallbackStyle(
181 const GURL& page_url,
182 int desired_size_in_pixel,
183 const favicon_base::LargeIconCallback& callback,
184 base::CancelableTaskTracker* tracker) {
185 // TODO(beaudoin): For now this is just a wrapper around
186 // GetLargestRawFaviconForPageURL. Add the logic required to select the best
187 // possible large icon. Also add logic to fetch-on-demand when the URL of
188 // a large icon is known but its bitmap is not available.
pkotwicz 2015/04/17 18:39:14 I recommend creating a new service LargeIconServic
beaudoin 2015/04/17 20:29:05 Ok, I'll get that out in another service. Another
189 return GetLargestRawFaviconForPageURL(
190 page_url,
191 large_icon_types_,
192 desired_size_in_pixel,
193 base::Bind(&FaviconService::RunLargeIconCallback,
194 base::Unretained(this), callback, desired_size_in_pixel),
195 tracker);
196 }
197
177 base::CancelableTaskTracker::TaskId FaviconService::GetFaviconForPageURL( 198 base::CancelableTaskTracker::TaskId FaviconService::GetFaviconForPageURL(
178 const GURL& page_url, 199 const GURL& page_url,
179 int icon_types, 200 int icon_types,
180 int desired_size_in_dip, 201 int desired_size_in_dip,
181 const favicon_base::FaviconResultsCallback& callback, 202 const favicon_base::FaviconResultsCallback& callback,
182 base::CancelableTaskTracker* tracker) { 203 base::CancelableTaskTracker* tracker) {
183 return GetFaviconForPageURLImpl( 204 return GetFaviconForPageURLImpl(
184 page_url, 205 page_url,
185 icon_types, 206 icon_types,
186 GetPixelSizesForFaviconScales(desired_size_in_dip), 207 GetPixelSizesForFaviconScales(desired_size_in_dip),
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 &resized_bitmap_data)) { 385 &resized_bitmap_data)) {
365 callback.Run(favicon_base::FaviconRawBitmapResult()); 386 callback.Run(favicon_base::FaviconRawBitmapResult());
366 return; 387 return;
367 } 388 }
368 389
369 bitmap_result.bitmap_data = base::RefCountedBytes::TakeVector( 390 bitmap_result.bitmap_data = base::RefCountedBytes::TakeVector(
370 &resized_bitmap_data); 391 &resized_bitmap_data);
371 callback.Run(bitmap_result); 392 callback.Run(bitmap_result);
372 } 393 }
373 394
395 void FaviconService::RunLargeIconCallback(
396 const favicon_base::LargeIconCallback& callback,
397 int desired_size_in_pixel,
398 const favicon_base::FaviconRawBitmapResult& bitmap_result) {
399 // If there are no bitmap, we return a result with an empty |bitmap| and a
400 // default |fallback_icon_style|.
401 favicon_base::LargeIconResult result;
402 if (!bitmap_result.is_valid()) {
403 callback.Run(result);
404 return;
405 }
406
407 // If there is a bitmap but it's smaller than the requested size, we compute
408 // its dominant color and use it as background for |fallback_icon_style|.
409 if (bitmap_result.pixel_size.width() < desired_size_in_pixel ||
410 bitmap_result.pixel_size.height() < desired_size_in_pixel) {
411 favicon_base::SetDominantColorAsBackground(bitmap_result.bitmap_data,
412 &result.fallback_icon_style);
413 callback.Run(result);
414 return;
415 }
416
417 // The bitmap is the right size, use it.
418 result.bitmap = bitmap_result;
huangs 2015/04/17 15:30:47 Can move this into "else" of previous "if" to use
huangs 2015/04/17 20:44:04 Ping on this comment (feel to reject, but just wan
beaudoin 2015/04/20 19:15:05 Done.
419 callback.Run(result);
420 }
421
374 } // namespace favicon 422 } // namespace favicon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698