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

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

Issue 2342183002: Call AddToHomescreenDataFetcher::Observer callbacks when manifest fetch times out (Closed)
Patch Set: Merge branch 'master' into remove_unneeded_var Created 4 years, 3 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 b1568786b07249bd322f10f6c9660a9ddbecea85..7d107a22b8624ec026336548246b366c197c2d87 100644
--- a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
+++ b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
@@ -73,7 +73,7 @@ AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
int minimum_icon_size_in_dp,
int ideal_splash_image_size_in_dp,
int minimum_splash_image_size_in_dp,
- bool check_installable,
+ bool check_webapk_compatibility,
Observer* observer)
: WebContentsObserver(web_contents),
weak_observer_(observer),
@@ -84,9 +84,9 @@ AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
minimum_icon_size_in_dp_(minimum_icon_size_in_dp),
ideal_splash_image_size_in_dp_(ideal_splash_image_size_in_dp),
minimum_splash_image_size_in_dp_(minimum_splash_image_size_in_dp),
- check_installable_(check_installable),
- is_waiting_for_installable_check_(check_installable),
+ check_webapk_compatibility_(check_webapk_compatibility),
is_waiting_for_web_application_info_(true),
+ is_installable_check_complete_(false),
is_icon_saved_(false),
is_ready_(false) {
DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp);
@@ -153,13 +153,12 @@ void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo(
// timeout, fall back to using a dynamically-generated launcher icon.
data_timeout_timer_.Start(
FROM_HERE, base::TimeDelta::FromMilliseconds(4000),
- base::Bind(&AddToHomescreenDataFetcher::OnFaviconFetched, this,
- favicon_base::FaviconRawBitmapResult()));
+ base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this));
manager->GetData(
ParamsToPerformInstallableCheck(ideal_icon_size_in_dp_,
minimum_icon_size_in_dp_,
- check_installable_),
+ check_webapk_compatibility_),
base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck,
this));
}
@@ -184,16 +183,30 @@ bool AddToHomescreenDataFetcher::OnMessageReceived(
return handled;
}
+void AddToHomescreenDataFetcher::OnDataTimedout() {
+ if (!web_contents() || !weak_observer_)
+ return;
+
+ if (!is_installable_check_complete_) {
+ is_installable_check_complete_ = true;
+ if (check_webapk_compatibility_)
+ weak_observer_->OnDidDetermineWebApkCompatibility(false);
+ weak_observer_->OnUserTitleAvailable(base::string16());
+ }
+
+ if (!is_icon_saved_)
+ CreateLauncherIcon(SkBitmap());
+}
void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck(
const InstallableData& data) {
if (!web_contents() || !weak_observer_)
return;
- if (check_installable_) {
- is_waiting_for_installable_check_ = false;
+ is_installable_check_complete_ = true;
+
+ if (check_webapk_compatibility_)
weak_observer_->OnDidDetermineWebApkCompatibility(data.is_installable);
- }
if (!data.manifest.IsEmpty()) {
content::RecordAction(
@@ -212,15 +225,7 @@ void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck(
if (data.icon) {
shortcut_info_.icon_url = data.icon_url;
- // base::Bind copies the arguments internally, so it is safe to pass it
- // data.icon (which is not owned by us).
- content::BrowserThread::GetBlockingPool()
- ->PostWorkerTaskWithShutdownBehavior(
- FROM_HERE,
- base::Bind(
- &AddToHomescreenDataFetcher::CreateLauncherIconInBackground,
- this, *(data.icon)),
- base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
+ CreateLauncherIcon(*(data.icon));
return;
}
@@ -231,11 +236,6 @@ void AddToHomescreenDataFetcher::FetchFavicon() {
if (!web_contents() || !weak_observer_)
return;
- if (check_installable_ && is_waiting_for_installable_check_) {
- is_waiting_for_installable_check_ = false;
- weak_observer_->OnDidDetermineWebApkCompatibility(false);
- }
-
// Grab the best, largest icon we can find to represent this bookmark.
// TODO(dfalcantara): Try combining with the new BookmarksHandler once its
// rewrite is further along.
@@ -286,6 +286,17 @@ void AddToHomescreenDataFetcher::CreateLauncherIconFromFaviconInBackground(
CreateLauncherIconInBackground(raw_icon);
}
+void AddToHomescreenDataFetcher::CreateLauncherIcon(const SkBitmap& raw_icon) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ content::BrowserThread::GetBlockingPool()
+ ->PostWorkerTaskWithShutdownBehavior(
+ FROM_HERE,
+ base::Bind(
+ &AddToHomescreenDataFetcher::CreateLauncherIconInBackground,
+ this, raw_icon),
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
+}
+
void AddToHomescreenDataFetcher::CreateLauncherIconInBackground(
const SkBitmap& raw_icon) {
DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());

Powered by Google App Engine
This is Rietveld 408576698