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

Unified Diff: chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc

Issue 1261143004: Implement manifest icon downloader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix favicon fallback in add to homescreen helper Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
diff --git a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
index 894f6a1af1c81049a6f6bdf6e319347102024b5d..7cb973186b82e3ead8d5cb9a674f7b583629a3ec 100644
--- a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
+++ b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
@@ -9,6 +9,7 @@
#include "base/strings/string16.h"
#include "base/task/cancelable_task_tracker.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
+#include "chrome/browser/manifest/manifest_icon_downloader.h"
#include "chrome/browser/manifest/manifest_icon_selector.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_constants.h"
@@ -45,6 +46,7 @@ AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
icon_timeout_timer_(false, false),
shortcut_info_(dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(
web_contents->GetURL())),
+ icon_downloader_(new ManifestIconDownloader()),
preferred_icon_size_in_px_(kPreferredIconSizeInDp *
gfx::Screen::GetScreenFor(web_contents->GetNativeView())->
GetPrimaryDisplay().device_scale_factor()) {
@@ -111,17 +113,15 @@ void AddToHomescreenDataFetcher::OnDidGetManifest(
manifest.icons,
kPreferredIconSizeInDp,
gfx::Screen::GetScreenFor(web_contents()->GetNativeView()));
- if (icon_src.is_valid()) {
- // Grab the best icon from the manifest.
- web_contents()->DownloadImage(
+
+ // If fetching the Manifest icon fails, fallback to the best favicon
+ // for the page.
+ if (!icon_downloader_->Download(
+ web_contents(),
icon_src,
- false,
- preferred_icon_size_in_px_,
- false,
- base::Bind(&AddToHomescreenDataFetcher::OnManifestIconFetched,
- this));
- } else {
- // Grab the best favicon for the page.
+ kPreferredIconSizeInDp,
+ base::Bind(&AddToHomescreenDataFetcher::NotifyObserver,
+ this))) {
FetchFavicon();
}
@@ -186,9 +186,8 @@ void AddToHomescreenDataFetcher::FetchFavicon() {
void AddToHomescreenDataFetcher::OnFaviconFetched(
const favicon_base::FaviconRawBitmapResult& bitmap_result) {
- if (!web_contents() || !weak_observer_ || is_icon_saved_) {
+ if (!web_contents() || !weak_observer_ || is_icon_saved_)
return;
- }
content::BrowserThread::PostTask(
content::BrowserThread::IO,
@@ -223,32 +222,12 @@ void AddToHomescreenDataFetcher::CreateLauncherIcon(
icon_bitmap));
}
-void AddToHomescreenDataFetcher::OnManifestIconFetched(
- int id,
- int http_status_code,
- const GURL& url,
- const std::vector<SkBitmap>& bitmaps,
- const std::vector<gfx::Size>& sizes) {
- if (!web_contents() || !weak_observer_) return;
-
- // If getting the candidate manifest icon failed, the ShortcutHelper should
- // fallback to the favicon.
- // Otherwise, it sets the state as if there was no manifest icon pending.
- if (bitmaps.empty()) {
+void AddToHomescreenDataFetcher::OnManifestIconFetched(const SkBitmap& icon) {
+ if (bitmap.drawsNothing()) {
FetchFavicon();
return;
}
-
- // There might be multiple bitmaps returned. The one to pick is bigger or
- // equal to the preferred size. |bitmaps| is ordered from bigger to smaller.
- int preferred_bitmap_index = 0;
- for (size_t i = 0; i < bitmaps.size(); ++i) {
- if (bitmaps[i].height() < preferred_icon_size_in_px_)
- break;
- preferred_bitmap_index = i;
- }
-
- NotifyObserver(bitmaps[preferred_bitmap_index]);
+ NotifyObserver(icon);
}
void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& bitmap) {

Powered by Google App Engine
This is Rietveld 408576698