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

Side by Side Diff: chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc

Issue 2763753003: [Merge To M58]Fix Default icon issue when cached icon file is corrupted. (Closed)
Patch Set: Rebase. 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 297
298 return ToIconPath(default_app->app_path, scale_factor); 298 return ToIconPath(default_app->app_path, scale_factor);
299 } 299 }
300 300
301 base::FilePath ArcAppListPrefs::GetIconPath( 301 base::FilePath ArcAppListPrefs::GetIconPath(
302 const std::string& app_id, 302 const std::string& app_id,
303 ui::ScaleFactor scale_factor) const { 303 ui::ScaleFactor scale_factor) const {
304 return ToIconPath(GetAppPath(app_id), scale_factor); 304 return ToIconPath(GetAppPath(app_id), scale_factor);
305 } 305 }
306 306
307 bool ArcAppListPrefs::IsIconRequestRecorded(
308 const std::string& app_id,
309 ui::ScaleFactor scale_factor) const {
310 const auto iter = request_icon_recorded_.find(app_id);
311 if (iter == request_icon_recorded_.end())
312 return false;
313 return iter->second & (1 << scale_factor);
314 }
315
316 void ArcAppListPrefs::MaybeRemoveIconRequestRecord(const std::string& app_id) {
317 request_icon_recorded_.erase(app_id);
318 }
319
320 void ArcAppListPrefs::ClearIconRequestRecord() {
321 request_icon_recorded_.clear();
322 }
323
307 void ArcAppListPrefs::RequestIcon(const std::string& app_id, 324 void ArcAppListPrefs::RequestIcon(const std::string& app_id,
308 ui::ScaleFactor scale_factor) { 325 ui::ScaleFactor scale_factor) {
309 if (!IsRegistered(app_id)) { 326 if (!IsRegistered(app_id)) {
310 VLOG(2) << "Request to load icon for non-registered app: " << app_id << "."; 327 VLOG(2) << "Request to load icon for non-registered app: " << app_id << ".";
311 return; 328 return;
312 } 329 }
313 330
314 // In case app is not ready, defer this request. 331 // In case app is not ready, recorded request will be send to ARC when app
315 if (!ready_apps_.count(app_id)) { 332 // becomes ready.
316 request_icon_deferred_[app_id] = 333 // This record will prevent ArcAppIcon from resending request to ARC for app
317 request_icon_deferred_[app_id] | 1 << scale_factor; 334 // icon when icon file decode failure is suffered in case app sends bad icon.
335 request_icon_recorded_[app_id] |= (1 << scale_factor);
336
337 if (!ready_apps_.count(app_id))
318 return; 338 return;
319 }
320 339
321 if (!app_instance_holder_->has_instance()) { 340 if (!app_instance_holder_->has_instance()) {
322 // AppInstance should be ready since we have app_id in ready_apps_. This 341 // AppInstance should be ready since we have app_id in ready_apps_. This
323 // can happen in browser_tests. 342 // can happen in browser_tests.
324 return; 343 return;
325 } 344 }
326 345
327 std::unique_ptr<AppInfo> app_info = GetApp(app_id); 346 std::unique_ptr<AppInfo> app_info = GetApp(app_id);
328 if (!app_info) { 347 if (!app_info) {
329 VLOG(2) << "Failed to get app info: " << app_id << "."; 348 VLOG(2) << "Failed to get app info: " << app_id << ".";
(...skipping 15 matching lines...) Expand all
345 if (!app_instance) 364 if (!app_instance)
346 return; // The instance version on ARC side was too old. 365 return; // The instance version on ARC side was too old.
347 app_instance->RequestIcon( 366 app_instance->RequestIcon(
348 app_info->icon_resource_id, 367 app_info->icon_resource_id,
349 static_cast<arc::mojom::ScaleFactor>(scale_factor), 368 static_cast<arc::mojom::ScaleFactor>(scale_factor),
350 base::Bind(&ArcAppListPrefs::OnIcon, base::Unretained(this), app_id, 369 base::Bind(&ArcAppListPrefs::OnIcon, base::Unretained(this), app_id,
351 static_cast<arc::mojom::ScaleFactor>(scale_factor))); 370 static_cast<arc::mojom::ScaleFactor>(scale_factor)));
352 } 371 }
353 } 372 }
354 373
374 void ArcAppListPrefs::MaybeRequestIcon(const std::string& app_id,
375 ui::ScaleFactor scale_factor) {
376 if (!IsIconRequestRecorded(app_id, scale_factor))
377 RequestIcon(app_id, scale_factor);
378 }
379
355 void ArcAppListPrefs::SetNotificationsEnabled(const std::string& app_id, 380 void ArcAppListPrefs::SetNotificationsEnabled(const std::string& app_id,
356 bool enabled) { 381 bool enabled) {
357 if (!IsRegistered(app_id)) { 382 if (!IsRegistered(app_id)) {
358 VLOG(2) << "Request to set notifications enabled flag for non-registered " 383 VLOG(2) << "Request to set notifications enabled flag for non-registered "
359 << "app:" << app_id << "."; 384 << "app:" << app_id << ".";
360 return; 385 return;
361 } 386 }
362 387
363 std::unique_ptr<AppInfo> app_info = GetApp(app_id); 388 std::unique_ptr<AppInfo> app_info = GetApp(app_id);
364 if (!app_info) { 389 if (!app_info) {
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 app_instance->Init(binding_.CreateInterfacePtrAndBind()); 722 app_instance->Init(binding_.CreateInterfacePtrAndBind());
698 app_instance->RefreshAppList(); 723 app_instance->RefreshAppList();
699 } 724 }
700 725
701 void ArcAppListPrefs::OnInstanceClosed() { 726 void ArcAppListPrefs::OnInstanceClosed() {
702 DisableAllApps(); 727 DisableAllApps();
703 installing_packages_count_ = 0; 728 installing_packages_count_ = 0;
704 default_apps_installations_.clear(); 729 default_apps_installations_.clear();
705 detect_default_app_availability_timeout_.Stop(); 730 detect_default_app_availability_timeout_.Stop();
706 binding_.Close(); 731 binding_.Close();
732 ClearIconRequestRecord();
707 733
708 if (sync_service_) { 734 if (sync_service_) {
709 sync_service_->StopSyncing(syncer::ARC_PACKAGE); 735 sync_service_->StopSyncing(syncer::ARC_PACKAGE);
710 sync_service_ = nullptr; 736 sync_service_ = nullptr;
711 } 737 }
712 738
713 is_initialized_ = false; 739 is_initialized_ = false;
714 package_list_initial_refreshed_ = false; 740 package_list_initial_refreshed_ = false;
715 } 741 }
716 742
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 icon_resource_id, base::Time(), GetInstallTime(app_id), 821 icon_resource_id, base::Time(), GetInstallTime(app_id),
796 sticky, notifications_enabled, true, 822 sticky, notifications_enabled, true,
797 launchable && arc::ShouldShowInLauncher(app_id), shortcut, 823 launchable && arc::ShouldShowInLauncher(app_id), shortcut,
798 launchable, orientation_lock); 824 launchable, orientation_lock);
799 for (auto& observer : observer_list_) 825 for (auto& observer : observer_list_)
800 observer.OnAppRegistered(app_id, app_info); 826 observer.OnAppRegistered(app_id, app_info);
801 tracked_apps_.insert(app_id); 827 tracked_apps_.insert(app_id);
802 } 828 }
803 829
804 if (app_ready) { 830 if (app_ready) {
805 auto deferred_icons = request_icon_deferred_.find(app_id); 831 auto pending_icons = request_icon_recorded_.find(app_id);
806 if (deferred_icons != request_icon_deferred_.end()) { 832 if (pending_icons != request_icon_recorded_.end()) {
807 for (uint32_t i = ui::SCALE_FACTOR_100P; i < ui::NUM_SCALE_FACTORS; ++i) { 833 for (uint32_t i = ui::SCALE_FACTOR_100P; i < ui::NUM_SCALE_FACTORS; ++i) {
808 if (deferred_icons->second & (1 << i)) { 834 if (pending_icons->second & (1 << i)) {
809 RequestIcon(app_id, static_cast<ui::ScaleFactor>(i)); 835 RequestIcon(app_id, static_cast<ui::ScaleFactor>(i));
810 } 836 }
811 } 837 }
812 request_icon_deferred_.erase(deferred_icons);
813 } 838 }
814 839
815 bool deferred_notifications_enabled; 840 bool deferred_notifications_enabled;
816 if (SetNotificationsEnabledDeferred(prefs_).Get( 841 if (SetNotificationsEnabledDeferred(prefs_).Get(
817 app_id, &deferred_notifications_enabled)) { 842 app_id, &deferred_notifications_enabled)) {
818 SetNotificationsEnabled(app_id, deferred_notifications_enabled); 843 SetNotificationsEnabled(app_id, deferred_notifications_enabled);
819 } 844 }
820 } 845 }
821 } 846 }
822 847
823 void ArcAppListPrefs::RemoveApp(const std::string& app_id) { 848 void ArcAppListPrefs::RemoveApp(const std::string& app_id) {
824 // Delete cached icon if there is any. 849 // Delete cached icon if there is any.
825 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = GetApp(app_id); 850 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = GetApp(app_id);
826 if (app_info && !app_info->icon_resource_id.empty()) { 851 if (app_info && !app_info->icon_resource_id.empty()) {
827 arc::RemoveCachedIcon(app_info->icon_resource_id); 852 arc::RemoveCachedIcon(app_info->icon_resource_id);
828 } 853 }
829 854
855 MaybeRemoveIconRequestRecord(app_id);
856
830 // From now, app is not available. 857 // From now, app is not available.
831 ready_apps_.erase(app_id); 858 ready_apps_.erase(app_id);
832 859
833 // app_id may be released by observers, get the path first. It should be done 860 // app_id may be released by observers, get the path first. It should be done
834 // before removing prefs entry in order not to mix with pre-build default apps 861 // before removing prefs entry in order not to mix with pre-build default apps
835 // files. 862 // files.
836 const base::FilePath app_path = GetAppPath(app_id); 863 const base::FilePath app_path = GetAppPath(app_id);
837 864
838 // Remove from prefs. 865 // Remove from prefs.
839 DictionaryPrefUpdate update(prefs_, prefs::kArcApps); 866 DictionaryPrefUpdate update(prefs_, prefs::kArcApps);
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 int64_t last_backup_android_id, 1399 int64_t last_backup_android_id,
1373 int64_t last_backup_time, 1400 int64_t last_backup_time,
1374 bool should_sync, 1401 bool should_sync,
1375 bool system) 1402 bool system)
1376 : package_name(package_name), 1403 : package_name(package_name),
1377 package_version(package_version), 1404 package_version(package_version),
1378 last_backup_android_id(last_backup_android_id), 1405 last_backup_android_id(last_backup_android_id),
1379 last_backup_time(last_backup_time), 1406 last_backup_time(last_backup_time),
1380 should_sync(should_sync), 1407 should_sync(should_sync),
1381 system(system) {} 1408 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