1a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// found in the LICENSE file. 4a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 5a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/browser/configuration_policy_handler_list.h" 6a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/prefs/pref_value_map.h" 8a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/stl_util.h" 9a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/browser/configuration_policy_handler.h" 10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/policy/core/browser/configuration_policy_handler_parameters.h" 11a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/browser/policy_error_map.h" 12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/common/policy_map.h" 13cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "grit/components_strings.h" 14a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 15a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)namespace policy { 16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)ConfigurationPolicyHandlerList::ConfigurationPolicyHandlerList( 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const PopulatePolicyHandlerParametersCallback& parameters_callback, 18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const GetChromePolicyDetailsCallback& details_callback) 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) : parameters_callback_(parameters_callback), 20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) details_callback_(details_callback) {} 21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)ConfigurationPolicyHandlerList::~ConfigurationPolicyHandlerList() { 23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) STLDeleteElements(&handlers_); 24a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 25a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void ConfigurationPolicyHandlerList::AddHandler( 27a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) scoped_ptr<ConfigurationPolicyHandler> handler) { 28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) handlers_.push_back(handler.release()); 29a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void ConfigurationPolicyHandlerList::ApplyPolicySettings( 32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const PolicyMap& policies, 33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) PrefValueMap* prefs, 34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) PolicyErrorMap* errors) const { 35a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) PolicyErrorMap scoped_errors; 36a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (!errors) 37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) errors = &scoped_errors; 38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) policy::PolicyHandlerParameters parameters; 40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) parameters_callback_.Run(¶meters); 41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 42a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::vector<ConfigurationPolicyHandler*>::const_iterator handler; 43a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) for (handler = handlers_.begin(); handler != handlers_.end(); ++handler) { 44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if ((*handler)->CheckPolicySettings(policies, errors) && prefs) 45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) (*handler) 46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ->ApplyPolicySettingsWithParameters(policies, parameters, prefs); 47a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 49a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) for (PolicyMap::const_iterator it = policies.begin(); 50a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) it != policies.end(); 51a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ++it) { 52a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const PolicyDetails* details = 53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) details_callback_.is_null() ? NULL : details_callback_.Run(it->first); 54a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (details && details->is_deprecated) 55a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) errors->AddError(it->first, IDS_POLICY_DEPRECATED); 56a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 57a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 58a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 59a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void ConfigurationPolicyHandlerList::PrepareForDisplaying( 60a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) PolicyMap* policies) const { 61a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::vector<ConfigurationPolicyHandler*>::const_iterator handler; 62a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) for (handler = handlers_.begin(); handler != handlers_.end(); ++handler) 63a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) (*handler)->PrepareForDisplaying(policies); 64a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 65a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 66a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} // namespace policy 67