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