Commit bf378c04 authored by Melissa Zhang's avatar Melissa Zhang Committed by Commit Bot

Remove deprecated GetBoolean and GetInt in arc_app_list_prefs.cc

BUG=968439

Change-Id: If92868debe3c0a2b1c2532a05e97fa953c50901c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1939148
Commit-Queue: Melissa Zhang <melzhang@chromium.org>
Reviewed-by: default avatarYury Khmel <khmel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728427}
parent 60038851
...@@ -92,10 +92,9 @@ constexpr base::TimeDelta kDetectDefaultAppAvailabilityTimeout = ...@@ -92,10 +92,9 @@ constexpr base::TimeDelta kDetectDefaultAppAvailabilityTimeout =
base::TimeDelta::FromMinutes(1); base::TimeDelta::FromMinutes(1);
// Accessor for deferred set notifications enabled requests in prefs. // Accessor for deferred set notifications enabled requests in prefs.
class SetNotificationsEnabledDeferred { class NotificationsEnabledDeferred {
public: public:
explicit SetNotificationsEnabledDeferred(PrefService* prefs) explicit NotificationsEnabledDeferred(PrefService* prefs) : prefs_(prefs) {}
: prefs_(prefs) {}
void Put(const std::string& app_id, bool enabled) { void Put(const std::string& app_id, bool enabled) {
DictionaryPrefUpdate update( DictionaryPrefUpdate update(
...@@ -104,10 +103,10 @@ class SetNotificationsEnabledDeferred { ...@@ -104,10 +103,10 @@ class SetNotificationsEnabledDeferred {
dict->SetKey(app_id, base::Value(enabled)); dict->SetKey(app_id, base::Value(enabled));
} }
bool Get(const std::string& app_id, bool* enabled) { bool Get(const std::string& app_id) {
const base::DictionaryValue* dict = const base::DictionaryValue* dict =
prefs_->GetDictionary(arc::prefs::kArcSetNotificationsEnabledDeferred); prefs_->GetDictionary(arc::prefs::kArcSetNotificationsEnabledDeferred);
return dict->GetBoolean(app_id, enabled); return dict->FindBoolKey(app_id).value_or(false);
} }
void Remove(const std::string& app_id) { void Remove(const std::string& app_id) {
...@@ -576,7 +575,7 @@ void ArcAppListPrefs::SetNotificationsEnabled(const std::string& app_id, ...@@ -576,7 +575,7 @@ void ArcAppListPrefs::SetNotificationsEnabled(const std::string& app_id,
// In case app is not ready, defer this request. // In case app is not ready, defer this request.
if (!ready_apps_.count(app_id)) { if (!ready_apps_.count(app_id)) {
SetNotificationsEnabledDeferred(prefs_).Put(app_id, enabled); NotificationsEnabledDeferred(prefs_).Put(app_id, enabled);
for (auto& observer : observer_list_) for (auto& observer : observer_list_)
observer.OnNotificationsEnabledChanged(app_info->package_name, enabled); observer.OnNotificationsEnabledChanged(app_info->package_name, enabled);
return; return;
...@@ -587,7 +586,7 @@ void ArcAppListPrefs::SetNotificationsEnabled(const std::string& app_id, ...@@ -587,7 +586,7 @@ void ArcAppListPrefs::SetNotificationsEnabled(const std::string& app_id,
if (!app_instance) if (!app_instance)
return; return;
SetNotificationsEnabledDeferred(prefs_).Remove(app_id); NotificationsEnabledDeferred(prefs_).Remove(app_id);
app_instance->SetNotificationsEnabled(app_info->package_name, enabled); app_instance->SetNotificationsEnabled(app_info->package_name, enabled);
} }
...@@ -626,25 +625,16 @@ std::unique_ptr<ArcAppListPrefs::PackageInfo> ArcAppListPrefs::GetPackage( ...@@ -626,25 +625,16 @@ std::unique_ptr<ArcAppListPrefs::PackageInfo> ArcAppListPrefs::GetPackage(
!packages->GetDictionaryWithoutPathExpansion(package_name, &package)) !packages->GetDictionaryWithoutPathExpansion(package_name, &package))
return std::unique_ptr<PackageInfo>(); return std::unique_ptr<PackageInfo>();
bool uninstalled = false; if (package->FindBoolKey(kUninstalled).value_or(false))
if (package->GetBoolean(kUninstalled, &uninstalled) && uninstalled)
return nullptr; return nullptr;
int32_t package_version = 0;
int64_t last_backup_android_id = 0; int64_t last_backup_android_id = 0;
int64_t last_backup_time = 0; int64_t last_backup_time = 0;
bool should_sync = false;
bool system = false;
bool vpn_provider = false;
base::flat_map<arc::mojom::AppPermission, arc::mojom::PermissionStatePtr> base::flat_map<arc::mojom::AppPermission, arc::mojom::PermissionStatePtr>
permissions; permissions;
GetInt64FromPref(package, kLastBackupAndroidId, &last_backup_android_id); GetInt64FromPref(package, kLastBackupAndroidId, &last_backup_android_id);
GetInt64FromPref(package, kLastBackupTime, &last_backup_time); GetInt64FromPref(package, kLastBackupTime, &last_backup_time);
package->GetInteger(kPackageVersion, &package_version);
package->GetBoolean(kShouldSync, &should_sync);
package->GetBoolean(kSystem, &system);
package->GetBoolean(kVPNProvider, &vpn_provider);
const base::Value* permission_val = package->FindKey(kPermissionStates); const base::Value* permission_val = package->FindKey(kPermissionStates);
if (permission_val) { if (permission_val) {
const base::DictionaryValue* permission_dict = nullptr; const base::DictionaryValue* permission_dict = nullptr;
...@@ -678,8 +668,12 @@ std::unique_ptr<ArcAppListPrefs::PackageInfo> ArcAppListPrefs::GetPackage( ...@@ -678,8 +668,12 @@ std::unique_ptr<ArcAppListPrefs::PackageInfo> ArcAppListPrefs::GetPackage(
} }
return std::make_unique<PackageInfo>( return std::make_unique<PackageInfo>(
package_name, package_version, last_backup_android_id, last_backup_time, package_name, package->FindIntKey(kPackageVersion).value_or(0),
should_sync, system, vpn_provider, std::move(permissions)); last_backup_android_id, last_backup_time,
package->FindBoolKey(kShouldSync).value_or(false),
package->FindBoolKey(kSystem).value_or(false),
package->FindBoolKey(kVPNProvider).value_or(false),
std::move(permissions));
} }
std::vector<std::string> ArcAppListPrefs::GetAppIds() const { std::vector<std::string> ArcAppListPrefs::GetAppIds() const {
...@@ -745,22 +739,16 @@ std::unique_ptr<ArcAppListPrefs::AppInfo> ArcAppListPrefs::GetAppFromPrefs( ...@@ -745,22 +739,16 @@ std::unique_ptr<ArcAppListPrefs::AppInfo> ArcAppListPrefs::GetAppFromPrefs(
std::string activity; std::string activity;
std::string intent_uri; std::string intent_uri;
std::string icon_resource_id; std::string icon_resource_id;
bool suspended = false; bool notifications_enabled =
bool sticky = false; app->FindBoolKey(kNotificationsEnabled).value_or(true);
bool notifications_enabled = true; const bool shortcut = app->FindBoolKey(kShortcut).value_or(false);
bool shortcut = false; const bool launchable = app->FindBoolKey(kLaunchable).value_or(true);
bool launchable = true;
app->GetString(kName, &name); app->GetString(kName, &name);
app->GetString(kPackageName, &package_name); app->GetString(kPackageName, &package_name);
app->GetString(kActivity, &activity); app->GetString(kActivity, &activity);
app->GetString(kIntentUri, &intent_uri); app->GetString(kIntentUri, &intent_uri);
app->GetString(kIconResourceId, &icon_resource_id); app->GetString(kIconResourceId, &icon_resource_id);
app->GetBoolean(kSuspended, &suspended);
app->GetBoolean(kSticky, &sticky);
app->GetBoolean(kNotificationsEnabled, &notifications_enabled);
app->GetBoolean(kShortcut, &shortcut);
app->GetBoolean(kLaunchable, &launchable);
DCHECK(!name.empty()); DCHECK(!name.empty());
DCHECK(!shortcut || activity.empty()); DCHECK(!shortcut || activity.empty());
...@@ -772,14 +760,16 @@ std::unique_ptr<ArcAppListPrefs::AppInfo> ArcAppListPrefs::GetAppFromPrefs( ...@@ -772,14 +760,16 @@ std::unique_ptr<ArcAppListPrefs::AppInfo> ArcAppListPrefs::GetAppFromPrefs(
last_launch_time = base::Time::FromInternalValue(last_launch_time_internal); last_launch_time = base::Time::FromInternalValue(last_launch_time_internal);
} }
bool deferred; const bool deferred = NotificationsEnabledDeferred(prefs_).Get(app_id);
if (SetNotificationsEnabledDeferred(prefs_).Get(app_id, &deferred)) if (deferred)
notifications_enabled = deferred; notifications_enabled = deferred;
return std::make_unique<AppInfo>( return std::make_unique<AppInfo>(
name, package_name, activity, intent_uri, icon_resource_id, name, package_name, activity, intent_uri, icon_resource_id,
last_launch_time, GetInstallTime(app_id), sticky, notifications_enabled, last_launch_time, GetInstallTime(app_id),
ready_apps_.count(app_id) > 0 /* ready */, suspended, app->FindBoolKey(kSticky).value_or(false), notifications_enabled,
ready_apps_.count(app_id) > 0 /* ready */,
app->FindBoolKey(kSuspended).value_or(false),
launchable && arc::ShouldShowInLauncher(app_id), shortcut, launchable); launchable && arc::ShouldShowInLauncher(app_id), shortcut, launchable);
} }
...@@ -1177,11 +1167,10 @@ void ArcAppListPrefs::AddAppAndShortcut(const std::string& name, ...@@ -1177,11 +1167,10 @@ void ArcAppListPrefs::AddAppAndShortcut(const std::string& name,
} }
if (app_ready) { if (app_ready) {
bool deferred_notifications_enabled; const bool deferred_notifications_enabled =
if (SetNotificationsEnabledDeferred(prefs_).Get( NotificationsEnabledDeferred(prefs_).Get(app_id);
app_id, &deferred_notifications_enabled)) { if (deferred_notifications_enabled)
SetNotificationsEnabled(app_id, deferred_notifications_enabled); SetNotificationsEnabled(app_id, deferred_notifications_enabled);
}
// Invalidate app icons in case it was already registered, becomes ready and // Invalidate app icons in case it was already registered, becomes ready and
// icon version is updated. This allows to use previous icons until new // icon version is updated. This allows to use previous icons until new
...@@ -1277,9 +1266,8 @@ void ArcAppListPrefs::AddOrUpdatePackagePrefs( ...@@ -1277,9 +1266,8 @@ void ArcAppListPrefs::AddOrUpdatePackagePrefs(
base::NumberToString(package.last_backup_android_id); base::NumberToString(package.last_backup_android_id);
const std::string time_str = base::NumberToString(package.last_backup_time); const std::string time_str = base::NumberToString(package.last_backup_time);
int old_package_version = -1; int old_package_version =
package_dict->GetInteger(kPackageVersion, &old_package_version); package_dict->FindIntKey(kPackageVersion).value_or(-1);
package_dict->SetBoolean(kShouldSync, package.sync); package_dict->SetBoolean(kShouldSync, package.sync);
package_dict->SetInteger(kPackageVersion, package.package_version); package_dict->SetInteger(kPackageVersion, package.package_version);
package_dict->SetString(kLastBackupAndroidId, id_str); package_dict->SetString(kLastBackupAndroidId, id_str);
...@@ -1538,17 +1526,15 @@ void ArcAppListPrefs::OnUninstallShortcut(const std::string& package_name, ...@@ -1538,17 +1526,15 @@ void ArcAppListPrefs::OnUninstallShortcut(const std::string& package_name,
app_it.Advance()) { app_it.Advance()) {
const base::Value* value = &app_it.value(); const base::Value* value = &app_it.value();
const base::DictionaryValue* app; const base::DictionaryValue* app;
bool shortcut;
std::string installed_package_name; std::string installed_package_name;
std::string installed_intent_uri; std::string installed_intent_uri;
if (!value->GetAsDictionary(&app) || if (!value->GetAsDictionary(&app) ||
!app->GetBoolean(kShortcut, &shortcut) ||
!app->GetString(kPackageName, &installed_package_name) || !app->GetString(kPackageName, &installed_package_name) ||
!app->GetString(kIntentUri, &installed_intent_uri)) { !app->GetString(kIntentUri, &installed_intent_uri)) {
VLOG(2) << "Failed to extract information for " << app_it.key() << "."; VLOG(2) << "Failed to extract information for " << app_it.key() << ".";
continue; continue;
} }
const bool shortcut = app->FindBoolKey(kShortcut).value_or(false);
if (!shortcut || installed_package_name != package_name || if (!shortcut || installed_package_name != package_name ||
installed_intent_uri != intent_uri) { installed_intent_uri != intent_uri) {
continue; continue;
...@@ -1597,15 +1583,13 @@ std::unordered_set<std::string> ArcAppListPrefs::GetAppsAndShortcutsForPackage( ...@@ -1597,15 +1583,13 @@ std::unordered_set<std::string> ArcAppListPrefs::GetAppsAndShortcutsForPackage(
continue; continue;
if (!include_shortcuts) { if (!include_shortcuts) {
bool shortcut = false; if (app->FindBoolKey(kShortcut).value_or(false))
if (app->GetBoolean(kShortcut, &shortcut) && shortcut)
continue; continue;
} }
if (include_only_launchable_apps) { if (include_only_launchable_apps) {
// Filter out non-lauchable apps. // Filter out non-lauchable apps.
bool launchable = false; if (!app->FindBoolKey(kLaunchable).value_or(false))
if (!app->GetBoolean(kLaunchable, &launchable) || !launchable)
continue; continue;
} }
...@@ -1816,8 +1800,8 @@ std::vector<std::string> ArcAppListPrefs::GetPackagesFromPrefs( ...@@ -1816,8 +1800,8 @@ std::vector<std::string> ArcAppListPrefs::GetPackagesFromPrefs(
continue; continue;
} }
bool uninstalled = false; const bool uninstalled =
package_info->GetBoolean(kUninstalled, &uninstalled); package_info->FindBoolKey(kUninstalled).value_or(false);
if (installed != !uninstalled) if (installed != !uninstalled)
continue; continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment