Home | History | Annotate | Download | only in policy
      1 // Copyright (c) 2013 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 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_IMPL_H_
      6 #define CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_IMPL_H_
      7 
      8 #include "chrome/browser/chromeos/policy/network_configuration_updater.h"
      9 #include "chrome/browser/policy/policy_service.h"
     10 #include "chromeos/network/onc/onc_constants.h"
     11 
     12 namespace base {
     13 class Value;
     14 }
     15 
     16 namespace chromeos {
     17 namespace onc {
     18 class CertificateImporter;
     19 }
     20 }
     21 
     22 namespace policy {
     23 
     24 class PolicyMap;
     25 
     26 // This implementation pushes policies to the
     27 // ManagedNetworkConfigurationHandler. User policies are only pushed after
     28 // OnUserPolicyInitialized() was called.
     29 class NetworkConfigurationUpdaterImpl : public NetworkConfigurationUpdater,
     30                                         public PolicyService::Observer {
     31  public:
     32   NetworkConfigurationUpdaterImpl(
     33       PolicyService* device_policy_service,
     34       scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer);
     35   virtual ~NetworkConfigurationUpdaterImpl();
     36 
     37   // NetworkConfigurationUpdater overrides.
     38   virtual void SetUserPolicyService(
     39       bool allow_trusted_certs_from_policy,
     40       const std::string& hashed_username,
     41       PolicyService* user_policy_service) OVERRIDE;
     42 
     43   virtual void UnsetUserPolicyService() OVERRIDE;
     44 
     45   // PolicyService::Observer overrides for both device and user policies.
     46   virtual void OnPolicyUpdated(const PolicyNamespace& ns,
     47                                const PolicyMap& previous,
     48                                const PolicyMap& current) OVERRIDE;
     49   virtual void OnPolicyServiceInitialized(PolicyDomain domain) OVERRIDE;
     50 
     51   private:
     52    // Called if the ONC policy from |onc_source| changed.
     53    void OnPolicyChanged(chromeos::onc::ONCSource onc_source,
     54                         const base::Value* previous,
     55                         const base::Value* current);
     56 
     57    void ApplyNetworkConfiguration(chromeos::onc::ONCSource onc_source);
     58 
     59    // Used to register for notifications from the |user_policy_service_|.
     60    scoped_ptr<PolicyChangeRegistrar> user_policy_change_registrar_;
     61 
     62    // Used to register for notifications from the |device_policy_service_|.
     63    PolicyChangeRegistrar device_policy_change_registrar_;
     64 
     65    // Used to retrieve user policies.
     66    PolicyService* user_policy_service_;
     67 
     68    // Used to retrieve device policies.
     69    PolicyService* device_policy_service_;
     70 
     71    // User hash of the user that the user policy applies to.
     72    std::string hashed_username_;
     73 
     74    scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_;
     75 
     76    DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationUpdaterImpl);
     77 };
     78 
     79 }  // namespace policy
     80 
     81 #endif  // CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_IMPL_H_
     82