Index: components/policy/core/browser/configuration_policy_handler_list.cc |
diff --git a/components/policy/core/browser/configuration_policy_handler_list.cc b/components/policy/core/browser/configuration_policy_handler_list.cc |
index 9cdfc2aa897fbef1cd53f97489786ad6347eed67..1e9937372d1c46d25de6dfdfa6ae92fc4f685471 100644 |
--- a/components/policy/core/browser/configuration_policy_handler_list.cc |
+++ b/components/policy/core/browser/configuration_policy_handler_list.cc |
@@ -4,15 +4,23 @@ |
#include "components/policy/core/browser/configuration_policy_handler_list.h" |
+#include "base/bind.h" |
#include "base/stl_util.h" |
#include "components/policy/core/browser/configuration_policy_handler.h" |
#include "components/policy/core/browser/configuration_policy_handler_parameters.h" |
#include "components/policy/core/browser/policy_error_map.h" |
-#include "components/policy/core/common/policy_map.h" |
#include "components/prefs/pref_value_map.h" |
#include "grit/components_strings.h" |
namespace policy { |
+ |
+namespace { |
+ |
+// Don't show errors for policies starting with that prefix. |
+const char kPolicyCommentPrefix[] = "_comment"; |
+ |
+} // namespace |
+ |
ConfigurationPolicyHandlerList::ConfigurationPolicyHandlerList( |
const PopulatePolicyHandlerParametersCallback& parameters_callback, |
const GetChromePolicyDetailsCallback& details_callback) |
@@ -35,37 +43,64 @@ void ConfigurationPolicyHandlerList::ApplyPolicySettings( |
// This function is used both to apply the policy settings, and to check them |
// and list errors. As such it must get all the errors even if it isn't |
// applying the policies. |
- // TODO (aberent) split into two functions. |
+ // TODO(aberent): split into two functions. |
+ std::unique_ptr<PolicyMap> filtered_policies = policies.DeepCopy(); |
+ filtered_policies->EraseMatching( |
+ base::Bind(&ConfigurationPolicyHandlerList::IsPlatformDevicePolicy, |
+ base::Unretained(this))); |
+ |
PolicyErrorMap scoped_errors; |
if (!errors) |
errors = &scoped_errors; |
- policy::PolicyHandlerParameters parameters; |
+ PolicyHandlerParameters parameters; |
parameters_callback_.Run(¶meters); |
- std::vector<ConfigurationPolicyHandler*>::const_iterator handler; |
- for (handler = handlers_.begin(); handler != handlers_.end(); ++handler) { |
- if ((*handler)->CheckPolicySettings(policies, errors) && prefs) { |
- (*handler) |
- ->ApplyPolicySettingsWithParameters(policies, parameters, prefs); |
+ for (auto handler : handlers_) { |
+ if (handler->CheckPolicySettings(*filtered_policies, errors) && prefs) { |
+ handler->ApplyPolicySettingsWithParameters( |
+ *filtered_policies, parameters, prefs); |
} |
} |
- for (PolicyMap::const_iterator it = policies.begin(); |
- it != policies.end(); |
- ++it) { |
- const PolicyDetails* details = |
- details_callback_.is_null() ? NULL : details_callback_.Run(it->first); |
- if (details && details->is_deprecated) |
- errors->AddError(it->first, IDS_POLICY_DEPRECATED); |
+ if (details_callback_) { |
+ for (PolicyMap::const_iterator it = filtered_policies->begin(); |
+ it != filtered_policies->end(); |
+ ++it) { |
+ const PolicyDetails* details = details_callback_.Run(it->first); |
+ if (details && details->is_deprecated) |
+ errors->AddError(it->first, IDS_POLICY_DEPRECATED); |
+ } |
} |
} |
void ConfigurationPolicyHandlerList::PrepareForDisplaying( |
PolicyMap* policies) const { |
- std::vector<ConfigurationPolicyHandler*>::const_iterator handler; |
- for (handler = handlers_.begin(); handler != handlers_.end(); ++handler) |
- (*handler)->PrepareForDisplaying(policies); |
+ for (auto handler : handlers_) |
+ handler->PrepareForDisplaying(policies); |
+} |
+ |
+bool ConfigurationPolicyHandlerList::IsPlatformDevicePolicy( |
+ const PolicyMap::const_iterator iter) const { |
+ // Callback might be missing in tests. |
+ if (!details_callback_) { |
+ return false; |
+ } |
+ const PolicyDetails* policy_details = details_callback_.Run(iter->first); |
+ if (!policy_details) { |
+ const std::string prefix(kPolicyCommentPrefix); |
+ if (iter->first.compare(0, prefix.length(), prefix) != 0) { |
+ LOG(ERROR) << "Unknown policy: " << iter->first; |
+ } |
+ return false; |
+ } |
+ if (iter->second.source == POLICY_SOURCE_PLATFORM && |
+ policy_details->is_device_policy) { |
+ // Device Policy is only implemented as Cloud Policy (not Platform Policy). |
+ LOG(WARNING) << "Ignoring device platform policy: " << iter->first; |
+ return true; |
+ } |
+ return false; |
} |
} // namespace policy |