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

Unified Diff: chrome/browser/ui/app_list/arc/arc_app_icon.cc

Issue 2749973002: arc: Fix Default icon issue when cached icon file is corrupted. (Closed)
Patch Set: Address Yury's comments. Created 3 years, 9 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/ui/app_list/arc/arc_app_icon.cc
diff --git a/chrome/browser/ui/app_list/arc/arc_app_icon.cc b/chrome/browser/ui/app_list/arc/arc_app_icon.cc
index f888755d4ab4f6cd8d233f51729d7ab10447a2b6..1a82e99cfcf7b7df2ebcc404a10d07fe98204b3e 100644
--- a/chrome/browser/ui/app_list/arc/arc_app_icon.cc
+++ b/chrome/browser/ui/app_list/arc/arc_app_icon.cc
@@ -172,6 +172,7 @@ class ArcAppIcon::DecodeRequest : public ImageDecoder::ImageRequest {
// ImageDecoder::ImageRequest
void OnImageDecoded(const SkBitmap& bitmap) override;
void OnDecodeImageFailed() override;
+
private:
base::WeakPtr<ArcAppIcon> host_;
int dimension_;
@@ -206,6 +207,8 @@ void ArcAppIcon::DecodeRequest::OnImageDecoded(const SkBitmap& bitmap) {
VLOG(2) << "Decoded ARC icon has unexpected dimension "
<< bitmap.width() << "x" << bitmap.height() << ". Expected "
<< expected_dim << "x" << ".";
+
+ host_->MaybeRequestIcon(scale_factor_);
host_->DiscardDecodeRequest(this);
return;
}
@@ -214,7 +217,6 @@ void ArcAppIcon::DecodeRequest::OnImageDecoded(const SkBitmap& bitmap) {
image_skia.AddRepresentation(gfx::ImageSkiaRep(
bitmap,
ui::GetScaleForScaleFactor(scale_factor_)));
-
host_->Update(&image_skia);
host_->DiscardDecodeRequest(this);
}
@@ -225,6 +227,7 @@ void ArcAppIcon::DecodeRequest::OnDecodeImageFailed() {
if (!host_)
return;
+ host_->MaybeRequestIcon(scale_factor_);
host_->DiscardDecodeRequest(this);
}
@@ -270,7 +273,7 @@ void ArcAppIcon::LoadForScaleFactor(ui::ScaleFactor scale_factor) {
base::Bind(&ArcAppIcon::OnIconRead, weak_ptr_factory_.GetWeakPtr()));
}
-void ArcAppIcon::RequestIcon(ui::ScaleFactor scale_factor) {
+void ArcAppIcon::MaybeRequestIcon(ui::ScaleFactor scale_factor) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context_);
DCHECK(prefs);
@@ -278,7 +281,7 @@ void ArcAppIcon::RequestIcon(ui::ScaleFactor scale_factor) {
// ArcAppListPrefs notifies ArcAppModelBuilder via Observer when icon is ready
// and ArcAppModelBuilder refreshes the icon of the corresponding item by
// calling LoadScaleFactor.
- prefs->RequestIcon(app_id_, scale_factor);
+ prefs->MaybeRequestIcon(app_id_, scale_factor);
}
// static
@@ -299,18 +302,23 @@ std::unique_ptr<ArcAppIcon::ReadResult> ArcAppIcon::ReadOnFileThread(
path_to_read = default_app_path;
}
+ bool request_to_install = path_to_read != path;
+
// Read the file from disk.
std::string unsafe_icon_data;
- if (!base::ReadFileToString(path_to_read, &unsafe_icon_data)) {
+ if (!base::ReadFileToString(path_to_read, &unsafe_icon_data) ||
+ unsafe_icon_data.empty()) {
VLOG(2) << "Failed to read an ARC icon from file " << path.MaybeAsASCII();
+
+ // If unsafe_icon_data is empty typically means we have a file corruption on
Luis Héctor Chávez 2017/03/15 20:28:51 nit: |unsafe_icon_data|
lgcheng 2017/03/15 22:05:33 Done.
+ // cached icon file. Send request to re install the icon.
+ request_to_install = request_to_install || unsafe_icon_data.empty();
Luis Héctor Chávez 2017/03/15 20:28:51 nit: request_to_install |= unsafe_icon_data.empty(
xiyuan 2017/03/15 20:30:26 nit: request_to_install |= unsafe_icon_data.empty(
lgcheng 2017/03/15 22:05:33 Done.
return base::WrapUnique(new ArcAppIcon::ReadResult(
- true, path_to_read != path, scale_factor, std::string()));
+ true, request_to_install, scale_factor, std::string()));
}
- return base::WrapUnique(new ArcAppIcon::ReadResult(false,
- path_to_read != path,
- scale_factor,
- unsafe_icon_data));
+ return base::WrapUnique(new ArcAppIcon::ReadResult(
xiyuan 2017/03/15 20:30:26 nit: base::MakeUnique<ArcAppIcon::ReadResult>(...)
lgcheng 2017/03/15 22:05:33 Done.
+ false, request_to_install, scale_factor, unsafe_icon_data));
}
void ArcAppIcon::OnIconRead(
@@ -318,7 +326,7 @@ void ArcAppIcon::OnIconRead(
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (read_result->request_to_install)
- RequestIcon(read_result->scale_factor);
+ MaybeRequestIcon(read_result->scale_factor);
if (!read_result->unsafe_icon_data.empty()) {
decode_requests_.push_back(base::MakeUnique<DecodeRequest>(

Powered by Google App Engine
This is Rietveld 408576698