| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ash/system/chromeos/network/network_connect.h" | 5 #include "ash/system/chromeos/network/network_connect.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/system/chromeos/network/network_observer.h" | 8 #include "ash/system/chromeos/network/network_observer.h" |
| 9 #include "ash/system/chromeos/network/network_state_notifier.h" | 9 #include "ash/system/chromeos/network/network_state_notifier.h" |
| 10 #include "ash/system/tray/system_tray_delegate.h" | 10 #include "ash/system/tray/system_tray_delegate.h" |
| 11 #include "ash/system/tray/system_tray_notifier.h" | 11 #include "ash/system/tray/system_tray_notifier.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chromeos/login/login_state.h" | 16 #include "chromeos/login/login_state.h" |
| 17 #include "chromeos/network/device_state.h" | 17 #include "chromeos/network/device_state.h" |
| 18 #include "chromeos/network/network_configuration_handler.h" | 18 #include "chromeos/network/network_configuration_handler.h" |
| 19 #include "chromeos/network/network_connection_handler.h" | 19 #include "chromeos/network/network_connection_handler.h" |
| 20 #include "chromeos/network/network_event_log.h" | 20 #include "chromeos/network/network_event_log.h" |
| 21 #include "chromeos/network/network_handler_callbacks.h" |
| 21 #include "chromeos/network/network_profile.h" | 22 #include "chromeos/network/network_profile.h" |
| 22 #include "chromeos/network/network_profile_handler.h" | 23 #include "chromeos/network/network_profile_handler.h" |
| 23 #include "chromeos/network/network_state.h" | 24 #include "chromeos/network/network_state.h" |
| 24 #include "chromeos/network/network_state_handler.h" | 25 #include "chromeos/network/network_state_handler.h" |
| 25 #include "grit/ash_strings.h" | 26 #include "grit/ash_strings.h" |
| 26 #include "third_party/cros_system_api/dbus/service_constants.h" | 27 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 28 | 29 |
| 29 using chromeos::DeviceState; | 30 using chromeos::DeviceState; |
| 30 using chromeos::NetworkConfigurationHandler; | 31 using chromeos::NetworkConfigurationHandler; |
| 31 using chromeos::NetworkConnectionHandler; | 32 using chromeos::NetworkConnectionHandler; |
| 32 using chromeos::NetworkHandler; | 33 using chromeos::NetworkHandler; |
| 33 using chromeos::NetworkProfile; | 34 using chromeos::NetworkProfile; |
| 34 using chromeos::NetworkProfileHandler; | 35 using chromeos::NetworkProfileHandler; |
| 35 using chromeos::NetworkState; | 36 using chromeos::NetworkState; |
| 36 | 37 |
| 37 namespace ash { | 38 namespace ash { |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 42 // TODO(stevenjb): This should be in service_constants.h |
| 43 const char kErrorInProgress[] = "org.chromium.flimflam.Error.InProgress"; |
| 44 |
| 41 // Returns true for carriers that can be activated through Shill instead of | 45 // Returns true for carriers that can be activated through Shill instead of |
| 42 // through a WebUI dialog. | 46 // through a WebUI dialog. |
| 43 bool IsDirectActivatedCarrier(const std::string& carrier) { | 47 bool IsDirectActivatedCarrier(const std::string& carrier) { |
| 44 if (carrier == shill::kCarrierSprint) | 48 if (carrier == shill::kCarrierSprint) |
| 45 return true; | 49 return true; |
| 46 return false; | 50 return false; |
| 47 } | 51 } |
| 48 | 52 |
| 53 void ShowErrorNotification(const std::string& error, |
| 54 const std::string& service_path) { |
| 55 Shell::GetInstance()->system_tray_notifier()->network_state_notifier()-> |
| 56 ShowNetworkConnectError(error, service_path); |
| 57 } |
| 58 |
| 49 void OnConnectFailed(const std::string& service_path, | 59 void OnConnectFailed(const std::string& service_path, |
| 50 gfx::NativeWindow owning_window, | 60 gfx::NativeWindow owning_window, |
| 51 const std::string& error_name, | 61 const std::string& error_name, |
| 52 scoped_ptr<base::DictionaryValue> error_data) { | 62 scoped_ptr<base::DictionaryValue> error_data) { |
| 53 NET_LOG_ERROR("Connect Failed: " + error_name, service_path); | 63 NET_LOG_ERROR("Connect Failed: " + error_name, service_path); |
| 54 | 64 |
| 65 // If a new connect attempt canceled this connect, no need to notify the user. |
| 66 if (error_name == NetworkConnectionHandler::kErrorConnectCanceled) |
| 67 return; |
| 68 |
| 55 if (error_name == NetworkConnectionHandler::kErrorPassphraseRequired || | 69 if (error_name == NetworkConnectionHandler::kErrorPassphraseRequired || |
| 56 error_name == NetworkConnectionHandler::kErrorConfigurationRequired || | 70 error_name == NetworkConnectionHandler::kErrorConfigurationRequired || |
| 57 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) { | 71 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) { |
| 58 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( | 72 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( |
| 59 service_path); | 73 service_path); |
| 60 return; | 74 return; |
| 61 } | 75 } |
| 62 | 76 |
| 63 if (error_name == NetworkConnectionHandler::kErrorCertificateRequired) { | 77 if (error_name == NetworkConnectionHandler::kErrorCertificateRequired) { |
| 64 ash::Shell::GetInstance()->system_tray_delegate()->EnrollOrConfigureNetwork( | 78 ash::Shell::GetInstance()->system_tray_delegate()->EnrollOrConfigureNetwork( |
| 65 service_path, owning_window); | 79 service_path, owning_window); |
| 66 return; | 80 return; |
| 67 } | 81 } |
| 68 | 82 |
| 69 if (error_name == NetworkConnectionHandler::kErrorActivationRequired) { | 83 if (error_name == NetworkConnectionHandler::kErrorActivationRequired) { |
| 70 network_connect::ActivateCellular(service_path); | 84 network_connect::ActivateCellular(service_path); |
| 71 return; | 85 return; |
| 72 } | 86 } |
| 73 | 87 |
| 74 if (error_name == NetworkConnectionHandler::kErrorConnected || | 88 if (error_name == NetworkConnectionHandler::kErrorConnected || |
| 75 error_name == NetworkConnectionHandler::kErrorConnecting) { | 89 error_name == NetworkConnectionHandler::kErrorConnecting) { |
| 76 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( | 90 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( |
| 77 service_path); | 91 service_path); |
| 78 return; | 92 return; |
| 79 } | 93 } |
| 80 | 94 |
| 81 // Shill does not always provide a helpful error. In this case, show the | 95 // ConnectFailed or unknown error; show a notification. |
| 82 // configuration UI and a notification. See crbug.com/217033 for an example. | 96 ShowErrorNotification(error_name, service_path); |
| 83 if (error_name == NetworkConnectionHandler::kErrorConnectFailed) { | 97 |
| 84 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( | 98 // Show a configure dialog for ConnectFailed errors. |
| 85 service_path); | 99 if (error_name != NetworkConnectionHandler::kErrorConnectFailed) |
| 86 } | 100 return; |
| 87 ash::Shell::GetInstance()->system_tray_notifier()->network_state_notifier()-> | 101 |
| 88 ShowNetworkConnectError(error_name, service_path); | 102 // If Shill reports an InProgress error, don't try to configure the network. |
| 103 std::string dbus_error_name; |
| 104 error_data.get()->GetString( |
| 105 chromeos::network_handler::kDbusErrorName, &dbus_error_name); |
| 106 if (dbus_error_name == kErrorInProgress) |
| 107 return; |
| 108 |
| 109 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( |
| 110 service_path); |
| 89 } | 111 } |
| 90 | 112 |
| 91 void OnConnectSucceeded(const std::string& service_path) { | 113 void OnConnectSucceeded(const std::string& service_path) { |
| 92 NET_LOG_USER("Connect Succeeded", service_path); | 114 NET_LOG_USER("Connect Succeeded", service_path); |
| 93 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( | 115 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( |
| 94 NetworkObserver::ERROR_CONNECT_FAILED); | 116 NetworkObserver::ERROR_CONNECT_FAILED); |
| 95 } | 117 } |
| 96 | 118 |
| 97 // If |check_error_state| is true, error state for the network is checked, | 119 // If |check_error_state| is true, error state for the network is checked, |
| 98 // otherwise any current error state is ignored (e.g. for recently configured | 120 // otherwise any current error state is ignored (e.g. for recently configured |
| (...skipping 12 matching lines...) Expand all Loading... |
| 111 service_path, | 133 service_path, |
| 112 base::Bind(&OnConnectSucceeded, service_path), | 134 base::Bind(&OnConnectSucceeded, service_path), |
| 113 base::Bind(&OnConnectFailed, service_path, owning_window), | 135 base::Bind(&OnConnectFailed, service_path, owning_window), |
| 114 check_error_state); | 136 check_error_state); |
| 115 } | 137 } |
| 116 | 138 |
| 117 void OnActivateFailed(const std::string& service_path, | 139 void OnActivateFailed(const std::string& service_path, |
| 118 const std::string& error_name, | 140 const std::string& error_name, |
| 119 scoped_ptr<base::DictionaryValue> error_data) { | 141 scoped_ptr<base::DictionaryValue> error_data) { |
| 120 NET_LOG_ERROR("Unable to activate network", service_path); | 142 NET_LOG_ERROR("Unable to activate network", service_path); |
| 143 ShowErrorNotification( |
| 144 NetworkConnectionHandler::kErrorActivateFailed, service_path); |
| 121 } | 145 } |
| 122 | 146 |
| 123 void OnActivateSucceeded(const std::string& service_path) { | 147 void OnActivateSucceeded(const std::string& service_path) { |
| 124 NET_LOG_USER("Activation Succeeded", service_path); | 148 NET_LOG_USER("Activation Succeeded", service_path); |
| 125 } | 149 } |
| 126 | 150 |
| 127 void OnConfigureFailed(const std::string& error_name, | 151 void OnConfigureFailed(const std::string& error_name, |
| 128 scoped_ptr<base::DictionaryValue> error_data) { | 152 scoped_ptr<base::DictionaryValue> error_data) { |
| 129 NET_LOG_ERROR("Unable to configure network", ""); | 153 NET_LOG_ERROR("Unable to configure network", ""); |
| 154 ShowErrorNotification(NetworkConnectionHandler::kErrorConfigureFailed, ""); |
| 130 } | 155 } |
| 131 | 156 |
| 132 void OnConfigureSucceeded(const std::string& service_path) { | 157 void OnConfigureSucceeded(const std::string& service_path) { |
| 133 NET_LOG_USER("Configure Succeeded", service_path); | 158 NET_LOG_USER("Configure Succeeded", service_path); |
| 134 // After configuring a network, ignore any (possibly stale) error state. | 159 // After configuring a network, ignore any (possibly stale) error state. |
| 135 const bool check_error_state = false; | 160 const bool check_error_state = false; |
| 136 const gfx::NativeWindow owning_window = NULL; | 161 const gfx::NativeWindow owning_window = NULL; |
| 137 CallConnectToNetwork(service_path, check_error_state, owning_window); | 162 CallConnectToNetwork(service_path, check_error_state, owning_window); |
| 138 } | 163 } |
| 139 | 164 |
| 140 void SetPropertiesFailed(const std::string& desc, | 165 void SetPropertiesFailed(const std::string& desc, |
| 141 const std::string& service_path, | 166 const std::string& service_path, |
| 142 const std::string& config_error_name, | 167 const std::string& config_error_name, |
| 143 scoped_ptr<base::DictionaryValue> error_data) { | 168 scoped_ptr<base::DictionaryValue> error_data) { |
| 144 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path); | 169 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path); |
| 170 ShowErrorNotification( |
| 171 NetworkConnectionHandler::kErrorConfigureFailed, service_path); |
| 145 } | 172 } |
| 146 | 173 |
| 147 void SetPropertiesToClear(base::DictionaryValue* properties_to_set, | 174 void SetPropertiesToClear(base::DictionaryValue* properties_to_set, |
| 148 std::vector<std::string>* properties_to_clear) { | 175 std::vector<std::string>* properties_to_clear) { |
| 149 // Move empty string properties to properties_to_clear. | 176 // Move empty string properties to properties_to_clear. |
| 150 for (base::DictionaryValue::Iterator iter(*properties_to_set); | 177 for (base::DictionaryValue::Iterator iter(*properties_to_set); |
| 151 !iter.IsAtEnd(); iter.Advance()) { | 178 !iter.IsAtEnd(); iter.Advance()) { |
| 152 std::string value_str; | 179 std::string value_str; |
| 153 if (iter.value().GetAsString(&value_str) && value_str.empty()) | 180 if (iter.value().GetAsString(&value_str) && value_str.empty()) |
| 154 properties_to_clear->push_back(iter.key()); | 181 properties_to_clear->push_back(iter.key()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 169 const gfx::NativeWindow owning_window = NULL; | 196 const gfx::NativeWindow owning_window = NULL; |
| 170 NetworkHandler::Get()->network_configuration_handler()->ClearProperties( | 197 NetworkHandler::Get()->network_configuration_handler()->ClearProperties( |
| 171 service_path, | 198 service_path, |
| 172 properties_to_clear, | 199 properties_to_clear, |
| 173 base::Bind(&CallConnectToNetwork, | 200 base::Bind(&CallConnectToNetwork, |
| 174 service_path, check_error_state, | 201 service_path, check_error_state, |
| 175 owning_window), | 202 owning_window), |
| 176 base::Bind(&SetPropertiesFailed, "ClearProperties", service_path)); | 203 base::Bind(&SetPropertiesFailed, "ClearProperties", service_path)); |
| 177 } | 204 } |
| 178 | 205 |
| 179 std::string GetNetworkProfilePath(bool shared) { | 206 // Returns false if !shared and no valid profile is available, which will |
| 180 // No need to specify a profile if not logged in and authenticated. | 207 // trigger an error and abort. |
| 181 if (!chromeos::LoginState::Get()->IsUserAuthenticated() && !shared) { | 208 bool GetNetworkProfilePath(bool shared, std::string* profile_path) { |
| 182 NET_LOG_ERROR("User profile specified before login", ""); | 209 if (shared) { |
| 183 shared = true; | 210 *profile_path = NetworkProfileHandler::kSharedProfilePath; |
| 211 return true; |
| 184 } | 212 } |
| 185 | 213 |
| 186 if (!shared) { | 214 if (!chromeos::LoginState::Get()->IsUserAuthenticated()) { |
| 187 const NetworkProfile* profile = | 215 NET_LOG_ERROR("User profile specified before login", ""); |
| 188 NetworkHandler::Get()->network_profile_handler()-> | 216 return false; |
| 189 GetDefaultUserProfile(); | |
| 190 if (profile) | |
| 191 return profile->path; | |
| 192 NET_LOG_ERROR("No user profile for unshared network configuration", ""); | |
| 193 } | 217 } |
| 194 | 218 |
| 195 return NetworkProfileHandler::kSharedProfilePath; | 219 const NetworkProfile* profile = |
| 220 NetworkHandler::Get()->network_profile_handler()-> |
| 221 GetDefaultUserProfile(); |
| 222 if (!profile) { |
| 223 NET_LOG_ERROR("No user profile for unshared network configuration", ""); |
| 224 return false; |
| 225 } |
| 226 |
| 227 *profile_path = profile->path; |
| 228 return true; |
| 196 } | 229 } |
| 197 | 230 |
| 198 void ConfigureSetProfileSucceeded( | 231 void ConfigureSetProfileSucceeded( |
| 199 const std::string& service_path, | 232 const std::string& service_path, |
| 200 scoped_ptr<base::DictionaryValue> properties_to_set) { | 233 scoped_ptr<base::DictionaryValue> properties_to_set) { |
| 201 std::vector<std::string> properties_to_clear; | 234 std::vector<std::string> properties_to_clear; |
| 202 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear); | 235 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear); |
| 203 NetworkHandler::Get()->network_configuration_handler()->SetProperties( | 236 NetworkHandler::Get()->network_configuration_handler()->SetProperties( |
| 204 service_path, | 237 service_path, |
| 205 *properties_to_set, | 238 *properties_to_set, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 base::Bind(&OnActivateFailed, service_path)); | 287 base::Bind(&OnActivateFailed, service_path)); |
| 255 } | 288 } |
| 256 | 289 |
| 257 void ConfigureNetworkAndConnect(const std::string& service_path, | 290 void ConfigureNetworkAndConnect(const std::string& service_path, |
| 258 const base::DictionaryValue& properties, | 291 const base::DictionaryValue& properties, |
| 259 bool shared) { | 292 bool shared) { |
| 260 NET_LOG_USER("ConfigureNetworkAndConnect", service_path); | 293 NET_LOG_USER("ConfigureNetworkAndConnect", service_path); |
| 261 | 294 |
| 262 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy()); | 295 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy()); |
| 263 | 296 |
| 264 std::string profile_path = GetNetworkProfilePath(shared); | 297 std::string profile_path; |
| 298 if (!GetNetworkProfilePath(shared, &profile_path)) { |
| 299 ShowErrorNotification( |
| 300 NetworkConnectionHandler::kErrorConfigureFailed, service_path); |
| 301 return; |
| 302 } |
| 265 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile( | 303 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile( |
| 266 service_path, profile_path, | 304 service_path, profile_path, |
| 267 base::Bind(&ConfigureSetProfileSucceeded, | 305 base::Bind(&ConfigureSetProfileSucceeded, |
| 268 service_path, base::Passed(&properties_to_set)), | 306 service_path, base::Passed(&properties_to_set)), |
| 269 base::Bind(&SetPropertiesFailed, | 307 base::Bind(&SetPropertiesFailed, |
| 270 "SetProfile: " + profile_path, service_path)); | 308 "SetProfile: " + profile_path, service_path)); |
| 271 } | 309 } |
| 272 | 310 |
| 273 void CreateConfigurationAndConnect(base::DictionaryValue* properties, | 311 void CreateConfigurationAndConnect(base::DictionaryValue* properties, |
| 274 bool shared) { | 312 bool shared) { |
| 275 NET_LOG_USER("CreateConfigurationAndConnect", ""); | 313 NET_LOG_USER("CreateConfigurationAndConnect", ""); |
| 276 std::string profile_path = GetNetworkProfilePath(shared); | 314 std::string profile_path; |
| 315 if (!GetNetworkProfilePath(shared, &profile_path)) { |
| 316 ShowErrorNotification(NetworkConnectionHandler::kErrorConfigureFailed, ""); |
| 317 return; |
| 318 } |
| 277 properties->SetStringWithoutPathExpansion( | 319 properties->SetStringWithoutPathExpansion( |
| 278 flimflam::kProfileProperty, profile_path); | 320 flimflam::kProfileProperty, profile_path); |
| 279 NetworkHandler::Get()->network_configuration_handler()->CreateConfiguration( | 321 NetworkHandler::Get()->network_configuration_handler()->CreateConfiguration( |
| 280 *properties, | 322 *properties, |
| 281 base::Bind(&OnConfigureSucceeded), | 323 base::Bind(&OnConfigureSucceeded), |
| 282 base::Bind(&OnConfigureFailed)); | 324 base::Bind(&OnConfigureFailed)); |
| 283 } | 325 } |
| 284 | 326 |
| 285 string16 ErrorString(const std::string& error) { | 327 string16 ErrorString(const std::string& error) { |
| 286 if (error.empty()) | 328 if (error.empty()) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 if (StringToLowerASCII(error) == | 388 if (StringToLowerASCII(error) == |
| 347 StringToLowerASCII(std::string(flimflam::kUnknownString))) { | 389 StringToLowerASCII(std::string(flimflam::kUnknownString))) { |
| 348 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); | 390 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); |
| 349 } | 391 } |
| 350 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR, | 392 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR, |
| 351 UTF8ToUTF16(error)); | 393 UTF8ToUTF16(error)); |
| 352 } | 394 } |
| 353 | 395 |
| 354 } // network_connect | 396 } // network_connect |
| 355 } // ash | 397 } // ash |
| OLD | NEW |