Commit c061c2c6 authored by Pavol Marko's avatar Pavol Marko Committed by Commit Bot

Rename kPinnedAppsPrefAppIDPath to kPinnedAppsPrefAppIDKey

To be consistent with usage of base::Value::SetKey (as opposed to
base::Value::SetPath).

Bug: none
Change-Id: I07648205e14cb17a22409d11cd5d3737f53e01e8
Reviewed-on: https://chromium-review.googlesource.com/c/1449577Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Pavol Marko <pmarko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629918}
parent e49b2555
...@@ -351,7 +351,7 @@ void PinnedLauncherAppsPolicyHandler::ApplyList( ...@@ -351,7 +351,7 @@ void PinnedLauncherAppsPolicyHandler::ApplyList(
std::vector<base::Value> pinned_apps_list; std::vector<base::Value> pinned_apps_list;
for (const base::Value& entry : filtered_list->GetList()) { for (const base::Value& entry : filtered_list->GetList()) {
base::Value app_dict(base::Value::Type::DICTIONARY); base::Value app_dict(base::Value::Type::DICTIONARY);
app_dict.SetKey(kPinnedAppsPrefAppIDPath, entry.Clone()); app_dict.SetKey(kPinnedAppsPrefAppIDKey, entry.Clone());
pinned_apps_list.push_back(std::move(app_dict)); pinned_apps_list.push_back(std::move(app_dict));
} }
prefs->SetValue(prefs::kPolicyPinnedLauncherApps, prefs->SetValue(prefs::kPolicyPinnedLauncherApps,
......
...@@ -310,14 +310,14 @@ TEST(PinnedLauncherAppsPolicyHandler, PrefTranslation) { ...@@ -310,14 +310,14 @@ TEST(PinnedLauncherAppsPolicyHandler, PrefTranslation) {
// Extension IDs are OK. // Extension IDs are OK.
base::Value entry1("abcdefghijklmnopabcdefghijklmnop"); base::Value entry1("abcdefghijklmnopabcdefghijklmnop");
auto entry1_dict = std::make_unique<base::DictionaryValue>(); auto entry1_dict = std::make_unique<base::DictionaryValue>();
entry1_dict->Set(kPinnedAppsPrefAppIDPath, entry1.CreateDeepCopy()); entry1_dict->Set(kPinnedAppsPrefAppIDKey, entry1.CreateDeepCopy());
expected_pinned_apps.Append(std::move(entry1_dict)); expected_pinned_apps.Append(std::move(entry1_dict));
list.Append(entry1.CreateDeepCopy()); list.Append(entry1.CreateDeepCopy());
// Android appds are OK. // Android appds are OK.
base::Value entry2("com.google.android.gm"); base::Value entry2("com.google.android.gm");
auto entry2_dict = std::make_unique<base::DictionaryValue>(); auto entry2_dict = std::make_unique<base::DictionaryValue>();
entry2_dict->Set(kPinnedAppsPrefAppIDPath, entry2.CreateDeepCopy()); entry2_dict->Set(kPinnedAppsPrefAppIDKey, entry2.CreateDeepCopy());
expected_pinned_apps.Append(std::move(entry2_dict)); expected_pinned_apps.Append(std::move(entry2_dict));
list.Append(entry2.CreateDeepCopy()); list.Append(entry2.CreateDeepCopy());
......
...@@ -76,7 +76,7 @@ struct ComparePinInfo { ...@@ -76,7 +76,7 @@ struct ComparePinInfo {
} // namespace } // namespace
const char kPinnedAppsPrefAppIDPath[] = "id"; const char kPinnedAppsPrefAppIDKey[] = "id";
void RegisterChromeLauncherUserPrefs(PrefRegistrySimple* registry) { void RegisterChromeLauncherUserPrefs(PrefRegistrySimple* registry) {
registry->RegisterListPref(prefs::kPolicyPinnedLauncherApps); registry->RegisterListPref(prefs::kPolicyPinnedLauncherApps);
...@@ -107,14 +107,17 @@ std::vector<std::string> GetAppsPinnedByPolicy( ...@@ -107,14 +107,17 @@ std::vector<std::string> GetAppsPinnedByPolicy(
arc_app_list_pref ? arc_app_list_pref->GetAppIds() arc_app_list_pref ? arc_app_list_pref->GetAppIds()
: std::vector<std::string>()); : std::vector<std::string>());
std::string app_id; for (const auto& policy_apps_entry : policy_apps->GetList()) {
for (size_t i = 0; i < policy_apps->GetSize(); ++i) { const base::Value* app_id_value =
const base::DictionaryValue* dictionary = nullptr; policy_apps_entry.is_dict()
if (!policy_apps->GetDictionary(i, &dictionary) || ? policy_apps_entry.FindKeyOfType(kPinnedAppsPrefAppIDKey,
!dictionary->GetString(kPinnedAppsPrefAppIDPath, &app_id)) { base::Value::Type::STRING)
: nullptr;
if (!app_id_value) {
LOG(ERROR) << "Cannot extract policy app info from prefs."; LOG(ERROR) << "Cannot extract policy app info from prefs.";
continue; continue;
} }
const std::string app_id = app_id_value->GetString();
if (chromeos::DemoSession::Get() && if (chromeos::DemoSession::Get() &&
chromeos::DemoSession::Get()->ShouldIgnorePinPolicy(app_id)) { chromeos::DemoSession::Get()->ShouldIgnorePinPolicy(app_id)) {
......
...@@ -14,9 +14,9 @@ class PrefRegistrySimple; ...@@ -14,9 +14,9 @@ class PrefRegistrySimple;
class PrefService; class PrefService;
class Profile; class Profile;
// Path within the dictionary entries in the prefs::kPinnedLauncherApps list // Key for the dictionary entries in the prefs::kPinnedLauncherApps list
// specifying the extension ID of the app to be pinned by that entry. // specifying the extension ID of the app to be pinned by that entry.
extern const char kPinnedAppsPrefAppIDPath[]; extern const char kPinnedAppsPrefAppIDKey[];
extern const char kPinnedAppsPrefPinnedByPolicy[]; extern const char kPinnedAppsPrefPinnedByPolicy[];
......
...@@ -718,12 +718,11 @@ class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { ...@@ -718,12 +718,11 @@ class ChromeLauncherControllerTest : public BrowserWithTestWindowTest {
base::WrapUnique<LauncherControllerHelper>(helper)); base::WrapUnique<LauncherControllerHelper>(helper));
} }
void InsertPrefValue(base::ListValue* pref_value, void AppendPrefValue(base::ListValue* pref_value,
int index,
const std::string& extension_id) { const std::string& extension_id) {
auto entry = std::make_unique<base::DictionaryValue>(); base::DictionaryValue entry;
entry->SetString(kPinnedAppsPrefAppIDPath, extension_id); entry.SetKey(kPinnedAppsPrefAppIDKey, base::Value(extension_id));
pref_value->Insert(index, std::move(entry)); pref_value->GetList().push_back(std::move(entry));
} }
void InsertRemoveAllPinsChange(syncer::SyncChangeList* list) { void InsertRemoveAllPinsChange(syncer::SyncChangeList* list) {
...@@ -1514,8 +1513,8 @@ TEST_F(ChromeLauncherControllerTest, MergePolicyAndUserPrefPinnedApps) { ...@@ -1514,8 +1513,8 @@ TEST_F(ChromeLauncherControllerTest, MergePolicyAndUserPrefPinnedApps) {
base::ListValue policy_value; base::ListValue policy_value;
// extension 2 4 are pinned by policy // extension 2 4 are pinned by policy
InsertPrefValue(&policy_value, 0, extension2_->id()); AppendPrefValue(&policy_value, extension2_->id());
InsertPrefValue(&policy_value, 1, extensionDocApp_->id()); AppendPrefValue(&policy_value, extensionDocApp_->id());
profile()->GetTestingPrefService()->SetManagedPref( profile()->GetTestingPrefService()->SetManagedPref(
prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy()); prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy());
...@@ -2980,8 +2979,8 @@ TEST_F(ChromeLauncherControllerTest, Policy) { ...@@ -2980,8 +2979,8 @@ TEST_F(ChromeLauncherControllerTest, Policy) {
// Pin policy should be initilized before controller start. // Pin policy should be initilized before controller start.
base::ListValue policy_value; base::ListValue policy_value;
InsertPrefValue(&policy_value, 0, extension1_->id()); AppendPrefValue(&policy_value, extension1_->id());
InsertPrefValue(&policy_value, 1, extension2_->id()); AppendPrefValue(&policy_value, extension2_->id());
profile()->GetTestingPrefService()->SetManagedPref( profile()->GetTestingPrefService()->SetManagedPref(
prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy()); prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy());
...@@ -3906,7 +3905,7 @@ TEST_F(ChromeLauncherControllerWithArcTest, ArcAppPinPolicy) { ...@@ -3906,7 +3905,7 @@ TEST_F(ChromeLauncherControllerWithArcTest, ArcAppPinPolicy) {
// package_name (not hash) specified as id. In this test we check that // package_name (not hash) specified as id. In this test we check that
// by hash we can determine that appropriate package was set by policy. // by hash we can determine that appropriate package was set by policy.
base::ListValue policy_value; base::ListValue policy_value;
InsertPrefValue(&policy_value, 0, appinfo.package_name); AppendPrefValue(&policy_value, appinfo.package_name);
profile()->GetTestingPrefService()->SetManagedPref( profile()->GetTestingPrefService()->SetManagedPref(
prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy()); prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy());
...@@ -4568,8 +4567,8 @@ TEST_F(ChromeLauncherControllerDemoModeTest, PinnedAppsOnline) { ...@@ -4568,8 +4567,8 @@ TEST_F(ChromeLauncherControllerDemoModeTest, PinnedAppsOnline) {
extension_service_->AddExtension(extension1_.get()); extension_service_->AddExtension(extension1_.get());
extension_service_->AddExtension(extension2_.get()); extension_service_->AddExtension(extension2_.get());
InsertPrefValue(&policy_value, 0, extension1_->id()); AppendPrefValue(&policy_value, extension1_->id());
InsertPrefValue(&policy_value, 1, extension2_->id()); AppendPrefValue(&policy_value, extension2_->id());
arc::mojom::AppInfo appinfo = arc::mojom::AppInfo appinfo =
CreateAppInfo("Some App", "SomeActivity", "com.example.app"); CreateAppInfo("Some App", "SomeActivity", "com.example.app");
...@@ -4580,8 +4579,8 @@ TEST_F(ChromeLauncherControllerDemoModeTest, PinnedAppsOnline) { ...@@ -4580,8 +4579,8 @@ TEST_F(ChromeLauncherControllerDemoModeTest, PinnedAppsOnline) {
const std::string online_only_app_id = const std::string online_only_app_id =
AddArcAppAndShortcut(online_only_appinfo); AddArcAppAndShortcut(online_only_appinfo);
InsertPrefValue(&policy_value, 2, appinfo.package_name); AppendPrefValue(&policy_value, appinfo.package_name);
InsertPrefValue(&policy_value, 3, online_only_appinfo.package_name); AppendPrefValue(&policy_value, online_only_appinfo.package_name);
// If the device is offline, extension2 and onlineonly should be unpinned. // If the device is offline, extension2 and onlineonly should be unpinned.
chromeos::DemoSession::Get()->OverrideIgnorePinPolicyAppsForTesting( chromeos::DemoSession::Get()->OverrideIgnorePinPolicyAppsForTesting(
...@@ -4618,8 +4617,8 @@ TEST_F(ChromeLauncherControllerDemoModeTest, PinnedAppsOffline) { ...@@ -4618,8 +4617,8 @@ TEST_F(ChromeLauncherControllerDemoModeTest, PinnedAppsOffline) {
extension_service_->AddExtension(extension1_.get()); extension_service_->AddExtension(extension1_.get());
extension_service_->AddExtension(extension2_.get()); extension_service_->AddExtension(extension2_.get());
InsertPrefValue(&policy_value, 0, extension1_->id()); AppendPrefValue(&policy_value, extension1_->id());
InsertPrefValue(&policy_value, 1, extension2_->id()); AppendPrefValue(&policy_value, extension2_->id());
arc::mojom::AppInfo appinfo = arc::mojom::AppInfo appinfo =
CreateAppInfo("Some App", "SomeActivity", "com.example.app"); CreateAppInfo("Some App", "SomeActivity", "com.example.app");
...@@ -4630,8 +4629,8 @@ TEST_F(ChromeLauncherControllerDemoModeTest, PinnedAppsOffline) { ...@@ -4630,8 +4629,8 @@ TEST_F(ChromeLauncherControllerDemoModeTest, PinnedAppsOffline) {
const std::string online_only_app_id = const std::string online_only_app_id =
AddArcAppAndShortcut(online_only_appinfo); AddArcAppAndShortcut(online_only_appinfo);
InsertPrefValue(&policy_value, 2, appinfo.package_name); AppendPrefValue(&policy_value, appinfo.package_name);
InsertPrefValue(&policy_value, 3, online_only_appinfo.package_name); AppendPrefValue(&policy_value, online_only_appinfo.package_name);
// If the device is offline, extension2 and onlineonly should be unpinned. // If the device is offline, extension2 and onlineonly should be unpinned.
chromeos::DemoSession::Get()->OverrideIgnorePinPolicyAppsForTesting( chromeos::DemoSession::Get()->OverrideIgnorePinPolicyAppsForTesting(
......
...@@ -49,7 +49,7 @@ AppListControllerDelegate::Pinnable GetPinnableForAppID( ...@@ -49,7 +49,7 @@ AppListControllerDelegate::Pinnable GetPinnableForAppID(
const base::DictionaryValue* app = nullptr; const base::DictionaryValue* app = nullptr;
std::string app_id_or_package; std::string app_id_or_package;
if (pref->GetDictionary(index, &app) && if (pref->GetDictionary(index, &app) &&
app->GetString(kPinnedAppsPrefAppIDPath, &app_id_or_package) && app->GetString(kPinnedAppsPrefAppIDKey, &app_id_or_package) &&
(app_id == app_id_or_package || (app_id == app_id_or_package ||
arc_app_package_name == app_id_or_package)) { arc_app_package_name == app_id_or_package)) {
if (chromeos::DemoSession::Get() && if (chromeos::DemoSession::Get() &&
......
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