| 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/chromeos/net/onc_utils.h" | 5 #include "chrome/browser/chromeos/net/onc_utils.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/chromeos/login/users/user.h" | |
| 13 #include "chrome/browser/chromeos/login/users/user_manager.h" | 12 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 14 #include "chrome/browser/chromeos/ui_proxy_config.h" | 13 #include "chrome/browser/chromeos/ui_proxy_config.h" |
| 15 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 14 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
| 16 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 17 #include "chromeos/network/managed_network_configuration_handler.h" | 16 #include "chromeos/network/managed_network_configuration_handler.h" |
| 18 #include "chromeos/network/network_configuration_handler.h" | 17 #include "chromeos/network/network_configuration_handler.h" |
| 19 #include "chromeos/network/network_handler.h" | 18 #include "chromeos/network/network_handler.h" |
| 20 #include "chromeos/network/network_profile.h" | 19 #include "chromeos/network/network_profile.h" |
| 21 #include "chromeos/network/network_profile_handler.h" | 20 #include "chromeos/network/network_profile_handler.h" |
| 22 #include "chromeos/network/network_state.h" | 21 #include "chromeos/network/network_state.h" |
| 23 #include "chromeos/network/network_state_handler.h" | 22 #include "chromeos/network/network_state_handler.h" |
| 24 #include "chromeos/network/network_ui_data.h" | 23 #include "chromeos/network/network_ui_data.h" |
| 25 #include "chromeos/network/onc/onc_normalizer.h" | 24 #include "chromeos/network/onc/onc_normalizer.h" |
| 26 #include "chromeos/network/onc/onc_signature.h" | 25 #include "chromeos/network/onc/onc_signature.h" |
| 27 #include "chromeos/network/onc/onc_translator.h" | 26 #include "chromeos/network/onc/onc_translator.h" |
| 28 #include "chromeos/network/onc/onc_utils.h" | 27 #include "chromeos/network/onc/onc_utils.h" |
| 28 #include "components/user_manager/user.h" |
| 29 #include "net/base/host_port_pair.h" | 29 #include "net/base/host_port_pair.h" |
| 30 #include "net/proxy/proxy_bypass_rules.h" | 30 #include "net/proxy/proxy_bypass_rules.h" |
| 31 #include "net/proxy/proxy_server.h" | 31 #include "net/proxy/proxy_server.h" |
| 32 #include "third_party/cros_system_api/dbus/service_constants.h" | 32 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 33 #include "url/gurl.h" | 33 #include "url/gurl.h" |
| 34 | 34 |
| 35 namespace chromeos { | 35 namespace chromeos { |
| 36 namespace onc { | 36 namespace onc { |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 } | 145 } |
| 146 return proxy_dict.Pass(); | 146 return proxy_dict.Pass(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 namespace { | 149 namespace { |
| 150 | 150 |
| 151 // This class defines which string placeholders of ONC are replaced by which | 151 // This class defines which string placeholders of ONC are replaced by which |
| 152 // user attribute. | 152 // user attribute. |
| 153 class UserStringSubstitution : public chromeos::onc::StringSubstitution { | 153 class UserStringSubstitution : public chromeos::onc::StringSubstitution { |
| 154 public: | 154 public: |
| 155 explicit UserStringSubstitution(const chromeos::User* user) : user_(user) {} | 155 explicit UserStringSubstitution(const user_manager::User* user) |
| 156 : user_(user) {} |
| 156 virtual ~UserStringSubstitution() {} | 157 virtual ~UserStringSubstitution() {} |
| 157 | 158 |
| 158 virtual bool GetSubstitute(const std::string& placeholder, | 159 virtual bool GetSubstitute(const std::string& placeholder, |
| 159 std::string* substitute) const OVERRIDE { | 160 std::string* substitute) const OVERRIDE { |
| 160 if (placeholder == ::onc::substitutes::kLoginIDField) | 161 if (placeholder == ::onc::substitutes::kLoginIDField) |
| 161 *substitute = user_->GetAccountName(false); | 162 *substitute = user_->GetAccountName(false); |
| 162 else if (placeholder == ::onc::substitutes::kEmailField) | 163 else if (placeholder == ::onc::substitutes::kEmailField) |
| 163 *substitute = user_->email(); | 164 *substitute = user_->email(); |
| 164 else | 165 else |
| 165 return false; | 166 return false; |
| 166 return true; | 167 return true; |
| 167 } | 168 } |
| 168 | 169 |
| 169 private: | 170 private: |
| 170 const chromeos::User* user_; | 171 const user_manager::User* user_; |
| 171 | 172 |
| 172 DISALLOW_COPY_AND_ASSIGN(UserStringSubstitution); | 173 DISALLOW_COPY_AND_ASSIGN(UserStringSubstitution); |
| 173 }; | 174 }; |
| 174 | 175 |
| 175 } // namespace | 176 } // namespace |
| 176 | 177 |
| 177 void ExpandStringPlaceholdersInNetworksForUser( | 178 void ExpandStringPlaceholdersInNetworksForUser( |
| 178 const chromeos::User* user, | 179 const user_manager::User* user, |
| 179 base::ListValue* network_configs) { | 180 base::ListValue* network_configs) { |
| 180 if (!user) { | 181 if (!user) { |
| 181 // In tests no user may be logged in. It's not harmful if we just don't | 182 // In tests no user may be logged in. It's not harmful if we just don't |
| 182 // expand the strings. | 183 // expand the strings. |
| 183 return; | 184 return; |
| 184 } | 185 } |
| 185 UserStringSubstitution substitution(user); | 186 UserStringSubstitution substitution(user); |
| 186 chromeos::onc::ExpandStringsInNetworks(substitution, network_configs); | 187 chromeos::onc::ExpandStringsInNetworks(substitution, network_configs); |
| 187 } | 188 } |
| 188 | 189 |
| 189 void ImportNetworksForUser(const chromeos::User* user, | 190 void ImportNetworksForUser(const user_manager::User* user, |
| 190 const base::ListValue& network_configs, | 191 const base::ListValue& network_configs, |
| 191 std::string* error) { | 192 std::string* error) { |
| 192 error->clear(); | 193 error->clear(); |
| 193 | 194 |
| 194 scoped_ptr<base::ListValue> expanded_networks(network_configs.DeepCopy()); | 195 scoped_ptr<base::ListValue> expanded_networks(network_configs.DeepCopy()); |
| 195 ExpandStringPlaceholdersInNetworksForUser(user, expanded_networks.get()); | 196 ExpandStringPlaceholdersInNetworksForUser(user, expanded_networks.get()); |
| 196 | 197 |
| 197 const NetworkProfile* profile = | 198 const NetworkProfile* profile = |
| 198 NetworkHandler::Get()->network_profile_handler()->GetProfileForUserhash( | 199 NetworkHandler::Get()->network_profile_handler()->GetProfileForUserhash( |
| 199 user->username_hash()); | 200 user->username_hash()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 } | 259 } |
| 259 } | 260 } |
| 260 | 261 |
| 261 if (ethernet_not_found) | 262 if (ethernet_not_found) |
| 262 *error = "No Ethernet available to configure."; | 263 *error = "No Ethernet available to configure."; |
| 263 } | 264 } |
| 264 | 265 |
| 265 const base::DictionaryValue* FindPolicyForActiveUser( | 266 const base::DictionaryValue* FindPolicyForActiveUser( |
| 266 const std::string& guid, | 267 const std::string& guid, |
| 267 ::onc::ONCSource* onc_source) { | 268 ::onc::ONCSource* onc_source) { |
| 268 const User* user = UserManager::Get()->GetActiveUser(); | 269 const user_manager::User* user = UserManager::Get()->GetActiveUser(); |
| 269 std::string username_hash = user ? user->username_hash() : std::string(); | 270 std::string username_hash = user ? user->username_hash() : std::string(); |
| 270 return NetworkHandler::Get()->managed_network_configuration_handler()-> | 271 return NetworkHandler::Get()->managed_network_configuration_handler()-> |
| 271 FindPolicyByGUID(username_hash, guid, onc_source); | 272 FindPolicyByGUID(username_hash, guid, onc_source); |
| 272 } | 273 } |
| 273 | 274 |
| 274 const base::DictionaryValue* GetGlobalConfigFromPolicy(bool for_active_user) { | 275 const base::DictionaryValue* GetGlobalConfigFromPolicy(bool for_active_user) { |
| 275 std::string username_hash; | 276 std::string username_hash; |
| 276 if (for_active_user) { | 277 if (for_active_user) { |
| 277 const User* user = UserManager::Get()->GetActiveUser(); | 278 const user_manager::User* user = UserManager::Get()->GetActiveUser(); |
| 278 if (!user) { | 279 if (!user) { |
| 279 LOG(ERROR) << "No user logged in yet."; | 280 LOG(ERROR) << "No user logged in yet."; |
| 280 return NULL; | 281 return NULL; |
| 281 } | 282 } |
| 282 username_hash = user->username_hash(); | 283 username_hash = user->username_hash(); |
| 283 } | 284 } |
| 284 return NetworkHandler::Get()->managed_network_configuration_handler()-> | 285 return NetworkHandler::Get()->managed_network_configuration_handler()-> |
| 285 GetGlobalConfigFromPolicy(username_hash); | 286 GetGlobalConfigFromPolicy(username_hash); |
| 286 } | 287 } |
| 287 | 288 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 const PrefService* local_state_prefs, | 448 const PrefService* local_state_prefs, |
| 448 const NetworkState& network) { | 449 const NetworkState& network) { |
| 449 ::onc::ONCSource ignored_onc_source; | 450 ::onc::ONCSource ignored_onc_source; |
| 450 const base::DictionaryValue* policy = onc::GetPolicyForNetwork( | 451 const base::DictionaryValue* policy = onc::GetPolicyForNetwork( |
| 451 profile_prefs, local_state_prefs, network, &ignored_onc_source); | 452 profile_prefs, local_state_prefs, network, &ignored_onc_source); |
| 452 return policy != NULL; | 453 return policy != NULL; |
| 453 } | 454 } |
| 454 | 455 |
| 455 } // namespace onc | 456 } // namespace onc |
| 456 } // namespace chromeos | 457 } // namespace chromeos |
| OLD | NEW |