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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" 5 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 class ArcAppIcon::DecodeRequest : public ImageDecoder::ImageRequest { 165 class ArcAppIcon::DecodeRequest : public ImageDecoder::ImageRequest {
166 public: 166 public:
167 DecodeRequest(const base::WeakPtr<ArcAppIcon>& host, 167 DecodeRequest(const base::WeakPtr<ArcAppIcon>& host,
168 int dimension, 168 int dimension,
169 ui::ScaleFactor scale_factor); 169 ui::ScaleFactor scale_factor);
170 ~DecodeRequest() override; 170 ~DecodeRequest() override;
171 171
172 // ImageDecoder::ImageRequest 172 // ImageDecoder::ImageRequest
173 void OnImageDecoded(const SkBitmap& bitmap) override; 173 void OnImageDecoded(const SkBitmap& bitmap) override;
174 void OnDecodeImageFailed() override; 174 void OnDecodeImageFailed() override;
175
175 private: 176 private:
176 base::WeakPtr<ArcAppIcon> host_; 177 base::WeakPtr<ArcAppIcon> host_;
177 int dimension_; 178 int dimension_;
178 ui::ScaleFactor scale_factor_; 179 ui::ScaleFactor scale_factor_;
179 180
180 DISALLOW_COPY_AND_ASSIGN(DecodeRequest); 181 DISALLOW_COPY_AND_ASSIGN(DecodeRequest);
181 }; 182 };
182 183
183 //////////////////////////////////////////////////////////////////////////////// 184 ////////////////////////////////////////////////////////////////////////////////
184 // ArcAppIcon::DecodeRequest 185 // ArcAppIcon::DecodeRequest
(...skipping 14 matching lines...) Expand all
199 200
200 if (!host_) 201 if (!host_)
201 return; 202 return;
202 203
203 int expected_dim = static_cast<int>( 204 int expected_dim = static_cast<int>(
204 ui::GetScaleForScaleFactor(scale_factor_) * dimension_ + 0.5f); 205 ui::GetScaleForScaleFactor(scale_factor_) * dimension_ + 0.5f);
205 if (bitmap.width() != expected_dim || bitmap.height() != expected_dim) { 206 if (bitmap.width() != expected_dim || bitmap.height() != expected_dim) {
206 VLOG(2) << "Decoded ARC icon has unexpected dimension " 207 VLOG(2) << "Decoded ARC icon has unexpected dimension "
207 << bitmap.width() << "x" << bitmap.height() << ". Expected " 208 << bitmap.width() << "x" << bitmap.height() << ". Expected "
208 << expected_dim << "x" << "."; 209 << expected_dim << "x" << ".";
210
211 host_->MaybeRequestIcon(scale_factor_);
209 host_->DiscardDecodeRequest(this); 212 host_->DiscardDecodeRequest(this);
210 return; 213 return;
211 } 214 }
212 215
213 gfx::ImageSkia image_skia; 216 gfx::ImageSkia image_skia;
214 image_skia.AddRepresentation(gfx::ImageSkiaRep( 217 image_skia.AddRepresentation(gfx::ImageSkiaRep(
215 bitmap, 218 bitmap,
216 ui::GetScaleForScaleFactor(scale_factor_))); 219 ui::GetScaleForScaleFactor(scale_factor_)));
217
218 host_->Update(&image_skia); 220 host_->Update(&image_skia);
219 host_->DiscardDecodeRequest(this); 221 host_->DiscardDecodeRequest(this);
220 } 222 }
221 223
222 void ArcAppIcon::DecodeRequest::OnDecodeImageFailed() { 224 void ArcAppIcon::DecodeRequest::OnDecodeImageFailed() {
223 VLOG(2) << "Failed to decode ARC icon."; 225 VLOG(2) << "Failed to decode ARC icon.";
224 226
225 if (!host_) 227 if (!host_)
226 return; 228 return;
227 229
230 host_->MaybeRequestIcon(scale_factor_);
228 host_->DiscardDecodeRequest(this); 231 host_->DiscardDecodeRequest(this);
229 } 232 }
230 233
231 //////////////////////////////////////////////////////////////////////////////// 234 ////////////////////////////////////////////////////////////////////////////////
232 // ArcAppIcon 235 // ArcAppIcon
233 236
234 // static 237 // static
235 void ArcAppIcon::DisableSafeDecodingForTesting() { 238 void ArcAppIcon::DisableSafeDecodingForTesting() {
236 disable_safe_decoding = true; 239 disable_safe_decoding = true;
237 } 240 }
(...skipping 25 matching lines...) Expand all
263 return; 266 return;
264 267
265 base::PostTaskWithTraitsAndReplyWithResult( 268 base::PostTaskWithTraitsAndReplyWithResult(
266 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( 269 FROM_HERE, base::TaskTraits().MayBlock().WithPriority(
267 base::TaskPriority::BACKGROUND), 270 base::TaskPriority::BACKGROUND),
268 base::Bind(&ArcAppIcon::ReadOnFileThread, scale_factor, path, 271 base::Bind(&ArcAppIcon::ReadOnFileThread, scale_factor, path,
269 prefs->MaybeGetIconPathForDefaultApp(app_id_, scale_factor)), 272 prefs->MaybeGetIconPathForDefaultApp(app_id_, scale_factor)),
270 base::Bind(&ArcAppIcon::OnIconRead, weak_ptr_factory_.GetWeakPtr())); 273 base::Bind(&ArcAppIcon::OnIconRead, weak_ptr_factory_.GetWeakPtr()));
271 } 274 }
272 275
273 void ArcAppIcon::RequestIcon(ui::ScaleFactor scale_factor) { 276 void ArcAppIcon::MaybeRequestIcon(ui::ScaleFactor scale_factor) {
274 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 277 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
275 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context_); 278 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context_);
276 DCHECK(prefs); 279 DCHECK(prefs);
277 280
281 // Request for Icon has been recorded. Don't resend same request within same
282 // user session.
283 if (prefs->IsIconRequestRecorded(app_id_, scale_factor))
khmel 2017/03/15 01:16:55 Could you please move this logic into prefs. It wo
lgcheng 2017/03/15 19:59:31 Done.
284 return;
278 // ArcAppListPrefs notifies ArcAppModelBuilder via Observer when icon is ready 285 // ArcAppListPrefs notifies ArcAppModelBuilder via Observer when icon is ready
279 // and ArcAppModelBuilder refreshes the icon of the corresponding item by 286 // and ArcAppModelBuilder refreshes the icon of the corresponding item by
280 // calling LoadScaleFactor. 287 // calling LoadScaleFactor.
281 prefs->RequestIcon(app_id_, scale_factor); 288 prefs->RequestIcon(app_id_, scale_factor);
282 } 289 }
283 290
284 // static 291 // static
285 std::unique_ptr<ArcAppIcon::ReadResult> ArcAppIcon::ReadOnFileThread( 292 std::unique_ptr<ArcAppIcon::ReadResult> ArcAppIcon::ReadOnFileThread(
286 ui::ScaleFactor scale_factor, 293 ui::ScaleFactor scale_factor,
287 const base::FilePath& path, 294 const base::FilePath& path,
(...skipping 22 matching lines...) Expand all
310 return base::WrapUnique(new ArcAppIcon::ReadResult(false, 317 return base::WrapUnique(new ArcAppIcon::ReadResult(false,
311 path_to_read != path, 318 path_to_read != path,
312 scale_factor, 319 scale_factor,
313 unsafe_icon_data)); 320 unsafe_icon_data));
314 } 321 }
315 322
316 void ArcAppIcon::OnIconRead( 323 void ArcAppIcon::OnIconRead(
317 std::unique_ptr<ArcAppIcon::ReadResult> read_result) { 324 std::unique_ptr<ArcAppIcon::ReadResult> read_result) {
318 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 325 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
319 326
320 if (read_result->request_to_install) 327 // When unsafe_icon_data is empty, there are four senarios.
321 RequestIcon(read_result->scale_factor); 328 // 1. Default app icon path is non valid. In this case, request_to_install is
329 // true.
330 // 2. Fail to read default icon file. In this case request_to_install is true.
331 // 3. Default icon file is empty. In this case request_to_install is true.
332 // 4. Icon file for app_id_ is empty. This indicates a file corruption of some
333 // sort of issue. We should try to request app icon.
334 if (read_result->request_to_install || read_result->unsafe_icon_data.empty())
khmel 2017/03/15 01:16:55 Could you please move read_result->unsafe_icon_dat
lgcheng 2017/03/15 19:59:31 Done.
335 MaybeRequestIcon(read_result->scale_factor);
322 336
323 if (!read_result->unsafe_icon_data.empty()) { 337 if (!read_result->unsafe_icon_data.empty()) {
324 decode_requests_.push_back(base::MakeUnique<DecodeRequest>( 338 decode_requests_.push_back(base::MakeUnique<DecodeRequest>(
325 weak_ptr_factory_.GetWeakPtr(), resource_size_in_dip_, 339 weak_ptr_factory_.GetWeakPtr(), resource_size_in_dip_,
326 read_result->scale_factor)); 340 read_result->scale_factor));
327 if (disable_safe_decoding) { 341 if (disable_safe_decoding) {
328 SkBitmap bitmap; 342 SkBitmap bitmap;
329 if (!read_result->unsafe_icon_data.empty() && 343 if (!read_result->unsafe_icon_data.empty() &&
330 gfx::PNGCodec::Decode( 344 gfx::PNGCodec::Decode(
331 reinterpret_cast<const unsigned char*>( 345 reinterpret_cast<const unsigned char*>(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 void ArcAppIcon::DiscardDecodeRequest(DecodeRequest* request) { 377 void ArcAppIcon::DiscardDecodeRequest(DecodeRequest* request) {
364 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 378 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
365 379
366 auto it = std::find_if(decode_requests_.begin(), decode_requests_.end(), 380 auto it = std::find_if(decode_requests_.begin(), decode_requests_.end(),
367 [request](const std::unique_ptr<DecodeRequest>& ptr) { 381 [request](const std::unique_ptr<DecodeRequest>& ptr) {
368 return ptr.get() == request; 382 return ptr.get() == request;
369 }); 383 });
370 CHECK(it != decode_requests_.end()); 384 CHECK(it != decode_requests_.end());
371 decode_requests_.erase(it); 385 decode_requests_.erase(it);
372 } 386 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698