| 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 "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h" | 5 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 FetchFavicon(); | 256 FetchFavicon(); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void AddToHomescreenDataFetcher::FetchFavicon() { | 259 void AddToHomescreenDataFetcher::FetchFavicon() { |
| 260 if (!web_contents() || !weak_observer_) | 260 if (!web_contents() || !weak_observer_) |
| 261 return; | 261 return; |
| 262 | 262 |
| 263 // Grab the best, largest icon we can find to represent this bookmark. | 263 // Grab the best, largest icon we can find to represent this bookmark. |
| 264 // TODO(dfalcantara): Try combining with the new BookmarksHandler once its | 264 // TODO(dfalcantara): Try combining with the new BookmarksHandler once its |
| 265 // rewrite is further along. | 265 // rewrite is further along. |
| 266 std::vector<int> icon_types{ | |
| 267 favicon_base::FAVICON, | |
| 268 favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON}; | |
| 269 | |
| 270 favicon::FaviconService* favicon_service = | 266 favicon::FaviconService* favicon_service = |
| 271 FaviconServiceFactory::GetForProfile( | 267 FaviconServiceFactory::GetForProfile( |
| 272 Profile::FromBrowserContext(web_contents()->GetBrowserContext()), | 268 Profile::FromBrowserContext(web_contents()->GetBrowserContext()), |
| 273 ServiceAccessType::EXPLICIT_ACCESS); | 269 ServiceAccessType::EXPLICIT_ACCESS); |
| 274 | 270 |
| 275 // Using favicon if its size is not smaller than platform required size, | |
| 276 // otherwise using the largest icon among all avaliable icons. | |
| 277 int threshold_to_get_any_largest_icon = ideal_icon_size_in_px_ - 1; | |
| 278 favicon_service->GetLargestRawFaviconForPageURL( | 271 favicon_service->GetLargestRawFaviconForPageURL( |
| 279 shortcut_info_.url, icon_types, threshold_to_get_any_largest_icon, | 272 shortcut_info_.url, |
| 280 base::Bind(&AddToHomescreenDataFetcher::OnFaviconFetched, this), | 273 base::Bind(&AddToHomescreenDataFetcher::OnFaviconFetched, this), |
| 281 &favicon_task_tracker_); | 274 &favicon_task_tracker_); |
| 282 } | 275 } |
| 283 | 276 |
| 284 void AddToHomescreenDataFetcher::OnFaviconFetched( | 277 void AddToHomescreenDataFetcher::OnFaviconFetched( |
| 285 const favicon_base::FaviconRawBitmapResult& bitmap_result) { | 278 const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
| 286 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 279 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
| 287 return; | 280 return; |
| 288 | 281 |
| 289 base::PostTaskAndReplyWithResult( | 282 base::PostTaskAndReplyWithResult( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { | 332 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { |
| 340 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 333 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 341 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 334 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
| 342 return; | 335 return; |
| 343 | 336 |
| 344 is_icon_saved_ = true; | 337 is_icon_saved_ = true; |
| 345 primary_icon_ = primary_icon; | 338 primary_icon_ = primary_icon; |
| 346 is_ready_ = true; | 339 is_ready_ = true; |
| 347 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); | 340 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); |
| 348 } | 341 } |
| OLD | NEW |