12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_H_
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include <string>
9424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/basictypes.h"
11424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "base/compiler_specific.h"
12c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "components/onc/onc_constants.h"
14a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/common/policy_service.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
16424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)namespace base {
178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class DictionaryValue;
188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class ListValue;
19424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)class Value;
203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
22424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)namespace chromeos {
23424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)class ManagedNetworkConfigurationHandler;
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace policy {
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
28424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)class PolicyMap;
297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
30424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Implements the common part of tracking a OpenNetworkConfiguration device or
31424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// user policy. Pushes the network configs to the
32424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// ManagedNetworkConfigurationHandler, which in turn writes configurations to
33424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Shill. Certificates are imported with the chromeos::onc::CertificateImporter.
34424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// For user policies the subclass UserNetworkConfigurationUpdater must be used.
35424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Does not handle proxy settings.
36424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)class NetworkConfigurationUpdater : public PolicyService::Observer {
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~NetworkConfigurationUpdater();
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
40424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // PolicyService::Observer overrides
41424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual void OnPolicyUpdated(const PolicyNamespace& ns,
42424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)                               const PolicyMap& previous,
43424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)                               const PolicyMap& current) OVERRIDE;
44424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual void OnPolicyServiceInitialized(PolicyDomain domain) OVERRIDE;
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) protected:
47424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  NetworkConfigurationUpdater(
484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      onc::ONCSource onc_source,
49424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      std::string policy_key,
50424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      PolicyService* policy_service,
51424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      chromeos::ManagedNetworkConfigurationHandler* network_config_handler);
52424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void Init();
54424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
55424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Imports the certificates part of the policy.
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void ImportCertificates(const base::ListValue& certificates_onc) = 0;
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
58424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Pushes the network part of the policy to the
59424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // ManagedNetworkConfigurationHandler. This can be overridden by subclasses to
60424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // modify |network_configs_onc| before the actual application.
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void ApplyNetworkPolicy(
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::ListValue* network_configs_onc,
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::DictionaryValue* global_network_config) = 0;
64424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  onc::ONCSource onc_source_;
66424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
67424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Pointer to the global singleton or a test instance.
68424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  chromeos::ManagedNetworkConfigurationHandler* network_config_handler_;
69424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
70c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private:
71424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Called if the ONC policy changed.
72424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  void OnPolicyChanged(const base::Value* previous, const base::Value* current);
73424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
74424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Apply the observed policy, i.e. both networks and certificates.
75424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  void ApplyPolicy();
76424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
77424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  std::string LogHeader() const;
78424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
79424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  std::string policy_key_;
80424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
81424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Used to register for notifications from the |policy_service_|.
82424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  PolicyChangeRegistrar policy_change_registrar_;
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
84424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Used to retrieve the policies.
85424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  PolicyService* policy_service_;
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationUpdater);
882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace policy
912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_H_
93