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

Unified Diff: chrome/browser/android/shortcut_data_fetcher.cc

Issue 1124433005: Introduce timeout for downloading a favicon for adding to Home screen (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dialog
Patch Set: is_icon_saved_ Created 5 years, 7 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
« no previous file with comments | « chrome/browser/android/shortcut_data_fetcher.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/shortcut_data_fetcher.cc
diff --git a/chrome/browser/android/shortcut_data_fetcher.cc b/chrome/browser/android/shortcut_data_fetcher.cc
index e8868bc9e6d24e56483cf2fad2137337e45d14fe..39bccfaafb33113969d678d924d3c638217fd1c3 100644
--- a/chrome/browser/android/shortcut_data_fetcher.cc
+++ b/chrome/browser/android/shortcut_data_fetcher.cc
@@ -39,7 +39,10 @@ ShortcutDataFetcher::ShortcutDataFetcher(
Observer* observer)
: WebContentsObserver(web_contents),
weak_observer_(observer),
+ is_waiting_for_web_application_info_(false),
+ is_icon_saved_(false),
is_ready_(false),
+ icon_timeout_timer_(false, false),
shortcut_info_(dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(
web_contents->GetURL())),
preferred_icon_size_in_px_(kPreferredIconSizeInDp *
@@ -119,6 +122,14 @@ void ShortcutDataFetcher::OnDidGetManifest(const content::Manifest& manifest) {
}
weak_observer_->OnTitleAvailable(shortcut_info_.title);
+
+ // Kick off a timeout for downloading the icon. If an icon isn't set within
+ // the timeout, fall back to using a dynamically-generated launcher icon.
+ icon_timeout_timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(3000),
+ base::Bind(&ShortcutDataFetcher::OnFaviconFetched,
+ this,
+ favicon_base::FaviconRawBitmapResult()));
}
bool ShortcutDataFetcher::OnMessageReceived(const IPC::Message& message) {
@@ -164,12 +175,14 @@ void ShortcutDataFetcher::FetchFavicon() {
icon_types,
threshold_to_get_any_largest_icon,
base::Bind(&ShortcutDataFetcher::OnFaviconFetched, this),
- &cancelable_task_tracker_);
+ &favicon_task_tracker_);
}
void ShortcutDataFetcher::OnFaviconFetched(
const favicon_base::FaviconRawBitmapResult& bitmap_result) {
- if (!web_contents() || !weak_observer_) return;
+ if (!web_contents() || !weak_observer_ || is_icon_saved_) {
+ return;
+ }
content::BrowserThread::PostTask(
content::BrowserThread::IO,
@@ -192,14 +205,14 @@ void ShortcutDataFetcher::CreateLauncherIcon(
}
if (weak_observer_) {
- shortcut_icon_ = weak_observer_->FinalizeLauncherIcon(icon_bitmap,
- shortcut_info_.url);
+ icon_bitmap = weak_observer_->FinalizeLauncherIcon(icon_bitmap,
+ shortcut_info_.url);
}
content::BrowserThread::PostTask(
content::BrowserThread::UI,
FROM_HERE,
- base::Bind(&ShortcutDataFetcher::NotifyObserver, this));
+ base::Bind(&ShortcutDataFetcher::NotifyObserver, this, icon_bitmap));
}
void ShortcutDataFetcher::OnManifestIconFetched(
@@ -227,14 +240,16 @@ void ShortcutDataFetcher::OnManifestIconFetched(
preferred_bitmap_index = i;
}
- shortcut_icon_ = bitmaps[preferred_bitmap_index];
- NotifyObserver();
+ NotifyObserver(bitmaps[preferred_bitmap_index]);
}
-void ShortcutDataFetcher::NotifyObserver() {
- if (!web_contents() || !weak_observer_) return;
+void ShortcutDataFetcher::NotifyObserver(const SkBitmap& bitmap) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ if (!web_contents() || !weak_observer_ || is_icon_saved_)
+ return;
+ is_icon_saved_ = true;
+ shortcut_icon_ = bitmap;
is_ready_ = true;
weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_);
}
« no previous file with comments | « chrome/browser/android/shortcut_data_fetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698