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

Side by Side Diff: chrome/browser/ui/app_list/arc/arc_app_list_prefs.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_list_prefs.h" 5 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 310
311 return ToIconPath(default_app->app_path, scale_factor); 311 return ToIconPath(default_app->app_path, scale_factor);
312 } 312 }
313 313
314 base::FilePath ArcAppListPrefs::GetIconPath( 314 base::FilePath ArcAppListPrefs::GetIconPath(
315 const std::string& app_id, 315 const std::string& app_id,
316 ui::ScaleFactor scale_factor) const { 316 ui::ScaleFactor scale_factor) const {
317 return ToIconPath(GetAppPath(app_id), scale_factor); 317 return ToIconPath(GetAppPath(app_id), scale_factor);
318 } 318 }
319 319
320 bool ArcAppListPrefs::IsIconRequestRecorded(
321 const std::string& app_id,
322 ui::ScaleFactor scale_factor) const {
323 const auto iter = request_icon_record_.find(app_id);
324 if (iter == request_icon_record_.end())
325 return false;
326 return iter->second & 1 << scale_factor;
327 }
328
329 void ArcAppListPrefs::MaybeRemoveIconRequestRecord(const std::string& app_id) {
330 request_icon_record_.erase(app_id);
331 }
332
333 void ArcAppListPrefs::ClearIconRequestRecord() {
334 request_icon_record_.clear();
335 }
336
320 void ArcAppListPrefs::RequestIcon(const std::string& app_id, 337 void ArcAppListPrefs::RequestIcon(const std::string& app_id,
321 ui::ScaleFactor scale_factor) { 338 ui::ScaleFactor scale_factor) {
322 // ArcSessionManager can be terminated during test tear down, before callback 339 // ArcSessionManager can be terminated during test tear down, before callback
323 // into this function. 340 // into this function.
324 // TODO(victorhsieh): figure out the best way/place to handle this situation. 341 // TODO(victorhsieh): figure out the best way/place to handle this situation.
325 if (arc::ArcSessionManager::Get() == nullptr) 342 if (arc::ArcSessionManager::Get() == nullptr)
326 return; 343 return;
327 344
328 if (!IsRegistered(app_id)) { 345 if (!IsRegistered(app_id)) {
329 VLOG(2) << "Request to load icon for non-registered app: " << app_id << "."; 346 VLOG(2) << "Request to load icon for non-registered app: " << app_id << ".";
(...skipping 12 matching lines...) Expand all
342 // can happen in browser_tests. 359 // can happen in browser_tests.
343 return; 360 return;
344 } 361 }
345 362
346 std::unique_ptr<AppInfo> app_info = GetApp(app_id); 363 std::unique_ptr<AppInfo> app_info = GetApp(app_id);
347 if (!app_info) { 364 if (!app_info) {
348 VLOG(2) << "Failed to get app info: " << app_id << "."; 365 VLOG(2) << "Failed to get app info: " << app_id << ".";
349 return; 366 return;
350 } 367 }
351 368
369 // This record will prevent ArcAppIcon from resending request to Android for
370 // AppIcon when icon file decode failure is sufferd.
371 request_icon_record_[app_id] =
372 request_icon_record_[app_id] | 1 << scale_factor;
373
352 if (app_info->icon_resource_id.empty()) { 374 if (app_info->icon_resource_id.empty()) {
353 auto* app_instance = 375 auto* app_instance =
354 ARC_GET_INSTANCE_FOR_METHOD(app_instance_holder_, RequestAppIcon); 376 ARC_GET_INSTANCE_FOR_METHOD(app_instance_holder_, RequestAppIcon);
355 // Version 0 instance should always be available here because has_instance() 377 // Version 0 instance should always be available here because has_instance()
356 // returned true above. 378 // returned true above.
357 DCHECK(app_instance); 379 DCHECK(app_instance);
358 app_instance->RequestAppIcon( 380 app_instance->RequestAppIcon(
359 app_info->package_name, app_info->activity, 381 app_info->package_name, app_info->activity,
360 static_cast<arc::mojom::ScaleFactor>(scale_factor)); 382 static_cast<arc::mojom::ScaleFactor>(scale_factor));
361 } else { 383 } else {
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 app_instance->Init(binding_.CreateInterfacePtrAndBind()); 754 app_instance->Init(binding_.CreateInterfacePtrAndBind());
733 app_instance->RefreshAppList(); 755 app_instance->RefreshAppList();
734 } 756 }
735 757
736 void ArcAppListPrefs::OnInstanceClosed() { 758 void ArcAppListPrefs::OnInstanceClosed() {
737 DisableAllApps(); 759 DisableAllApps();
738 installing_packages_count_ = 0; 760 installing_packages_count_ = 0;
739 default_apps_installations_.clear(); 761 default_apps_installations_.clear();
740 detect_default_app_availability_timeout_.Stop(); 762 detect_default_app_availability_timeout_.Stop();
741 binding_.Close(); 763 binding_.Close();
764 ClearIconRequestRecord();
742 765
743 if (sync_service_) { 766 if (sync_service_) {
744 sync_service_->StopSyncing(syncer::ARC_PACKAGE); 767 sync_service_->StopSyncing(syncer::ARC_PACKAGE);
745 sync_service_ = nullptr; 768 sync_service_ = nullptr;
746 } 769 }
747 770
748 is_initialized_ = false; 771 is_initialized_ = false;
749 package_list_initial_refreshed_ = false; 772 package_list_initial_refreshed_ = false;
750 } 773 }
751 774
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 } 878 }
856 } 879 }
857 880
858 void ArcAppListPrefs::RemoveApp(const std::string& app_id) { 881 void ArcAppListPrefs::RemoveApp(const std::string& app_id) {
859 // Delete cached icon if there is any. 882 // Delete cached icon if there is any.
860 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = GetApp(app_id); 883 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = GetApp(app_id);
861 if (app_info && !app_info->icon_resource_id.empty()) { 884 if (app_info && !app_info->icon_resource_id.empty()) {
862 arc::RemoveCachedIcon(app_info->icon_resource_id); 885 arc::RemoveCachedIcon(app_info->icon_resource_id);
863 } 886 }
864 887
888 MaybeRemoveIconRequestRecord(app_id);
889
865 // From now, app is not available. 890 // From now, app is not available.
866 ready_apps_.erase(app_id); 891 ready_apps_.erase(app_id);
867 892
868 // app_id may be released by observers, get the path first. It should be done 893 // app_id may be released by observers, get the path first. It should be done
869 // before removing prefs entry in order not to mix with pre-build default apps 894 // before removing prefs entry in order not to mix with pre-build default apps
870 // files. 895 // files.
871 const base::FilePath app_path = GetAppPath(app_id); 896 const base::FilePath app_path = GetAppPath(app_id);
872 897
873 // Remove from prefs. 898 // Remove from prefs.
874 DictionaryPrefUpdate update(prefs_, prefs::kArcApps); 899 DictionaryPrefUpdate update(prefs_, prefs::kArcApps);
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 int64_t last_backup_android_id, 1431 int64_t last_backup_android_id,
1407 int64_t last_backup_time, 1432 int64_t last_backup_time,
1408 bool should_sync, 1433 bool should_sync,
1409 bool system) 1434 bool system)
1410 : package_name(package_name), 1435 : package_name(package_name),
1411 package_version(package_version), 1436 package_version(package_version),
1412 last_backup_android_id(last_backup_android_id), 1437 last_backup_android_id(last_backup_android_id),
1413 last_backup_time(last_backup_time), 1438 last_backup_time(last_backup_time),
1414 should_sync(should_sync), 1439 should_sync(should_sync),
1415 system(system) {} 1440 system(system) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698