Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: components/policy/core/browser/configuration_policy_handler_list.cc

Issue 2414663002: Fix log spew for "_comment..." policies. (Closed)
Patch Set: Rename EraseGeneric() to FilterErase(). Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/policy/core/browser/configuration_policy_handler_list.h" 5 #include "components/policy/core/browser/configuration_policy_handler_list.h"
6 6
7 #include "base/bind.h"
7 #include "base/stl_util.h" 8 #include "base/stl_util.h"
8 #include "components/policy/core/browser/configuration_policy_handler.h" 9 #include "components/policy/core/browser/configuration_policy_handler.h"
9 #include "components/policy/core/browser/configuration_policy_handler_parameters .h" 10 #include "components/policy/core/browser/configuration_policy_handler_parameters .h"
10 #include "components/policy/core/browser/policy_error_map.h" 11 #include "components/policy/core/browser/policy_error_map.h"
11 #include "components/policy/core/common/policy_map.h"
12 #include "components/prefs/pref_value_map.h" 12 #include "components/prefs/pref_value_map.h"
13 #include "grit/components_strings.h" 13 #include "grit/components_strings.h"
14 14
15 namespace policy { 15 namespace policy {
16
17 namespace {
18
19 // Don't show errors for policies starting with that prefix.
20 const char kPolicyCommentPrefix[] = "_comment";
21
22 } // namespace
23
16 ConfigurationPolicyHandlerList::ConfigurationPolicyHandlerList( 24 ConfigurationPolicyHandlerList::ConfigurationPolicyHandlerList(
17 const PopulatePolicyHandlerParametersCallback& parameters_callback, 25 const PopulatePolicyHandlerParametersCallback& parameters_callback,
18 const GetChromePolicyDetailsCallback& details_callback) 26 const GetChromePolicyDetailsCallback& details_callback)
19 : parameters_callback_(parameters_callback), 27 : parameters_callback_(parameters_callback),
20 details_callback_(details_callback) {} 28 details_callback_(details_callback) {}
21 29
22 ConfigurationPolicyHandlerList::~ConfigurationPolicyHandlerList() { 30 ConfigurationPolicyHandlerList::~ConfigurationPolicyHandlerList() {
23 base::STLDeleteElements(&handlers_); 31 base::STLDeleteElements(&handlers_);
24 } 32 }
25 33
26 void ConfigurationPolicyHandlerList::AddHandler( 34 void ConfigurationPolicyHandlerList::AddHandler(
27 std::unique_ptr<ConfigurationPolicyHandler> handler) { 35 std::unique_ptr<ConfigurationPolicyHandler> handler) {
28 handlers_.push_back(handler.release()); 36 handlers_.push_back(handler.release());
29 } 37 }
30 38
31 void ConfigurationPolicyHandlerList::ApplyPolicySettings( 39 void ConfigurationPolicyHandlerList::ApplyPolicySettings(
32 const PolicyMap& policies, 40 const PolicyMap& policies,
33 PrefValueMap* prefs, 41 PrefValueMap* prefs,
34 PolicyErrorMap* errors) const { 42 PolicyErrorMap* errors) const {
35 // This function is used both to apply the policy settings, and to check them 43 // This function is used both to apply the policy settings, and to check them
36 // and list errors. As such it must get all the errors even if it isn't 44 // and list errors. As such it must get all the errors even if it isn't
37 // applying the policies. 45 // applying the policies.
38 // TODO (aberent) split into two functions. 46 // TODO(aberent): split into two functions.
47 std::unique_ptr<PolicyMap> filtered_policies = policies.DeepCopy();
48 filtered_policies->EraseMatching(
49 base::Bind(&ConfigurationPolicyHandlerList::IsPlatformDevicePolicy,
50 base::Unretained(this)));
51
39 PolicyErrorMap scoped_errors; 52 PolicyErrorMap scoped_errors;
40 if (!errors) 53 if (!errors)
41 errors = &scoped_errors; 54 errors = &scoped_errors;
42 55
43 policy::PolicyHandlerParameters parameters; 56 PolicyHandlerParameters parameters;
44 parameters_callback_.Run(&parameters); 57 parameters_callback_.Run(&parameters);
45 58
46 std::vector<ConfigurationPolicyHandler*>::const_iterator handler; 59 for (auto handler : handlers_) {
47 for (handler = handlers_.begin(); handler != handlers_.end(); ++handler) { 60 if (handler->CheckPolicySettings(*filtered_policies, errors) && prefs) {
48 if ((*handler)->CheckPolicySettings(policies, errors) && prefs) { 61 handler->ApplyPolicySettingsWithParameters(
49 (*handler) 62 *filtered_policies, parameters, prefs);
50 ->ApplyPolicySettingsWithParameters(policies, parameters, prefs);
51 } 63 }
52 } 64 }
53 65
54 for (PolicyMap::const_iterator it = policies.begin(); 66 if (details_callback_) {
55 it != policies.end(); 67 for (PolicyMap::const_iterator it = filtered_policies->begin();
56 ++it) { 68 it != filtered_policies->end();
57 const PolicyDetails* details = 69 ++it) {
58 details_callback_.is_null() ? NULL : details_callback_.Run(it->first); 70 const PolicyDetails* details = details_callback_.Run(it->first);
59 if (details && details->is_deprecated) 71 if (details && details->is_deprecated)
60 errors->AddError(it->first, IDS_POLICY_DEPRECATED); 72 errors->AddError(it->first, IDS_POLICY_DEPRECATED);
73 }
61 } 74 }
62 } 75 }
63 76
64 void ConfigurationPolicyHandlerList::PrepareForDisplaying( 77 void ConfigurationPolicyHandlerList::PrepareForDisplaying(
65 PolicyMap* policies) const { 78 PolicyMap* policies) const {
66 std::vector<ConfigurationPolicyHandler*>::const_iterator handler; 79 for (auto handler : handlers_)
67 for (handler = handlers_.begin(); handler != handlers_.end(); ++handler) 80 handler->PrepareForDisplaying(policies);
68 (*handler)->PrepareForDisplaying(policies); 81 }
82
83 bool ConfigurationPolicyHandlerList::IsPlatformDevicePolicy(
84 const PolicyMap::const_iterator iter) const {
85 // Callback might be missing in tests.
86 if (!details_callback_) {
87 return false;
88 }
89 const PolicyDetails* policy_details = details_callback_.Run(iter->first);
90 if (!policy_details) {
91 const std::string prefix(kPolicyCommentPrefix);
92 if (iter->first.compare(0, prefix.length(), prefix) != 0) {
93 LOG(ERROR) << "Unknown policy: " << iter->first;
94 }
95 return false;
96 }
97 if (iter->second.source == POLICY_SOURCE_PLATFORM &&
98 policy_details->is_device_policy) {
99 // Device Policy is only implemented as Cloud Policy (not Platform Policy).
100 LOG(WARNING) << "Ignoring device platform policy: " << iter->first;
101 return true;
102 }
103 return false;
69 } 104 }
70 105
71 } // namespace policy 106 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698