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

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