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

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: Nits fix. 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_recorded_.find(app_id);
324 if (iter == request_icon_recorded_.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_recorded_.erase(app_id);
331 }
332
333 void ArcAppListPrefs::ClearIconRequestRecord() {
334 request_icon_recorded_.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 << ".";
330 return; 347 return;
331 } 348 }
332 349
333 // In case app is not ready, defer this request. 350 // In case app is not ready, recorded request will be send to ARC when app
334 if (!ready_apps_.count(app_id)) { 351 // becomes ready.
335 request_icon_deferred_[app_id] = 352 // This record will prevent ArcAppIcon from resending request to ARC for app
336 request_icon_deferred_[app_id] | 1 << scale_factor; 353 // icon when icon file decode failure is suffered in case app sends bad icon.
354 request_icon_recorded_[app_id] |= (1 << scale_factor);
355
356 if (!ready_apps_.count(app_id))
337 return; 357 return;
338 }
339 358
340 if (!app_instance_holder_->has_instance()) { 359 if (!app_instance_holder_->has_instance()) {
341 // AppInstance should be ready since we have app_id in ready_apps_. This 360 // AppInstance should be ready since we have app_id in ready_apps_. This
342 // can happen in browser_tests. 361 // can happen in browser_tests.
343 return; 362 return;
344 } 363 }
345 364
346 std::unique_ptr<AppInfo> app_info = GetApp(app_id); 365 std::unique_ptr<AppInfo> app_info = GetApp(app_id);
347 if (!app_info) { 366 if (!app_info) {
348 VLOG(2) << "Failed to get app info: " << app_id << "."; 367 VLOG(2) << "Failed to get app info: " << app_id << ".";
(...skipping 15 matching lines...) Expand all
364 if (!app_instance) 383 if (!app_instance)
365 return; // The instance version on ARC side was too old. 384 return; // The instance version on ARC side was too old.
366 app_instance->RequestIcon( 385 app_instance->RequestIcon(
367 app_info->icon_resource_id, 386 app_info->icon_resource_id,
368 static_cast<arc::mojom::ScaleFactor>(scale_factor), 387 static_cast<arc::mojom::ScaleFactor>(scale_factor),
369 base::Bind(&ArcAppListPrefs::OnIcon, base::Unretained(this), app_id, 388 base::Bind(&ArcAppListPrefs::OnIcon, base::Unretained(this), app_id,
370 static_cast<arc::mojom::ScaleFactor>(scale_factor))); 389 static_cast<arc::mojom::ScaleFactor>(scale_factor)));
371 } 390 }
372 } 391 }
373 392
393 void ArcAppListPrefs::MaybeRequestIcon(const std::string& app_id,
394 ui::ScaleFactor scale_factor) {
395 if (!IsIconRequestRecorded(app_id, scale_factor))
396 RequestIcon(app_id, scale_factor);
397 }
398
374 void ArcAppListPrefs::SetNotificationsEnabled(const std::string& app_id, 399 void ArcAppListPrefs::SetNotificationsEnabled(const std::string& app_id,
375 bool enabled) { 400 bool enabled) {
376 if (!IsRegistered(app_id)) { 401 if (!IsRegistered(app_id)) {
377 VLOG(2) << "Request to set notifications enabled flag for non-registered " 402 VLOG(2) << "Request to set notifications enabled flag for non-registered "
378 << "app:" << app_id << "."; 403 << "app:" << app_id << ".";
379 return; 404 return;
380 } 405 }
381 406
382 std::unique_ptr<AppInfo> app_info = GetApp(app_id); 407 std::unique_ptr<AppInfo> app_info = GetApp(app_id);
383 if (!app_info) { 408 if (!app_info) {
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 app_instance->Init(binding_.CreateInterfacePtrAndBind()); 757 app_instance->Init(binding_.CreateInterfacePtrAndBind());
733 app_instance->RefreshAppList(); 758 app_instance->RefreshAppList();
734 } 759 }
735 760
736 void ArcAppListPrefs::OnInstanceClosed() { 761 void ArcAppListPrefs::OnInstanceClosed() {
737 DisableAllApps(); 762 DisableAllApps();
738 installing_packages_count_ = 0; 763 installing_packages_count_ = 0;
739 default_apps_installations_.clear(); 764 default_apps_installations_.clear();
740 detect_default_app_availability_timeout_.Stop(); 765 detect_default_app_availability_timeout_.Stop();
741 binding_.Close(); 766 binding_.Close();
767 ClearIconRequestRecord();
742 768
743 if (sync_service_) { 769 if (sync_service_) {
744 sync_service_->StopSyncing(syncer::ARC_PACKAGE); 770 sync_service_->StopSyncing(syncer::ARC_PACKAGE);
745 sync_service_ = nullptr; 771 sync_service_ = nullptr;
746 } 772 }
747 773
748 is_initialized_ = false; 774 is_initialized_ = false;
749 package_list_initial_refreshed_ = false; 775 package_list_initial_refreshed_ = false;
750 } 776 }
751 777
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 icon_resource_id, base::Time(), GetInstallTime(app_id), 856 icon_resource_id, base::Time(), GetInstallTime(app_id),
831 sticky, notifications_enabled, true, 857 sticky, notifications_enabled, true,
832 launchable && arc::ShouldShowInLauncher(app_id), shortcut, 858 launchable && arc::ShouldShowInLauncher(app_id), shortcut,
833 launchable, orientation_lock); 859 launchable, orientation_lock);
834 for (auto& observer : observer_list_) 860 for (auto& observer : observer_list_)
835 observer.OnAppRegistered(app_id, app_info); 861 observer.OnAppRegistered(app_id, app_info);
836 tracked_apps_.insert(app_id); 862 tracked_apps_.insert(app_id);
837 } 863 }
838 864
839 if (app_ready) { 865 if (app_ready) {
840 auto deferred_icons = request_icon_deferred_.find(app_id); 866 auto pending_icons = request_icon_recorded_.find(app_id);
841 if (deferred_icons != request_icon_deferred_.end()) { 867 if (pending_icons != request_icon_recorded_.end()) {
842 for (uint32_t i = ui::SCALE_FACTOR_100P; i < ui::NUM_SCALE_FACTORS; ++i) { 868 for (uint32_t i = ui::SCALE_FACTOR_100P; i < ui::NUM_SCALE_FACTORS; ++i) {
843 if (deferred_icons->second & (1 << i)) { 869 if (pending_icons->second & (1 << i)) {
844 RequestIcon(app_id, static_cast<ui::ScaleFactor>(i)); 870 RequestIcon(app_id, static_cast<ui::ScaleFactor>(i));
845 } 871 }
846 } 872 }
847 request_icon_deferred_.erase(deferred_icons);
848 } 873 }
849 874
850 bool deferred_notifications_enabled; 875 bool deferred_notifications_enabled;
851 if (SetNotificationsEnabledDeferred(prefs_).Get( 876 if (SetNotificationsEnabledDeferred(prefs_).Get(
852 app_id, &deferred_notifications_enabled)) { 877 app_id, &deferred_notifications_enabled)) {
853 SetNotificationsEnabled(app_id, deferred_notifications_enabled); 878 SetNotificationsEnabled(app_id, deferred_notifications_enabled);
854 } 879 }
855 } 880 }
856 } 881 }
857 882
858 void ArcAppListPrefs::RemoveApp(const std::string& app_id) { 883 void ArcAppListPrefs::RemoveApp(const std::string& app_id) {
859 // Delete cached icon if there is any. 884 // Delete cached icon if there is any.
860 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = GetApp(app_id); 885 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = GetApp(app_id);
861 if (app_info && !app_info->icon_resource_id.empty()) { 886 if (app_info && !app_info->icon_resource_id.empty()) {
862 arc::RemoveCachedIcon(app_info->icon_resource_id); 887 arc::RemoveCachedIcon(app_info->icon_resource_id);
863 } 888 }
864 889
890 MaybeRemoveIconRequestRecord(app_id);
891
865 // From now, app is not available. 892 // From now, app is not available.
866 ready_apps_.erase(app_id); 893 ready_apps_.erase(app_id);
867 894
868 // app_id may be released by observers, get the path first. It should be done 895 // 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 896 // before removing prefs entry in order not to mix with pre-build default apps
870 // files. 897 // files.
871 const base::FilePath app_path = GetAppPath(app_id); 898 const base::FilePath app_path = GetAppPath(app_id);
872 899
873 // Remove from prefs. 900 // Remove from prefs.
874 DictionaryPrefUpdate update(prefs_, prefs::kArcApps); 901 DictionaryPrefUpdate update(prefs_, prefs::kArcApps);
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 int64_t last_backup_android_id, 1433 int64_t last_backup_android_id,
1407 int64_t last_backup_time, 1434 int64_t last_backup_time,
1408 bool should_sync, 1435 bool should_sync,
1409 bool system) 1436 bool system)
1410 : package_name(package_name), 1437 : package_name(package_name),
1411 package_version(package_version), 1438 package_version(package_version),
1412 last_backup_android_id(last_backup_android_id), 1439 last_backup_android_id(last_backup_android_id),
1413 last_backup_time(last_backup_time), 1440 last_backup_time(last_backup_time),
1414 should_sync(should_sync), 1441 should_sync(should_sync),
1415 system(system) {} 1442 system(system) {}
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_list_prefs.h ('k') | chrome/browser/ui/app_list/arc/arc_app_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698