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

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

Issue 2763753003: [Merge To M58]Fix Default icon issue when cached icon file is corrupted. (Closed)
Patch Set: Rebase. 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
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_icon.h ('k') | chrome/browser/ui/app_list/arc/arc_app_list_prefs.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7a9614313d4521d8b902e219861ad751ca2e2eef..02a7d1a5e6b21324925a67c9c9de77e034a16ab9 100644
--- a/chrome/browser/ui/app_list/arc/arc_app_icon.cc
+++ b/chrome/browser/ui/app_list/arc/arc_app_icon.cc
@@ -171,6 +171,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_;
@@ -205,6 +206,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;
}
@@ -213,7 +216,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);
}
@@ -224,6 +226,7 @@ void ArcAppIcon::DecodeRequest::OnDecodeImageFailed() {
if (!host_)
return;
+ host_->MaybeRequestIcon(scale_factor_);
host_->DiscardDecodeRequest(this);
}
@@ -269,7 +272,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);
@@ -277,7 +280,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
@@ -292,24 +295,29 @@ std::unique_ptr<ArcAppIcon::ReadResult> ArcAppIcon::ReadOnFileThread(
path_to_read = path;
} else {
if (default_app_path.empty() || !base::PathExists(default_app_path)) {
- return base::WrapUnique(new ArcAppIcon::ReadResult(
- false, true, scale_factor, std::string()));
+ return base::MakeUnique<ArcAppIcon::ReadResult>(false, true, scale_factor,
+ std::string());
}
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();
- return base::WrapUnique(new ArcAppIcon::ReadResult(
- true, path_to_read != path, scale_factor, std::string()));
+
+ // If |unsafe_icon_data| is empty typically means we have a file corruption
+ // on cached icon file. Send request to re install the icon.
+ request_to_install |= unsafe_icon_data.empty();
+ return base::MakeUnique<ArcAppIcon::ReadResult>(
+ 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::MakeUnique<ArcAppIcon::ReadResult>(
+ false, request_to_install, scale_factor, unsafe_icon_data);
}
void ArcAppIcon::OnIconRead(
@@ -317,7 +325,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>(
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_icon.h ('k') | chrome/browser/ui/app_list/arc/arc_app_list_prefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698