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_state_notifier.h" | 8 #include "ash/system/chromeos/network/network_state_notifier.h" |
9 #include "ash/system/system_notifier.h" | 9 #include "ash/system/system_notifier.h" |
10 #include "ash/system/tray/system_tray_delegate.h" | 10 #include "ash/system/tray/system_tray_delegate.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 const char kErrorInProgress[] = "org.chromium.flimflam.Error.InProgress"; | 51 const char kErrorInProgress[] = "org.chromium.flimflam.Error.InProgress"; |
52 | 52 |
53 // Returns true for carriers that can be activated through Shill instead of | 53 // Returns true for carriers that can be activated through Shill instead of |
54 // through a WebUI dialog. | 54 // through a WebUI dialog. |
55 bool IsDirectActivatedCarrier(const std::string& carrier) { | 55 bool IsDirectActivatedCarrier(const std::string& carrier) { |
56 if (carrier == shill::kCarrierSprint) | 56 if (carrier == shill::kCarrierSprint) |
57 return true; | 57 return true; |
58 return false; | 58 return false; |
59 } | 59 } |
60 | 60 |
61 void ShowErrorNotification(const std::string& error, | 61 void ShowErrorNotification(const std::string& error_name, |
| 62 const std::string& shill_error, |
62 const std::string& service_path) { | 63 const std::string& service_path) { |
63 Shell::GetInstance()->system_tray_notifier()->network_state_notifier()-> | 64 Shell::GetInstance()->system_tray_notifier()->network_state_notifier()-> |
64 ShowNetworkConnectError(error, service_path); | 65 ShowNetworkConnectError(error_name, shill_error, service_path); |
65 } | 66 } |
66 | 67 |
67 void OnConnectFailed(const std::string& service_path, | 68 void OnConnectFailed(const std::string& service_path, |
68 gfx::NativeWindow owning_window, | 69 gfx::NativeWindow owning_window, |
69 const std::string& error_name, | 70 const std::string& error_name, |
70 scoped_ptr<base::DictionaryValue> error_data) { | 71 scoped_ptr<base::DictionaryValue> error_data) { |
71 NET_LOG_ERROR("Connect Failed: " + error_name, service_path); | 72 NET_LOG_ERROR("Connect Failed: " + error_name, service_path); |
72 | 73 |
73 if (!ash::Shell::HasInstance()) | 74 if (!ash::Shell::HasInstance()) |
74 return; | 75 return; |
(...skipping 22 matching lines...) Expand all Loading... |
97 return; | 98 return; |
98 } | 99 } |
99 | 100 |
100 if (error_name == NetworkConnectionHandler::kErrorConnected || | 101 if (error_name == NetworkConnectionHandler::kErrorConnected || |
101 error_name == NetworkConnectionHandler::kErrorConnecting) { | 102 error_name == NetworkConnectionHandler::kErrorConnecting) { |
102 network_connect::ShowNetworkSettings(service_path); | 103 network_connect::ShowNetworkSettings(service_path); |
103 return; | 104 return; |
104 } | 105 } |
105 | 106 |
106 // ConnectFailed or unknown error; show a notification. | 107 // ConnectFailed or unknown error; show a notification. |
107 ShowErrorNotification(error_name, service_path); | 108 std::string shill_error; |
| 109 error_data.get()->GetString( |
| 110 chromeos::network_handler::kErrorDetail, &shill_error); |
| 111 ShowErrorNotification(error_name, shill_error, service_path); |
108 | 112 |
109 // Show a configure dialog for ConnectFailed errors. | 113 // Show a configure dialog for ConnectFailed errors. |
110 if (error_name != flimflam::kErrorConnectFailed) | 114 if (error_name != flimflam::kErrorConnectFailed) |
111 return; | 115 return; |
112 | 116 |
113 // If Shill reports an InProgress error, don't try to configure the network. | 117 // If Shill reports an InProgress error, don't try to configure the network. |
114 std::string dbus_error_name; | 118 std::string dbus_error_name; |
115 error_data.get()->GetString( | 119 error_data.get()->GetString( |
116 chromeos::network_handler::kDbusErrorName, &dbus_error_name); | 120 chromeos::network_handler::kDbusErrorName, &dbus_error_name); |
117 if (dbus_error_name == kErrorInProgress) | 121 if (dbus_error_name == kErrorInProgress) |
(...skipping 28 matching lines...) Expand all Loading... |
146 service_path, | 150 service_path, |
147 base::Bind(&OnConnectSucceeded, service_path), | 151 base::Bind(&OnConnectSucceeded, service_path), |
148 base::Bind(&OnConnectFailed, service_path, owning_window), | 152 base::Bind(&OnConnectFailed, service_path, owning_window), |
149 check_error_state); | 153 check_error_state); |
150 } | 154 } |
151 | 155 |
152 void OnActivateFailed(const std::string& service_path, | 156 void OnActivateFailed(const std::string& service_path, |
153 const std::string& error_name, | 157 const std::string& error_name, |
154 scoped_ptr<base::DictionaryValue> error_data) { | 158 scoped_ptr<base::DictionaryValue> error_data) { |
155 NET_LOG_ERROR("Unable to activate network", service_path); | 159 NET_LOG_ERROR("Unable to activate network", service_path); |
156 ShowErrorNotification(network_connect::kErrorActivateFailed, service_path); | 160 ShowErrorNotification( |
| 161 network_connect::kErrorActivateFailed, "", service_path); |
157 } | 162 } |
158 | 163 |
159 void OnActivateSucceeded(const std::string& service_path) { | 164 void OnActivateSucceeded(const std::string& service_path) { |
160 NET_LOG_USER("Activation Succeeded", service_path); | 165 NET_LOG_USER("Activation Succeeded", service_path); |
161 } | 166 } |
162 | 167 |
163 void OnConfigureFailed(const std::string& error_name, | 168 void OnConfigureFailed(const std::string& error_name, |
164 scoped_ptr<base::DictionaryValue> error_data) { | 169 scoped_ptr<base::DictionaryValue> error_data) { |
165 NET_LOG_ERROR("Unable to configure network", ""); | 170 NET_LOG_ERROR("Unable to configure network", ""); |
166 ShowErrorNotification(NetworkConnectionHandler::kErrorConfigureFailed, ""); | 171 ShowErrorNotification( |
| 172 NetworkConnectionHandler::kErrorConfigureFailed, "", ""); |
167 } | 173 } |
168 | 174 |
169 void OnConfigureSucceeded(const std::string& service_path) { | 175 void OnConfigureSucceeded(const std::string& service_path) { |
170 NET_LOG_USER("Configure Succeeded", service_path); | 176 NET_LOG_USER("Configure Succeeded", service_path); |
171 // After configuring a network, ignore any (possibly stale) error state. | 177 // After configuring a network, ignore any (possibly stale) error state. |
172 const bool check_error_state = false; | 178 const bool check_error_state = false; |
173 const gfx::NativeWindow owning_window = NULL; | 179 const gfx::NativeWindow owning_window = NULL; |
174 CallConnectToNetwork(service_path, check_error_state, owning_window); | 180 CallConnectToNetwork(service_path, check_error_state, owning_window); |
175 } | 181 } |
176 | 182 |
177 void SetPropertiesFailed(const std::string& desc, | 183 void SetPropertiesFailed(const std::string& desc, |
178 const std::string& service_path, | 184 const std::string& service_path, |
179 const std::string& config_error_name, | 185 const std::string& config_error_name, |
180 scoped_ptr<base::DictionaryValue> error_data) { | 186 scoped_ptr<base::DictionaryValue> error_data) { |
181 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path); | 187 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path); |
182 ShowErrorNotification( | 188 ShowErrorNotification( |
183 NetworkConnectionHandler::kErrorConfigureFailed, service_path); | 189 NetworkConnectionHandler::kErrorConfigureFailed, "", service_path); |
184 } | 190 } |
185 | 191 |
186 void SetPropertiesToClear(base::DictionaryValue* properties_to_set, | 192 void SetPropertiesToClear(base::DictionaryValue* properties_to_set, |
187 std::vector<std::string>* properties_to_clear) { | 193 std::vector<std::string>* properties_to_clear) { |
188 // Move empty string properties to properties_to_clear. | 194 // Move empty string properties to properties_to_clear. |
189 for (base::DictionaryValue::Iterator iter(*properties_to_set); | 195 for (base::DictionaryValue::Iterator iter(*properties_to_set); |
190 !iter.IsAtEnd(); iter.Advance()) { | 196 !iter.IsAtEnd(); iter.Advance()) { |
191 std::string value_str; | 197 std::string value_str; |
192 if (iter.value().GetAsString(&value_str) && value_str.empty()) | 198 if (iter.value().GetAsString(&value_str) && value_str.empty()) |
193 properties_to_clear->push_back(iter.key()); | 199 properties_to_clear->push_back(iter.key()); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 void ConfigureNetworkAndConnect(const std::string& service_path, | 404 void ConfigureNetworkAndConnect(const std::string& service_path, |
399 const base::DictionaryValue& properties, | 405 const base::DictionaryValue& properties, |
400 bool shared) { | 406 bool shared) { |
401 NET_LOG_USER("ConfigureNetworkAndConnect", service_path); | 407 NET_LOG_USER("ConfigureNetworkAndConnect", service_path); |
402 | 408 |
403 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy()); | 409 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy()); |
404 | 410 |
405 std::string profile_path; | 411 std::string profile_path; |
406 if (!GetNetworkProfilePath(shared, &profile_path)) { | 412 if (!GetNetworkProfilePath(shared, &profile_path)) { |
407 ShowErrorNotification( | 413 ShowErrorNotification( |
408 NetworkConnectionHandler::kErrorConfigureFailed, service_path); | 414 NetworkConnectionHandler::kErrorConfigureFailed, "", service_path); |
409 return; | 415 return; |
410 } | 416 } |
411 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile( | 417 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile( |
412 service_path, profile_path, | 418 service_path, profile_path, |
413 base::Bind(&ConfigureSetProfileSucceeded, | 419 base::Bind(&ConfigureSetProfileSucceeded, |
414 service_path, base::Passed(&properties_to_set)), | 420 service_path, base::Passed(&properties_to_set)), |
415 base::Bind(&SetPropertiesFailed, | 421 base::Bind(&SetPropertiesFailed, |
416 "SetProfile: " + profile_path, service_path)); | 422 "SetProfile: " + profile_path, service_path)); |
417 } | 423 } |
418 | 424 |
419 void CreateConfigurationAndConnect(base::DictionaryValue* properties, | 425 void CreateConfigurationAndConnect(base::DictionaryValue* properties, |
420 bool shared) { | 426 bool shared) { |
421 NET_LOG_USER("CreateConfigurationAndConnect", ""); | 427 NET_LOG_USER("CreateConfigurationAndConnect", ""); |
422 std::string profile_path; | 428 std::string profile_path; |
423 if (!GetNetworkProfilePath(shared, &profile_path)) { | 429 if (!GetNetworkProfilePath(shared, &profile_path)) { |
424 ShowErrorNotification(NetworkConnectionHandler::kErrorConfigureFailed, ""); | 430 ShowErrorNotification( |
| 431 NetworkConnectionHandler::kErrorConfigureFailed, "", ""); |
425 return; | 432 return; |
426 } | 433 } |
427 properties->SetStringWithoutPathExpansion( | 434 properties->SetStringWithoutPathExpansion( |
428 flimflam::kProfileProperty, profile_path); | 435 flimflam::kProfileProperty, profile_path); |
429 NetworkHandler::Get()->network_configuration_handler()->CreateConfiguration( | 436 NetworkHandler::Get()->network_configuration_handler()->CreateConfiguration( |
430 *properties, | 437 *properties, |
431 base::Bind(&OnConfigureSucceeded), | 438 base::Bind(&OnConfigureSucceeded), |
432 base::Bind(&OnConfigureFailed)); | 439 base::Bind(&OnConfigureFailed)); |
433 } | 440 } |
434 | 441 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 | 510 |
504 void ShowNetworkSettings(const std::string& service_path) { | 511 void ShowNetworkSettings(const std::string& service_path) { |
505 if (!ash::Shell::HasInstance()) | 512 if (!ash::Shell::HasInstance()) |
506 return; | 513 return; |
507 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( | 514 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( |
508 service_path); | 515 service_path); |
509 } | 516 } |
510 | 517 |
511 } // network_connect | 518 } // network_connect |
512 } // ash | 519 } // ash |
OLD | NEW |