Commit 4aab1e39 authored by Aya ElAttar's avatar Aya ElAttar Committed by Commit Bot

Refactored ListValue to Value in policy handlers

Changed base::ListValue to base::Value according to the new design.

Change-Id: Iadabd65d527eea187ed6f7ecfb767bb8011a0538
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2120574
Commit-Queue: Aya Elsayed <ayaelattar@google.com>
Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753743}
parent b19c3d4d
...@@ -324,11 +324,11 @@ bool PinnedLauncherAppsPolicyHandler::CheckListEntry(const base::Value& value) { ...@@ -324,11 +324,11 @@ bool PinnedLauncherAppsPolicyHandler::CheckListEntry(const base::Value& value) {
return crx_file::id_util::IdIsValid(str); return crx_file::id_util::IdIsValid(str);
} }
void PinnedLauncherAppsPolicyHandler::ApplyList( void PinnedLauncherAppsPolicyHandler::ApplyList(base::Value filtered_list,
std::unique_ptr<base::ListValue> filtered_list, PrefValueMap* prefs) {
PrefValueMap* prefs) { DCHECK(filtered_list.is_list());
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(kPinnedAppsPrefAppIDKey, 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));
......
...@@ -9,15 +9,12 @@ ...@@ -9,15 +9,12 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/values.h"
#include "chrome/browser/extensions/policy_handlers.h" #include "chrome/browser/extensions/policy_handlers.h"
#include "chromeos/network/network_ui_data.h" #include "chromeos/network/network_ui_data.h"
#include "components/onc/onc_constants.h" #include "components/onc/onc_constants.h"
#include "components/policy/core/browser/configuration_policy_handler.h" #include "components/policy/core/browser/configuration_policy_handler.h"
namespace base {
class Value;
}
namespace policy { namespace policy {
class Schema; class Schema;
...@@ -95,8 +92,7 @@ class PinnedLauncherAppsPolicyHandler : public ListPolicyHandler { ...@@ -95,8 +92,7 @@ class PinnedLauncherAppsPolicyHandler : public ListPolicyHandler {
// Converts the list of strings |filtered_list| to a list of dictionaries and // Converts the list of strings |filtered_list| to a list of dictionaries and
// sets the pref. // sets the pref.
void ApplyList(std::unique_ptr<base::ListValue> filtered_list, void ApplyList(base::Value filtered_list, PrefValueMap* prefs) override;
PrefValueMap* prefs) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(PinnedLauncherAppsPolicyHandler); DISALLOW_COPY_AND_ASSIGN(PinnedLauncherAppsPolicyHandler);
......
...@@ -24,10 +24,11 @@ void SystemFeaturesDisableListPolicyHandler::RegisterPrefs( ...@@ -24,10 +24,11 @@ void SystemFeaturesDisableListPolicyHandler::RegisterPrefs(
} }
void SystemFeaturesDisableListPolicyHandler::ApplyList( void SystemFeaturesDisableListPolicyHandler::ApplyList(
std::unique_ptr<base::ListValue> filtered_list, base::Value filtered_list,
PrefValueMap* prefs) { PrefValueMap* prefs) {
DCHECK(filtered_list.is_list());
prefs->SetValue(policy_prefs::kSystemFeaturesDisableList, prefs->SetValue(policy_prefs::kSystemFeaturesDisableList,
base::Value::FromUniquePtrValue(std::move(filtered_list))); std::move(filtered_list));
} }
} // namespace policy } // namespace policy
...@@ -7,11 +7,9 @@ ...@@ -7,11 +7,9 @@
#include <memory> #include <memory>
#include "base/values.h"
#include "components/policy/core/browser/configuration_policy_handler.h" #include "components/policy/core/browser/configuration_policy_handler.h"
namespace base {
class ListValue;
}
class PrefValueMap; class PrefValueMap;
class PrefRegistrySimple; class PrefRegistrySimple;
...@@ -27,8 +25,7 @@ class SystemFeaturesDisableListPolicyHandler ...@@ -27,8 +25,7 @@ class SystemFeaturesDisableListPolicyHandler
protected: protected:
// ListPolicyHandler: // ListPolicyHandler:
void ApplyList(std::unique_ptr<base::ListValue> filtered_list, void ApplyList(base::Value filtered_list, PrefValueMap* prefs) override;
PrefValueMap* prefs) override;
}; };
} // namespace policy } // namespace policy
......
...@@ -28,12 +28,10 @@ bool NativeMessagingHostListPolicyHandler::CheckListEntry( ...@@ -28,12 +28,10 @@ bool NativeMessagingHostListPolicyHandler::CheckListEntry(
return NativeMessagingHostManifest::IsValidName(str); return NativeMessagingHostManifest::IsValidName(str);
} }
void NativeMessagingHostListPolicyHandler::ApplyList( void NativeMessagingHostListPolicyHandler::ApplyList(base::Value filtered_list,
std::unique_ptr<base::ListValue> filtered_list, PrefValueMap* prefs) {
PrefValueMap* prefs) { DCHECK(filtered_list.is_list());
DCHECK(filtered_list); prefs->SetValue(pref_path_, std::move(filtered_list));
prefs->SetValue(pref_path_,
base::Value::FromUniquePtrValue(std::move(filtered_list)));
} }
} // namespace extensions } // namespace extensions
...@@ -29,8 +29,7 @@ class NativeMessagingHostListPolicyHandler : public policy::ListPolicyHandler { ...@@ -29,8 +29,7 @@ class NativeMessagingHostListPolicyHandler : public policy::ListPolicyHandler {
bool CheckListEntry(const base::Value& value) override; bool CheckListEntry(const base::Value& value) override;
// Sets |prefs| at pref_path() to |filtered_list|. // Sets |prefs| at pref_path() to |filtered_list|.
void ApplyList(std::unique_ptr<base::ListValue> filtered_list, void ApplyList(base::Value filtered_list, PrefValueMap* prefs) override;
PrefValueMap* prefs) override;
private: private:
const char* pref_path_; const char* pref_path_;
......
...@@ -66,12 +66,10 @@ bool ExtensionListPolicyHandler::CheckListEntry(const base::Value& value) { ...@@ -66,12 +66,10 @@ bool ExtensionListPolicyHandler::CheckListEntry(const base::Value& value) {
return crx_file::id_util::IdIsValid(str); return crx_file::id_util::IdIsValid(str);
} }
void ExtensionListPolicyHandler::ApplyList( void ExtensionListPolicyHandler::ApplyList(base::Value filtered_list,
std::unique_ptr<base::ListValue> filtered_list, PrefValueMap* prefs) {
PrefValueMap* prefs) { DCHECK(filtered_list.is_list());
DCHECK(filtered_list); prefs->SetValue(pref_path_, std::move(filtered_list));
prefs->SetValue(pref_path_,
base::Value::FromUniquePtrValue(std::move(filtered_list)));
} }
// ExtensionInstallListPolicyHandler implementation ---------------------------- // ExtensionInstallListPolicyHandler implementation ----------------------------
......
...@@ -34,8 +34,7 @@ class ExtensionListPolicyHandler : public policy::ListPolicyHandler { ...@@ -34,8 +34,7 @@ class ExtensionListPolicyHandler : public policy::ListPolicyHandler {
bool CheckListEntry(const base::Value& value) override; bool CheckListEntry(const base::Value& value) override;
// Sets |prefs| at pref_path() to |filtered_list|. // Sets |prefs| at pref_path() to |filtered_list|.
void ApplyList(std::unique_ptr<base::ListValue> filtered_list, void ApplyList(base::Value filtered_list, PrefValueMap* prefs) override;
PrefValueMap* prefs) override;
private: private:
const char* pref_path_; const char* pref_path_;
......
...@@ -156,12 +156,10 @@ bool PrintingAllowedPageSizesPolicyHandler::CheckListEntry( ...@@ -156,12 +156,10 @@ bool PrintingAllowedPageSizesPolicyHandler::CheckListEntry(
return width && height && width->is_int() && height->is_int(); return width && height && width->is_int() && height->is_int();
} }
void PrintingAllowedPageSizesPolicyHandler::ApplyList( void PrintingAllowedPageSizesPolicyHandler::ApplyList(base::Value filtered_list,
std::unique_ptr<base::ListValue> filtered_list, PrefValueMap* prefs) {
PrefValueMap* prefs) { DCHECK(filtered_list.is_list());
DCHECK(filtered_list); prefs->SetValue(prefs::kPrintingAllowedPageSizes, std::move(filtered_list));
prefs->SetValue(prefs::kPrintingAllowedPageSizes,
base::Value::FromUniquePtrValue(std::move(filtered_list)));
} }
PrintingSizeDefaultPolicyHandler::PrintingSizeDefaultPolicyHandler() PrintingSizeDefaultPolicyHandler::PrintingSizeDefaultPolicyHandler()
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "base/values.h"
#include "components/policy/core/browser/configuration_policy_handler.h" #include "components/policy/core/browser/configuration_policy_handler.h"
#include "printing/backend/printing_restrictions.h" #include "printing/backend/printing_restrictions.h"
...@@ -95,8 +96,7 @@ class PrintingAllowedPageSizesPolicyHandler : public ListPolicyHandler { ...@@ -95,8 +96,7 @@ class PrintingAllowedPageSizesPolicyHandler : public ListPolicyHandler {
// ListPolicyHandler implementation: // ListPolicyHandler implementation:
bool CheckListEntry(const base::Value& value) override; bool CheckListEntry(const base::Value& value) override;
void ApplyList(std::unique_ptr<base::ListValue> filtered_list, void ApplyList(base::Value filtered_list, PrefValueMap* prefs) override;
PrefValueMap* prefs) override;
}; };
class PrintingSizeDefaultPolicyHandler : public TypeCheckingPolicyHandler { class PrintingSizeDefaultPolicyHandler : public TypeCheckingPolicyHandler {
......
...@@ -93,18 +93,14 @@ bool ListPolicyHandler::CheckPolicySettings(const policy::PolicyMap& policies, ...@@ -93,18 +93,14 @@ bool ListPolicyHandler::CheckPolicySettings(const policy::PolicyMap& policies,
void ListPolicyHandler::ApplyPolicySettings(const policy::PolicyMap& policies, void ListPolicyHandler::ApplyPolicySettings(const policy::PolicyMap& policies,
PrefValueMap* prefs) { PrefValueMap* prefs) {
std::unique_ptr<base::ListValue> list; base::Value list(base::Value::Type::NONE);
if (CheckAndGetList(policies, nullptr, &list) && list) if (CheckAndGetList(policies, nullptr, &list) && list.is_list())
ApplyList(std::move(list), prefs); ApplyList(std::move(list), prefs);
} }
bool ListPolicyHandler::CheckAndGetList( bool ListPolicyHandler::CheckAndGetList(const policy::PolicyMap& policies,
const policy::PolicyMap& policies, policy::PolicyErrorMap* errors,
policy::PolicyErrorMap* errors, base::Value* filtered_list) {
std::unique_ptr<base::ListValue>* filtered_list) {
if (filtered_list)
filtered_list->reset();
const base::Value* value = nullptr; const base::Value* value = nullptr;
if (!CheckAndGetValue(policies, errors, &value)) if (!CheckAndGetValue(policies, errors, &value))
return false; return false;
...@@ -115,7 +111,7 @@ bool ListPolicyHandler::CheckAndGetList( ...@@ -115,7 +111,7 @@ bool ListPolicyHandler::CheckAndGetList(
// Filter the list, rejecting any invalid strings. // Filter the list, rejecting any invalid strings.
base::Value::ConstListView list = value->GetList(); base::Value::ConstListView list = value->GetList();
if (filtered_list) if (filtered_list)
*filtered_list = std::make_unique<base::ListValue>(); *filtered_list = base::Value(base::Value::Type::LIST);
for (size_t list_index = 0; list_index < list.size(); ++list_index) { for (size_t list_index = 0; list_index < list.size(); ++list_index) {
const base::Value& entry = list[list_index]; const base::Value& entry = list[list_index];
if (entry.type() != list_entry_type_) { if (entry.type() != list_entry_type_) {
...@@ -135,7 +131,7 @@ bool ListPolicyHandler::CheckAndGetList( ...@@ -135,7 +131,7 @@ bool ListPolicyHandler::CheckAndGetList(
} }
if (filtered_list) if (filtered_list)
(*filtered_list)->Append(entry.CreateDeepCopy()); filtered_list->Append(entry.Clone());
} }
return true; return true;
......
...@@ -128,8 +128,7 @@ class POLICY_EXPORT ListPolicyHandler : public TypeCheckingPolicyHandler { ...@@ -128,8 +128,7 @@ class POLICY_EXPORT ListPolicyHandler : public TypeCheckingPolicyHandler {
// Implement this method to apply the |filtered_list| of values of type // Implement this method to apply the |filtered_list| of values of type
// |list_entry_type_| as returned from CheckAndGetList() to |prefs|. // |list_entry_type_| as returned from CheckAndGetList() to |prefs|.
virtual void ApplyList(std::unique_ptr<base::ListValue> filtered_list, virtual void ApplyList(base::Value filtered_list, PrefValueMap* prefs) = 0;
PrefValueMap* prefs) = 0;
private: private:
// Checks whether the policy value is indeed a list, filters out all entries // Checks whether the policy value is indeed a list, filters out all entries
...@@ -138,7 +137,7 @@ class POLICY_EXPORT ListPolicyHandler : public TypeCheckingPolicyHandler { ...@@ -138,7 +137,7 @@ class POLICY_EXPORT ListPolicyHandler : public TypeCheckingPolicyHandler {
// filtered list entries if |errors| is not nullptr. // filtered list entries if |errors| is not nullptr.
bool CheckAndGetList(const policy::PolicyMap& policies, bool CheckAndGetList(const policy::PolicyMap& policies,
policy::PolicyErrorMap* errors, policy::PolicyErrorMap* errors,
std::unique_ptr<base::ListValue>* filtered_list); base::Value* filtered_list);
// Expected value type for list entries. All other types are filtered out. // Expected value type for list entries. All other types are filtered out.
base::Value::Type list_entry_type_; base::Value::Type list_entry_type_;
......
...@@ -115,11 +115,9 @@ class StringListPolicyHandler : public ListPolicyHandler { ...@@ -115,11 +115,9 @@ class StringListPolicyHandler : public ListPolicyHandler {
: ListPolicyHandler(kPolicyName, base::Value::Type::STRING) {} : ListPolicyHandler(kPolicyName, base::Value::Type::STRING) {}
protected: protected:
void ApplyList(std::unique_ptr<base::ListValue> filtered_list, void ApplyList(base::Value filtered_list, PrefValueMap* prefs) override {
PrefValueMap* prefs) override { DCHECK(filtered_list.is_list());
DCHECK(filtered_list); prefs->SetValue(kTestPref, std::move(filtered_list));
prefs->SetValue(kTestPref,
base::Value::FromUniquePtrValue(std::move(filtered_list)));
} }
}; };
......
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