| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/policy/network_configuration_updater.h" | 5 #include "chrome/browser/policy/network_configuration_updater.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/cros/network_library.h" | 7 #include "chrome/browser/chromeos/cros/network_library.h" |
| 8 #include "chrome/browser/policy/policy_map.h" | 8 #include "chrome/browser/policy/policy_map.h" |
| 9 #include "policy/policy_constants.h" | 9 #include "policy/policy_constants.h" |
| 10 | 10 |
| 11 namespace policy { | 11 namespace policy { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 void NetworkConfigurationUpdater::Update() { | 32 void NetworkConfigurationUpdater::Update() { |
| 33 ConfigurationPolicyProvider* provider = provider_registrar_.provider(); | 33 ConfigurationPolicyProvider* provider = provider_registrar_.provider(); |
| 34 | 34 |
| 35 PolicyMap policy; | 35 PolicyMap policy; |
| 36 if (!provider->Provide(&policy)) { | 36 if (!provider->Provide(&policy)) { |
| 37 LOG(WARNING) << "Failed to read policy from policy provider."; | 37 LOG(WARNING) << "Failed to read policy from policy provider."; |
| 38 return; | 38 return; |
| 39 } | 39 } |
| 40 | 40 |
| 41 ApplyNetworkConfiguration(policy, kPolicyDeviceOpenNetworkConfiguration, | 41 ApplyNetworkConfiguration(policy, key::kDeviceOpenNetworkConfiguration, |
| 42 chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY, | 42 chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY, |
| 43 &device_network_config_); | 43 &device_network_config_); |
| 44 ApplyNetworkConfiguration(policy, kPolicyOpenNetworkConfiguration, | 44 ApplyNetworkConfiguration(policy, key::kOpenNetworkConfiguration, |
| 45 chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY, | 45 chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY, |
| 46 &user_network_config_); | 46 &user_network_config_); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void NetworkConfigurationUpdater::ApplyNetworkConfiguration( | 49 void NetworkConfigurationUpdater::ApplyNetworkConfiguration( |
| 50 const PolicyMap& policy_map, | 50 const PolicyMap& policy_map, |
| 51 ConfigurationPolicyType policy_type, | 51 const char* policy_name, |
| 52 chromeos::NetworkUIData::ONCSource onc_source, | 52 chromeos::NetworkUIData::ONCSource onc_source, |
| 53 std::string* cached_value) { | 53 std::string* cached_value) { |
| 54 std::string new_network_config; | 54 std::string new_network_config; |
| 55 const base::Value* value = policy_map.Get(policy_type); | 55 const base::Value* value = policy_map.GetValue(policy_name); |
| 56 if (value != NULL) { | 56 if (value != NULL) { |
| 57 // If the policy is not a string, we issue a warning, but still clear the | 57 // If the policy is not a string, we issue a warning, but still clear the |
| 58 // network configuration. | 58 // network configuration. |
| 59 if (!value->GetAsString(&new_network_config)) | 59 if (!value->GetAsString(&new_network_config)) |
| 60 LOG(WARNING) << "Invalid network configuration."; | 60 LOG(WARNING) << "Invalid network configuration."; |
| 61 } | 61 } |
| 62 | 62 |
| 63 // We need to load an empty configuration to get rid of any configuration | 63 // We need to load an empty configuration to get rid of any configuration |
| 64 // that has been installed previously. An empty string also works, but | 64 // that has been installed previously. An empty string also works, but |
| 65 // generates warnings and errors, which we'd like to avoid. | 65 // generates warnings and errors, which we'd like to avoid. |
| 66 if (new_network_config.empty()) | 66 if (new_network_config.empty()) |
| 67 new_network_config = kEmptyConfiguration; | 67 new_network_config = kEmptyConfiguration; |
| 68 | 68 |
| 69 if (*cached_value != new_network_config) { | 69 if (*cached_value != new_network_config) { |
| 70 *cached_value = new_network_config; | 70 *cached_value = new_network_config; |
| 71 std::string error; | 71 std::string error; |
| 72 if (!network_library_->LoadOncNetworks(new_network_config, "", onc_source, | 72 if (!network_library_->LoadOncNetworks(new_network_config, "", onc_source, |
| 73 &error)) { | 73 &error)) { |
| 74 LOG(WARNING) << "Network library failed to load ONC configuration:" | 74 LOG(WARNING) << "Network library failed to load ONC configuration:" |
| 75 << error; | 75 << error; |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 } // namespace policy | 80 } // namespace policy |
| OLD | NEW |