| OLD | NEW |
| 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // static | 242 // static |
| 243 bool ArcAppIcon::IsSafeDecodingDisabledForTesting() { | 243 bool ArcAppIcon::IsSafeDecodingDisabledForTesting() { |
| 244 return disable_safe_decoding_for_testing; | 244 return disable_safe_decoding_for_testing; |
| 245 } | 245 } |
| 246 | 246 |
| 247 ArcAppIcon::ArcAppIcon(content::BrowserContext* context, | 247 ArcAppIcon::ArcAppIcon(content::BrowserContext* context, |
| 248 const std::string& app_id, | 248 const std::string& app_id, |
| 249 int resource_size_in_dip, | 249 int resource_size_in_dip, |
| 250 Observer* observer) | 250 Observer* observer) |
| 251 : context_(context), | 251 : context_(context), |
| 252 app_id_(GetAppFromAppOrGroupId(context, app_id)), | 252 app_id_(app_id), |
| 253 mapped_app_id_(GetAppFromAppOrGroupId(context, app_id)), |
| 253 resource_size_in_dip_(resource_size_in_dip), | 254 resource_size_in_dip_(resource_size_in_dip), |
| 254 observer_(observer), | 255 observer_(observer), |
| 255 weak_ptr_factory_(this) { | 256 weak_ptr_factory_(this) { |
| 256 CHECK(observer_ != nullptr); | 257 CHECK(observer_ != nullptr); |
| 257 source_ = new Source(weak_ptr_factory_.GetWeakPtr(), resource_size_in_dip); | 258 source_ = new Source(weak_ptr_factory_.GetWeakPtr(), resource_size_in_dip); |
| 258 gfx::Size resource_size(resource_size_in_dip, resource_size_in_dip); | 259 gfx::Size resource_size(resource_size_in_dip, resource_size_in_dip); |
| 259 image_skia_ = gfx::ImageSkia(source_, resource_size); | 260 image_skia_ = gfx::ImageSkia(source_, resource_size); |
| 260 } | 261 } |
| 261 | 262 |
| 262 ArcAppIcon::~ArcAppIcon() { | 263 ArcAppIcon::~ArcAppIcon() { |
| 263 } | 264 } |
| 264 | 265 |
| 265 void ArcAppIcon::LoadForScaleFactor(ui::ScaleFactor scale_factor) { | 266 void ArcAppIcon::LoadForScaleFactor(ui::ScaleFactor scale_factor) { |
| 266 // We provide Play Store icon from Chrome resources and it is not expected | 267 // We provide Play Store icon from Chrome resources and it is not expected |
| 267 // that we have external load request. | 268 // that we have external load request. |
| 268 DCHECK_NE(app_id_, arc::kPlayStoreAppId); | 269 DCHECK_NE(app_id(), arc::kPlayStoreAppId); |
| 269 | 270 |
| 270 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(context_); | 271 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(context_); |
| 271 DCHECK(prefs); | 272 DCHECK(prefs); |
| 272 | 273 |
| 273 const base::FilePath path = prefs->GetIconPath(app_id_, scale_factor); | 274 const base::FilePath path = prefs->GetIconPath(mapped_app_id_, scale_factor); |
| 274 if (path.empty()) | 275 if (path.empty()) |
| 275 return; | 276 return; |
| 276 | 277 |
| 277 base::PostTaskWithTraitsAndReplyWithResult( | 278 base::PostTaskWithTraitsAndReplyWithResult( |
| 278 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, | 279 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
| 279 base::Bind(&ArcAppIcon::ReadOnFileThread, scale_factor, path, | 280 base::Bind( |
| 280 prefs->MaybeGetIconPathForDefaultApp(app_id_, scale_factor)), | 281 &ArcAppIcon::ReadOnFileThread, scale_factor, path, |
| 282 prefs->MaybeGetIconPathForDefaultApp(mapped_app_id_, scale_factor)), |
| 281 base::Bind(&ArcAppIcon::OnIconRead, weak_ptr_factory_.GetWeakPtr())); | 283 base::Bind(&ArcAppIcon::OnIconRead, weak_ptr_factory_.GetWeakPtr())); |
| 282 } | 284 } |
| 283 | 285 |
| 284 void ArcAppIcon::MaybeRequestIcon(ui::ScaleFactor scale_factor) { | 286 void ArcAppIcon::MaybeRequestIcon(ui::ScaleFactor scale_factor) { |
| 285 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 287 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 286 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context_); | 288 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context_); |
| 287 DCHECK(prefs); | 289 DCHECK(prefs); |
| 288 | 290 |
| 289 // ArcAppListPrefs notifies ArcAppModelBuilder via Observer when icon is ready | 291 // ArcAppListPrefs notifies ArcAppModelBuilder via Observer when icon is ready |
| 290 // and ArcAppModelBuilder refreshes the icon of the corresponding item by | 292 // and ArcAppModelBuilder refreshes the icon of the corresponding item by |
| 291 // calling LoadScaleFactor. | 293 // calling LoadScaleFactor. |
| 292 prefs->MaybeRequestIcon(app_id_, scale_factor); | 294 prefs->MaybeRequestIcon(mapped_app_id_, scale_factor); |
| 293 } | 295 } |
| 294 | 296 |
| 295 // static | 297 // static |
| 296 std::unique_ptr<ArcAppIcon::ReadResult> ArcAppIcon::ReadOnFileThread( | 298 std::unique_ptr<ArcAppIcon::ReadResult> ArcAppIcon::ReadOnFileThread( |
| 297 ui::ScaleFactor scale_factor, | 299 ui::ScaleFactor scale_factor, |
| 298 const base::FilePath& path, | 300 const base::FilePath& path, |
| 299 const base::FilePath& default_app_path) { | 301 const base::FilePath& default_app_path) { |
| 300 DCHECK(!path.empty()); | 302 DCHECK(!path.empty()); |
| 301 | 303 |
| 302 base::FilePath path_to_read; | 304 base::FilePath path_to_read; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 void ArcAppIcon::DiscardDecodeRequest(DecodeRequest* request) { | 379 void ArcAppIcon::DiscardDecodeRequest(DecodeRequest* request) { |
| 378 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 380 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 379 | 381 |
| 380 auto it = std::find_if(decode_requests_.begin(), decode_requests_.end(), | 382 auto it = std::find_if(decode_requests_.begin(), decode_requests_.end(), |
| 381 [request](const std::unique_ptr<DecodeRequest>& ptr) { | 383 [request](const std::unique_ptr<DecodeRequest>& ptr) { |
| 382 return ptr.get() == request; | 384 return ptr.get() == request; |
| 383 }); | 385 }); |
| 384 CHECK(it != decode_requests_.end()); | 386 CHECK(it != decode_requests_.end()); |
| 385 decode_requests_.erase(it); | 387 decode_requests_.erase(it); |
| 386 } | 388 } |
| OLD | NEW |