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#ifndef CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_IMPL_CROS_H_ 6#define CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_IMPL_CROS_H_ 7 8#include <string> 9 10#include "chrome/browser/chromeos/cros/network_constants.h" 11#include "chrome/browser/chromeos/cros/network_library.h" 12#include "chrome/browser/chromeos/policy/network_configuration_updater.h" 13#include "chrome/browser/policy/policy_service.h" 14#include "chromeos/network/network_ui_data.h" 15#include "chromeos/network/onc/onc_constants.h" 16 17namespace base { 18class Value; 19} 20 21namespace chromeos { 22namespace onc { 23class CertificateImporter; 24} 25} 26 27namespace policy { 28 29class PolicyMap; 30 31// DEPRECATED: will be replaced by NetworkConfigurationImpl. 32// This implementation pushes policies through the NetworkLibrary. It applies 33// network policies every time one of the relevant policies or Shill's profiles 34// changed or OnUserPolicyInitialized() is called. If the user policy is 35// available, always both the device and the user policy are applied. Otherwise 36// only the device policy is applied. 37class NetworkConfigurationUpdaterImplCros 38 : public NetworkConfigurationUpdater, 39 public chromeos::NetworkLibrary::NetworkProfileObserver, 40 public PolicyService::Observer { 41 public: 42 // The pointer |device_policy_service| is stored. The caller must guarantee 43 // that it's outliving the updater. 44 NetworkConfigurationUpdaterImplCros( 45 PolicyService* device_policy_service, 46 chromeos::NetworkLibrary* network_library, 47 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer); 48 virtual ~NetworkConfigurationUpdaterImplCros(); 49 50 // NetworkProfileObserver overrides. 51 virtual void OnProfileListChanged() OVERRIDE; 52 53 // NetworkConfigurationUpdater overrides. 54 55 // In this implementation, this function applies both device and user policy. 56 virtual void SetUserPolicyService( 57 bool allow_trusted_certs_from_policy, 58 const std::string& hashed_username, 59 PolicyService* user_policy_service) OVERRIDE; 60 61 virtual void UnsetUserPolicyService() OVERRIDE; 62 63 // PolicyService::Observer overrides for both device and user policies. 64 virtual void OnPolicyUpdated(const PolicyNamespace& ns, 65 const PolicyMap& previous, 66 const PolicyMap& current) OVERRIDE; 67 virtual void OnPolicyServiceInitialized(PolicyDomain domain) OVERRIDE; 68 69 private: 70 // Callback that's called by |policy_service_| if the respective ONC policy 71 // changed. 72 void OnPolicyChanged(chromeos::onc::ONCSource onc_source, 73 const base::Value* previous, 74 const base::Value* current); 75 76 // Retrieves the ONC policies from |policy_service_| and pushes the 77 // configurations to |network_library_|. Ensures that a device policy is 78 // always overwritten by a user policy. 79 void ApplyNetworkConfigurations(); 80 81 // Push the policy stored at |policy_key| for |onc_source| to 82 // |network_library_|. 83 void ApplyNetworkConfiguration(const std::string& policy_key, 84 chromeos::onc::ONCSource onc_source, 85 PolicyService* policy_service); 86 87 // Wraps the policy service we read network configuration from. 88 PolicyChangeRegistrar policy_change_registrar_; 89 90 // Network library to write network configuration to. 91 chromeos::NetworkLibrary* network_library_; 92 93 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_; 94 95 // Needed to check whether user policies are ready. 96 // Unowned. 97 PolicyService* user_policy_service_; 98 99 // The device policy service storing the ONC policies. Also needed to check 100 // whether device policies are ready. 101 // Unowned. 102 PolicyService* device_policy_service_; 103 104 DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationUpdaterImplCros); 105}; 106 107} // namespace policy 108 109#endif // CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_IMPL_CROS_H_ 110