| Index: chrome/browser/policy/network_configuration_updater.cc
|
| diff --git a/chrome/browser/policy/network_configuration_updater.cc b/chrome/browser/policy/network_configuration_updater.cc
|
| index 152927acee8b481610564f73ef95ee31bc08e6c5..dcc2ead8be498098890ecffd0c1112a6267d46ce 100644
|
| --- a/chrome/browser/policy/network_configuration_updater.cc
|
| +++ b/chrome/browser/policy/network_configuration_updater.cc
|
| @@ -4,6 +4,10 @@
|
|
|
| #include "chrome/browser/policy/network_configuration_updater.h"
|
|
|
| +#include <string>
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/bind_helpers.h"
|
| #include "chrome/browser/chromeos/cros/network_library.h"
|
| #include "chrome/browser/policy/policy_map.h"
|
| #include "policy/policy_constants.h"
|
| @@ -14,49 +18,52 @@ const char NetworkConfigurationUpdater::kEmptyConfiguration[] =
|
| "{\"NetworkConfigurations\":[],\"Certificates\":[]}";
|
|
|
| NetworkConfigurationUpdater::NetworkConfigurationUpdater(
|
| - ConfigurationPolicyProvider* provider,
|
| + PolicyService* policy_service,
|
| chromeos::NetworkLibrary* network_library)
|
| - : network_library_(network_library) {
|
| + : policy_change_registrar_(
|
| + policy_service, POLICY_DOMAIN_CHROME, std::string()),
|
| + network_library_(network_library) {
|
| DCHECK(network_library_);
|
| - provider_registrar_.Init(provider, this);
|
| - Update();
|
| -}
|
| + policy_change_registrar_.Observe(
|
| + key::kDeviceOpenNetworkConfiguration,
|
| + base::Bind(&NetworkConfigurationUpdater::ApplyNetworkConfiguration,
|
| + base::Unretained(this),
|
| + chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY,
|
| + &device_network_config_));
|
| + policy_change_registrar_.Observe(
|
| + key::kOpenNetworkConfiguration,
|
| + base::Bind(&NetworkConfigurationUpdater::ApplyNetworkConfiguration,
|
| + base::Unretained(this),
|
| + chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY,
|
| + &user_network_config_));
|
|
|
| -NetworkConfigurationUpdater::~NetworkConfigurationUpdater() {}
|
| -
|
| -void NetworkConfigurationUpdater::OnUpdatePolicy(
|
| - ConfigurationPolicyProvider* provider) {
|
| - Update();
|
| + // Apply the current values immediately.
|
| + const PolicyMap& policies = policy_service->GetPolicies(POLICY_DOMAIN_CHROME,
|
| + std::string());
|
| + ApplyNetworkConfiguration(
|
| + chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY,
|
| + &device_network_config_,
|
| + NULL,
|
| + policies.GetValue(key::kDeviceOpenNetworkConfiguration));
|
| + ApplyNetworkConfiguration(
|
| + chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY,
|
| + &user_network_config_,
|
| + NULL,
|
| + policies.GetValue(key::kOpenNetworkConfiguration));
|
| }
|
|
|
| -void NetworkConfigurationUpdater::Update() {
|
| - ConfigurationPolicyProvider* provider = provider_registrar_.provider();
|
| -
|
| - PolicyMap policy;
|
| - if (!provider->Provide(&policy)) {
|
| - LOG(WARNING) << "Failed to read policy from policy provider.";
|
| - return;
|
| - }
|
| -
|
| - ApplyNetworkConfiguration(policy, key::kDeviceOpenNetworkConfiguration,
|
| - chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY,
|
| - &device_network_config_);
|
| - ApplyNetworkConfiguration(policy, key::kOpenNetworkConfiguration,
|
| - chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY,
|
| - &user_network_config_);
|
| -}
|
| +NetworkConfigurationUpdater::~NetworkConfigurationUpdater() {}
|
|
|
| void NetworkConfigurationUpdater::ApplyNetworkConfiguration(
|
| - const PolicyMap& policy_map,
|
| - const char* policy_name,
|
| chromeos::NetworkUIData::ONCSource onc_source,
|
| - std::string* cached_value) {
|
| + std::string* cached_value,
|
| + const base::Value* previous,
|
| + const base::Value* current) {
|
| std::string new_network_config;
|
| - const base::Value* value = policy_map.GetValue(policy_name);
|
| - if (value != NULL) {
|
| + if (current != NULL) {
|
| // If the policy is not a string, we issue a warning, but still clear the
|
| // network configuration.
|
| - if (!value->GetAsString(&new_network_config))
|
| + if (!current->GetAsString(&new_network_config))
|
| LOG(WARNING) << "Invalid network configuration.";
|
| }
|
|
|
|
|