Home | History | Annotate | Download | only in browser
      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
      3 // found in the LICENSE file.
      4 
      5 #include "components/policy/core/browser/configuration_policy_handler_list.h"
      6 
      7 #include "base/prefs/pref_value_map.h"
      8 #include "base/stl_util.h"
      9 #include "components/policy/core/browser/configuration_policy_handler.h"
     10 #include "components/policy/core/browser/configuration_policy_handler_parameters.h"
     11 #include "components/policy/core/browser/policy_error_map.h"
     12 #include "components/policy/core/common/policy_map.h"
     13 #include "grit/components_strings.h"
     14 
     15 namespace policy {
     16 ConfigurationPolicyHandlerList::ConfigurationPolicyHandlerList(
     17     const PopulatePolicyHandlerParametersCallback& parameters_callback,
     18     const GetChromePolicyDetailsCallback& details_callback)
     19     : parameters_callback_(parameters_callback),
     20       details_callback_(details_callback) {}
     21 
     22 ConfigurationPolicyHandlerList::~ConfigurationPolicyHandlerList() {
     23   STLDeleteElements(&handlers_);
     24 }
     25 
     26 void ConfigurationPolicyHandlerList::AddHandler(
     27     scoped_ptr<ConfigurationPolicyHandler> handler) {
     28   handlers_.push_back(handler.release());
     29 }
     30 
     31 void ConfigurationPolicyHandlerList::ApplyPolicySettings(
     32     const PolicyMap& policies,
     33     PrefValueMap* prefs,
     34     PolicyErrorMap* errors) const {
     35   PolicyErrorMap scoped_errors;
     36   if (!errors)
     37     errors = &scoped_errors;
     38 
     39   policy::PolicyHandlerParameters parameters;
     40   parameters_callback_.Run(&parameters);
     41 
     42   std::vector<ConfigurationPolicyHandler*>::const_iterator handler;
     43   for (handler = handlers_.begin(); handler != handlers_.end(); ++handler) {
     44     if ((*handler)->CheckPolicySettings(policies, errors) && prefs)
     45       (*handler)
     46           ->ApplyPolicySettingsWithParameters(policies, parameters, prefs);
     47   }
     48 
     49   for (PolicyMap::const_iterator it = policies.begin();
     50        it != policies.end();
     51        ++it) {
     52     const PolicyDetails* details =
     53         details_callback_.is_null() ? NULL : details_callback_.Run(it->first);
     54     if (details && details->is_deprecated)
     55       errors->AddError(it->first, IDS_POLICY_DEPRECATED);
     56   }
     57 }
     58 
     59 void ConfigurationPolicyHandlerList::PrepareForDisplaying(
     60     PolicyMap* policies) const {
     61   std::vector<ConfigurationPolicyHandler*>::const_iterator handler;
     62   for (handler = handlers_.begin(); handler != handlers_.end(); ++handler)
     63     (*handler)->PrepareForDisplaying(policies);
     64 }
     65 
     66 }  // namespace policy
     67