Commit 776ed071 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Clean up some policy code.

- Remove PolicyUIHandler::AddLocalizedPolicyStrings() and use
  AddLocalizedStringsBulk().
- Remove policy::PolicyStringMap and use LocalizedString.
- Remove uses of "policy::" inside namespace policy.
- Use auto in more places for iterators.
- Fix lint errors.

Change-Id: I68a9939431769fe50197ff1b160756be3348c79b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626740Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662614}
parent 585914c8
This diff is collapsed.
......@@ -6,8 +6,10 @@
#define CHROME_BROWSER_POLICY_POLICY_CONVERSIONS_H_
#include <memory>
#include <string>
#include "base/values.h"
#include "chrome/browser/ui/webui/localized_string.h"
#include "components/policy/core/common/policy_types.h"
namespace content {
......@@ -16,12 +18,7 @@ class BrowserContext;
namespace policy {
struct PolicyStringMap {
const char* key;
int string_id;
};
extern const PolicyStringMap kPolicySources[policy::POLICY_SOURCE_COUNT];
extern const LocalizedString kPolicySources[POLICY_SOURCE_COUNT];
// Returns an array with the values of all set policies, with some values
// converted to be shown in javascript, if it is specified.
......
......@@ -620,18 +620,10 @@ PolicyUIHandler::~PolicyUIHandler() {
#endif
}
void PolicyUIHandler::AddLocalizedPolicyStrings(
content::WebUIDataSource* source,
const policy::PolicyStringMap* strings,
size_t count) {
for (size_t i = 0; i < count; ++i)
source->AddLocalizedString(strings[i].key, strings[i].string_id);
}
void PolicyUIHandler::AddCommonLocalizedStringsToSource(
content::WebUIDataSource* source) {
AddLocalizedPolicyStrings(source, policy::kPolicySources,
static_cast<size_t>(policy::POLICY_SOURCE_COUNT));
AddLocalizedStringsBulk(source, policy::kPolicySources,
policy::POLICY_SOURCE_COUNT);
static constexpr LocalizedString kStrings[] = {
{"conflict", IDS_POLICY_LABEL_CONFLICT},
......@@ -800,8 +792,8 @@ base::Value PolicyUIHandler::GetPolicyNames() const {
auto chrome_policy_names = std::make_unique<base::ListValue>();
policy::PolicyNamespace chrome_ns(policy::POLICY_DOMAIN_CHROME, "");
const policy::Schema* chrome_schema = schema_map->GetSchema(chrome_ns);
for (policy::Schema::Iterator it = chrome_schema->GetPropertiesIterator();
!it.IsAtEnd(); it.Advance()) {
for (auto it = chrome_schema->GetPropertiesIterator(); !it.IsAtEnd();
it.Advance()) {
chrome_policy_names->GetList().push_back(base::Value(it.key()));
}
auto chrome_values = std::make_unique<base::DictionaryValue>();
......@@ -826,8 +818,8 @@ base::Value PolicyUIHandler::GetPolicyNames() const {
if (schema && schema->valid()) {
// Get policy names from the extension's policy schema.
// Store in a map, not an array, for faster lookup on JS side.
for (policy::Schema::Iterator prop = schema->GetPropertiesIterator();
!prop.IsAtEnd(); prop.Advance()) {
for (auto prop = schema->GetPropertiesIterator(); !prop.IsAtEnd();
prop.Advance()) {
policy_names->GetList().push_back(base::Value(prop.key()));
}
}
......
......@@ -9,6 +9,7 @@
#include <string.h>
#include <memory>
#include <string>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
......@@ -27,10 +28,6 @@
#include "extensions/browser/extension_registry_observer.h"
#endif
namespace policy {
struct PolicyStringMap;
} // namespace policy
class PolicyStatusProvider;
// The JavaScript message handler for the chrome://policy page.
......@@ -45,10 +42,6 @@ class PolicyUIHandler : public content::WebUIMessageHandler,
PolicyUIHandler();
~PolicyUIHandler() override;
static void AddLocalizedPolicyStrings(content::WebUIDataSource* source,
const policy::PolicyStringMap* strings,
size_t count);
static void AddCommonLocalizedStringsToSource(
content::WebUIDataSource* source);
......@@ -73,7 +66,6 @@ class PolicyUIHandler : public content::WebUIMessageHandler,
void OnSchemaRegistryUpdated(bool has_new_schemas) override;
protected:
// ui::SelectFileDialog::Listener implementation.
void FileSelected(const base::FilePath& path,
int index,
......
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