| OLD | NEW |
| 1 // Copyright (c) 2012 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "chrome/browser/chromeos/cros/network_library.h" | 11 #include "chrome/browser/chromeos/cros/network_library.h" |
| 12 #include "chrome/browser/chromeos/login/user_manager.h" |
| 13 #include "chrome/browser/policy/browser_policy_connector.h" |
| 12 #include "chrome/browser/policy/policy_map.h" | 14 #include "chrome/browser/policy/policy_map.h" |
| 13 #include "policy/policy_constants.h" | 15 #include "policy/policy_constants.h" |
| 14 | 16 |
| 15 namespace policy { | 17 namespace policy { |
| 16 | 18 |
| 17 const char NetworkConfigurationUpdater::kEmptyConfiguration[] = | 19 const char NetworkConfigurationUpdater::kEmptyConfiguration[] = |
| 18 "{\"NetworkConfigurations\":[],\"Certificates\":[]}"; | 20 "{\"NetworkConfigurations\":[],\"Certificates\":[]}"; |
| 19 | 21 |
| 20 NetworkConfigurationUpdater::NetworkConfigurationUpdater( | 22 NetworkConfigurationUpdater::NetworkConfigurationUpdater( |
| 21 PolicyService* policy_service, | 23 PolicyService* policy_service, |
| 22 chromeos::NetworkLibrary* network_library) | 24 BrowserPolicyConnector* connector, |
| 25 chromeos::NetworkLibrary* network_library, |
| 26 chromeos::UserManager* user_manager) |
| 23 : policy_change_registrar_( | 27 : policy_change_registrar_( |
| 24 policy_service, POLICY_DOMAIN_CHROME, std::string()), | 28 policy_service, POLICY_DOMAIN_CHROME, std::string()), |
| 25 network_library_(network_library) { | 29 connector_(connector), |
| 30 network_library_(network_library), |
| 31 user_manager_(user_manager) { |
| 26 DCHECK(network_library_); | 32 DCHECK(network_library_); |
| 27 policy_change_registrar_.Observe( | 33 policy_change_registrar_.Observe( |
| 28 key::kDeviceOpenNetworkConfiguration, | 34 key::kDeviceOpenNetworkConfiguration, |
| 29 base::Bind(&NetworkConfigurationUpdater::ApplyNetworkConfiguration, | 35 base::Bind(&NetworkConfigurationUpdater::ApplyNetworkConfiguration, |
| 30 base::Unretained(this), | 36 base::Unretained(this), |
| 31 chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY, | 37 chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY, |
| 32 &device_network_config_)); | 38 &device_network_config_)); |
| 33 policy_change_registrar_.Observe( | 39 policy_change_registrar_.Observe( |
| 34 key::kOpenNetworkConfiguration, | 40 key::kOpenNetworkConfiguration, |
| 35 base::Bind(&NetworkConfigurationUpdater::ApplyNetworkConfiguration, | 41 base::Bind(&NetworkConfigurationUpdater::ApplyNetworkConfiguration, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 66 if (!current->GetAsString(&new_network_config)) | 72 if (!current->GetAsString(&new_network_config)) |
| 67 LOG(WARNING) << "Invalid network configuration."; | 73 LOG(WARNING) << "Invalid network configuration."; |
| 68 } | 74 } |
| 69 | 75 |
| 70 // We need to load an empty configuration to get rid of any configuration | 76 // We need to load an empty configuration to get rid of any configuration |
| 71 // that has been installed previously. An empty string also works, but | 77 // that has been installed previously. An empty string also works, but |
| 72 // generates warnings and errors, which we'd like to avoid. | 78 // generates warnings and errors, which we'd like to avoid. |
| 73 if (new_network_config.empty()) | 79 if (new_network_config.empty()) |
| 74 new_network_config = kEmptyConfiguration; | 80 new_network_config = kEmptyConfiguration; |
| 75 | 81 |
| 82 // Web trust certificates are only allowed for managed users on managed |
| 83 // devices of the same domain. |
| 84 const bool allow_web_trust_from_policy = |
| 85 user_manager_->IsUserLoggedIn() && |
| 86 !user_manager_->IsLoggedInAsGuest() && |
| 87 connector_->GetUserAffiliation( |
| 88 user_manager_->GetLoggedInUser().email()) == USER_AFFILIATION_MANAGED; |
| 89 |
| 76 if (*cached_value != new_network_config) { | 90 if (*cached_value != new_network_config) { |
| 77 *cached_value = new_network_config; | 91 *cached_value = new_network_config; |
| 78 std::string error; | 92 std::string error; |
| 79 if (!network_library_->LoadOncNetworks(new_network_config, "", onc_source, | 93 if (!network_library_->LoadOncNetworks(new_network_config, "", onc_source, |
| 94 allow_web_trust_from_policy, |
| 80 &error)) { | 95 &error)) { |
| 81 LOG(WARNING) << "Network library failed to load ONC configuration:" | 96 LOG(WARNING) << "Network library failed to load ONC configuration:" |
| 82 << error; | 97 << error; |
| 83 } | 98 } |
| 84 } | 99 } |
| 85 } | 100 } |
| 86 | 101 |
| 87 } // namespace policy | 102 } // namespace policy |
| OLD | NEW |