Chromium Code Reviews| Index: chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc |
| diff --git a/chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc b/chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc |
| index 7f26aebf6837da738501491d471c22827472b5fa..24d0ea990d67751c6fbdc76aef542eaae72cd032 100644 |
| --- a/chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc |
| +++ b/chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc |
| @@ -600,8 +600,7 @@ void ArcAppListPrefs::AddAppAndShortcut( |
| const arc::mojom::OrientationLock orientation_lock) { |
| std::string app_id = shortcut ? GetAppId(package_name, intent_uri) |
| : GetAppId(package_name, activity); |
| - bool was_registered = IsRegistered(app_id); |
| - |
| + const bool was_registered = IsRegistered(app_id); |
| if (was_registered) { |
| std::unique_ptr<ArcAppListPrefs::AppInfo> app_old_info = GetApp(app_id); |
| if (name != app_old_info->name) { |
| @@ -623,12 +622,15 @@ void ArcAppListPrefs::AddAppAndShortcut( |
| app_dict->SetInteger(kOrientationLock, static_cast<int>(orientation_lock)); |
| // From now, app is available. |
| - if (!ready_apps_.count(app_id)) |
| + const bool was_disable = ready_apps_.count(app_id) == 0; |
|
Luis Héctor Chávez
2016/08/09 17:25:02
nit: was_disabled
khmel
2016/08/09 17:46:39
Done.
|
| + if (was_disable) |
| ready_apps_.insert(app_id); |
| if (was_registered) { |
| - FOR_EACH_OBSERVER(Observer, observer_list_, |
| - OnAppReadyChanged(app_id, true)); |
| + if (was_disable) { |
| + FOR_EACH_OBSERVER(Observer, observer_list_, |
| + OnAppReadyChanged(app_id, true)); |
| + } |
| } else { |
| AppInfo app_info(name, package_name, activity, intent_uri, icon_resource_id, |
| base::Time(), sticky, notifications_enabled, true, |
| @@ -722,7 +724,7 @@ void ArcAppListPrefs::OnTaskOrientationLockRequested( |
| OnTaskOrientationLockRequested(task_id, orientation_lock)); |
| } |
| -void ArcAppListPrefs::OnAppAdded(arc::mojom::AppInfoPtr app) { |
| +void ArcAppListPrefs::OnAppAddedDeprecated(arc::mojom::AppInfoPtr app) { |
| if ((app->name.get().empty() || app->package_name.get().empty() || |
| app->activity.get().empty())) { |
| VLOG(2) << "App Name, package name, and activity cannot be empty."; |
| @@ -736,6 +738,23 @@ void ArcAppListPrefs::OnAppAdded(arc::mojom::AppInfoPtr app) { |
| app->orientation_lock); |
| } |
| +void ArcAppListPrefs::OnPackageAppListRefreshed( |
| + const mojo::String& package_name, |
| + mojo::Array<arc::mojom::AppInfoPtr> apps) { |
| + std::set<std::string> apps_to_remove = GetAppsForPackage(package_name); |
| + for (const auto& app : apps) { |
| + apps_to_remove.erase(GetAppId(app->package_name, app->activity)); |
| + AddAppAndShortcut(app->name, app->package_name, app->activity, |
|
Luis Héctor Chávez
2016/08/09 17:25:02
Don't you also want to do the validation in L728?
khmel
2016/08/09 17:46:39
Done
|
| + std::string() /* intent_uri */, |
| + std::string() /* icon_resource_id */, app->sticky, |
| + app->notifications_enabled, false /* shortcut */, |
| + app->orientation_lock); |
| + } |
| + |
| + for (const auto& app_id : apps_to_remove) |
| + RemoveApp(app_id); |
| +} |
| + |
| void ArcAppListPrefs::OnInstallShortcut(arc::mojom::ShortcutInfoPtr shortcut) { |
| if ((shortcut->name.get().empty() || shortcut->intent_uri.get().empty())) { |
| VLOG(2) << "Shortcut Name, and intent_uri cannot be empty."; |
| @@ -749,9 +768,10 @@ void ArcAppListPrefs::OnInstallShortcut(arc::mojom::ShortcutInfoPtr shortcut) { |
| arc::mojom::OrientationLock::NONE); |
| } |
| -void ArcAppListPrefs::OnPackageRemoved(const mojo::String& package_name) { |
| +std::set<std::string> ArcAppListPrefs::GetAppsForPackage( |
|
Luis Héctor Chávez
2016/08/09 17:25:02
std::unordered_set?
|
| + const std::string& package_name) const { |
| + std::set<std::string> app_set; |
| const base::DictionaryValue* apps = prefs_->GetDictionary(prefs::kArcApps); |
| - std::vector<std::string> apps_to_remove; |
| for (base::DictionaryValue::Iterator app_it(*apps); !app_it.IsAtEnd(); |
| app_it.Advance()) { |
| const base::Value* value = &app_it.value(); |
| @@ -770,10 +790,15 @@ void ArcAppListPrefs::OnPackageRemoved(const mojo::String& package_name) { |
| if (package_name != app_package) |
| continue; |
| - apps_to_remove.push_back(app_it.key()); |
| + app_set.insert(app_it.key()); |
| } |
| - for (auto& app_id : apps_to_remove) |
| + return app_set; |
| +} |
| + |
| +void ArcAppListPrefs::OnPackageRemoved(const mojo::String& package_name) { |
| + const std::set<std::string> apps_to_remove = GetAppsForPackage(package_name); |
| + for (const auto& app_id : apps_to_remove) |
| RemoveApp(app_id); |
| RemovePackageFromPrefs(prefs_, package_name); |