Commit 353879e5 authored by pneubeck's avatar pneubeck Committed by Commit bot

Cleanup the ConfigurationPolicyHandler interface.

After https://codereview.chromium.org/197013007
ConfigurationPolicyHandler provided a default implementation of ApplyPolicySettings() that simply called NOTREACHED.
Also it wasn't clear anymore what of ConfigurationPolicyHandler is the public interface and what is default implementation.

Both issues are resolved with this change.

Review URL: https://codereview.chromium.org/1019283005

Cr-Commit-Position: refs/heads/master@{#322381}
parent 9a424d2e
......@@ -114,3 +114,9 @@ void DownloadDirPolicyHandler::ApplyPolicySettingsWithParameters(
#endif
}
}
void DownloadDirPolicyHandler::ApplyPolicySettings(
const policy::PolicyMap& /* policies */,
PrefValueMap* /* prefs */) {
NOTREACHED();
}
......@@ -30,6 +30,10 @@ class DownloadDirPolicyHandler : public policy::TypeCheckingPolicyHandler {
const policy::PolicyHandlerParameters& parameters,
PrefValueMap* prefs) override;
protected:
void ApplyPolicySettings(const policy::PolicyMap& policies,
PrefValueMap* prefs) override;
private:
DISALLOW_COPY_AND_ASSIGN(DownloadDirPolicyHandler);
};
......
......@@ -48,12 +48,6 @@ ConfigurationPolicyHandler::~ConfigurationPolicyHandler() {
void ConfigurationPolicyHandler::PrepareForDisplaying(
PolicyMap* policies) const {}
void ConfigurationPolicyHandler::ApplyPolicySettings(
const policy::PolicyMap& policies,
PrefValueMap* prefs) {
NOTREACHED();
}
void ConfigurationPolicyHandler::ApplyPolicySettingsWithParameters(
const PolicyMap& policies,
const PolicyHandlerParameters& parameters,
......@@ -466,11 +460,13 @@ bool LegacyPoliciesDeprecatingPolicyHandler::CheckPolicySettings(
}
}
void LegacyPoliciesDeprecatingPolicyHandler::ApplyPolicySettings(
const PolicyMap& policies,
void LegacyPoliciesDeprecatingPolicyHandler::ApplyPolicySettingsWithParameters(
const policy::PolicyMap& policies,
const policy::PolicyHandlerParameters& parameters,
PrefValueMap* prefs) {
if (policies.Get(new_policy_handler_->policy_name())) {
new_policy_handler_->ApplyPolicySettings(policies, prefs);
new_policy_handler_->ApplyPolicySettingsWithParameters(policies, parameters,
prefs);
} else {
// The new policy is not set, fall back to legacy ones.
PolicyErrorMap scoped_errors;
......@@ -478,10 +474,17 @@ void LegacyPoliciesDeprecatingPolicyHandler::ApplyPolicySettings(
for (handler = legacy_policy_handlers_.begin();
handler != legacy_policy_handlers_.end();
++handler) {
if ((*handler)->CheckPolicySettings(policies, &scoped_errors))
(*handler)->ApplyPolicySettings(policies, prefs);
if ((*handler)->CheckPolicySettings(policies, &scoped_errors)) {
(*handler)
->ApplyPolicySettingsWithParameters(policies, parameters, prefs);
}
}
}
}
void LegacyPoliciesDeprecatingPolicyHandler::ApplyPolicySettings(
const policy::PolicyMap& /* policies */,
PrefValueMap* /* prefs */) {
NOTREACHED();
}
} // namespace policy
......@@ -55,18 +55,21 @@ class POLICY_EXPORT ConfigurationPolicyHandler {
const PolicyHandlerParameters& parameters,
PrefValueMap* prefs);
// This is a convenience version of ApplyPolicySettingsWithParameters()
// that leaves out the |parameters|. Anyone extending
// ConfigurationPolicyHandler should implement either ApplyPolicySettings or
// ApplyPolicySettingsWithParameters.
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs);
// Modifies the values of some of the policies in |policies| so that they
// are more suitable to display to the user. This can be used to remove
// sensitive values such as passwords, or to pretty-print values.
virtual void PrepareForDisplaying(PolicyMap* policies) const;
protected:
// This is a convenience version of ApplyPolicySettingsWithParameters()
// for derived classes that leaves out the |parameters|. Anyone extending
// ConfigurationPolicyHandler should implement either
// ApplyPolicySettingsWithParameters directly and implement
// ApplyPolicySettings with a NOTREACHED or implement only
// ApplyPolicySettings.
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyHandler);
};
......@@ -339,6 +342,12 @@ class POLICY_EXPORT LegacyPoliciesDeprecatingPolicyHandler
// ConfigurationPolicyHandler:
bool CheckPolicySettings(const PolicyMap& policies,
PolicyErrorMap* errors) override;
void ApplyPolicySettingsWithParameters(
const policy::PolicyMap& policies,
const policy::PolicyHandlerParameters& parameters,
PrefValueMap* prefs) override;
protected:
void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) override;
......
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