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" | |
17 #include "chromeos/network/device_state.h" | |
18 #include "chromeos/network/network_configuration_handler.h" | |
16 #include "chromeos/network/network_connection_handler.h" | 19 #include "chromeos/network/network_connection_handler.h" |
20 #include "chromeos/network/network_event_log.h" | |
21 #include "chromeos/network/network_profile.h" | |
22 #include "chromeos/network/network_profile_handler.h" | |
17 #include "chromeos/network/network_state.h" | 23 #include "chromeos/network/network_state.h" |
18 #include "chromeos/network/network_state_handler.h" | 24 #include "chromeos/network/network_state_handler.h" |
19 #include "grit/ash_strings.h" | 25 #include "grit/ash_strings.h" |
20 #include "third_party/cros_system_api/dbus/service_constants.h" | 26 #include "third_party/cros_system_api/dbus/service_constants.h" |
21 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
22 | 28 |
29 using chromeos::DeviceState; | |
30 using chromeos::NetworkConfigurationHandler; | |
23 using chromeos::NetworkConnectionHandler; | 31 using chromeos::NetworkConnectionHandler; |
24 using chromeos::NetworkHandler; | 32 using chromeos::NetworkHandler; |
33 using chromeos::NetworkProfile; | |
34 using chromeos::NetworkProfileHandler; | |
25 using chromeos::NetworkState; | 35 using chromeos::NetworkState; |
26 | 36 |
27 namespace ash { | 37 namespace ash { |
28 | 38 |
29 namespace { | 39 namespace { |
30 | 40 |
41 // Returns true for carriers that can be activated through Shill instead of | |
42 // through a WebUI dialog. | |
43 bool IsDirectActivatedCarrier(const std::string& carrier) { | |
44 if (carrier == shill::kCarrierSprint) | |
45 return true; | |
46 return false; | |
47 } | |
48 | |
31 void OnConnectFailed(const std::string& service_path, | 49 void OnConnectFailed(const std::string& service_path, |
50 gfx::NativeWindow owning_window, | |
32 const std::string& error_name, | 51 const std::string& error_name, |
33 scoped_ptr<base::DictionaryValue> error_data) { | 52 scoped_ptr<base::DictionaryValue> error_data) { |
34 VLOG(1) << "Connect Failed for " << service_path << ": " << error_name; | 53 NET_LOG_ERROR("Connect Failed: " + error_name, service_path); |
35 if (error_name == NetworkConnectionHandler::kErrorPassphraseRequired) { | 54 |
36 // TODO(stevenjb): Possibly add inline UI to handle passphrase entry here. | 55 if (error_name == NetworkConnectionHandler::kErrorPassphraseRequired || |
37 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( | |
38 service_path); | |
39 return; | |
40 } | |
41 if (error_name == NetworkConnectionHandler::kErrorActivationRequired || | |
42 error_name == NetworkConnectionHandler::kErrorCertificateRequired || | |
43 error_name == NetworkConnectionHandler::kErrorConfigurationRequired || | 56 error_name == NetworkConnectionHandler::kErrorConfigurationRequired || |
44 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) { | 57 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) { |
45 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( | 58 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( |
46 service_path); | 59 service_path); |
47 return; | 60 return; |
48 } | 61 } |
62 | |
63 if (error_name == NetworkConnectionHandler::kErrorCertificateRequired) { | |
64 ash::Shell::GetInstance()->system_tray_delegate()->EnrollOrConfigureNetwork( | |
65 service_path, owning_window); | |
66 return; | |
67 } | |
68 | |
69 if (error_name == NetworkConnectionHandler::kErrorActivationRequired) { | |
70 network_connect::ActivateCellular(service_path); | |
71 return; | |
72 } | |
73 | |
49 if (error_name == NetworkConnectionHandler::kErrorConnected || | 74 if (error_name == NetworkConnectionHandler::kErrorConnected || |
50 error_name == NetworkConnectionHandler::kErrorConnecting) { | 75 error_name == NetworkConnectionHandler::kErrorConnecting) { |
51 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( | 76 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( |
52 service_path); | 77 service_path); |
53 return; | 78 return; |
54 } | 79 } |
80 | |
55 // Shill does not always provide a helpful error. In this case, show the | 81 // Shill does not always provide a helpful error. In this case, show the |
56 // configuration UI and a notification. See crbug.com/217033 for an example. | 82 // configuration UI and a notification. See crbug.com/217033 for an example. |
57 if (error_name == NetworkConnectionHandler::kErrorConnectFailed) { | 83 if (error_name == NetworkConnectionHandler::kErrorConnectFailed) { |
58 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( | 84 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( |
59 service_path); | 85 service_path); |
60 } | 86 } |
61 ash::Shell::GetInstance()->system_tray_notifier()->network_state_notifier()-> | 87 ash::Shell::GetInstance()->system_tray_notifier()->network_state_notifier()-> |
62 ShowNetworkConnectError(error_name, service_path); | 88 ShowNetworkConnectError(error_name, service_path); |
63 } | 89 } |
64 | 90 |
65 void OnConnectSucceeded(const std::string& service_path) { | 91 void OnConnectSucceeded(const std::string& service_path) { |
66 VLOG(1) << "Connect Succeeded for " << service_path; | 92 NET_LOG_USER("Connect Succeeded", service_path); |
67 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( | 93 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( |
68 NetworkObserver::ERROR_CONNECT_FAILED); | 94 NetworkObserver::ERROR_CONNECT_FAILED); |
69 } | 95 } |
70 | 96 |
97 // 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 | |
99 // networks or repeat connect attempts). |owning_window| will be used to parent | |
100 // any configuration UI on failure and may be NULL (in which case the default | |
101 // window will be used). | |
102 void CallConnectToNetwork(const std::string& service_path, | |
103 bool check_error_state, | |
104 gfx::NativeWindow owning_window) { | |
105 NET_LOG_USER("ConnectToNetwork", service_path); | |
106 | |
107 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( | |
108 NetworkObserver::ERROR_CONNECT_FAILED); | |
109 | |
110 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( | |
111 service_path, | |
112 base::Bind(&OnConnectSucceeded, service_path), | |
113 base::Bind(&OnConnectFailed, service_path, owning_window), | |
114 check_error_state); | |
115 } | |
116 | |
117 void OnActivateFailed(const std::string& service_path, | |
118 const std::string& error_name, | |
119 scoped_ptr<base::DictionaryValue> error_data) { | |
120 NET_LOG_ERROR("Unable to activate network", service_path); | |
121 } | |
122 | |
123 void OnActivateSucceeded(const std::string& service_path) { | |
124 NET_LOG_USER("Activation Succeeded", service_path); | |
125 } | |
126 | |
127 void OnConfigureFailed(const std::string& error_name, | |
128 scoped_ptr<base::DictionaryValue> error_data) { | |
129 NET_LOG_ERROR("Unable to configure network", ""); | |
130 } | |
131 | |
132 void OnConfigureSucceeded(const std::string& service_path) { | |
133 NET_LOG_USER("Configure Succeeded", service_path); | |
134 // After configuring a network, ignore any (possibly stale) error state. | |
135 const bool check_error_state = false; | |
136 const gfx::NativeWindow owning_window = NULL; | |
137 CallConnectToNetwork(service_path, check_error_state, owning_window); | |
138 } | |
139 | |
140 void SetPropertiesFailed(const std::string& desc, | |
141 const std::string& service_path, | |
142 const std::string& config_error_name, | |
143 scoped_ptr<base::DictionaryValue> error_data) { | |
144 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path); | |
145 } | |
146 | |
147 void SetPropertiesToClear(base::DictionaryValue* properties_to_set, | |
148 std::vector<std::string>* properties_to_clear) { | |
149 // Move empty string properties to properties_to_clear. | |
150 for (base::DictionaryValue::Iterator iter(*properties_to_set); | |
151 !iter.IsAtEnd(); iter.Advance()) { | |
152 std::string value_str; | |
153 if (iter.value().GetAsString(&value_str) && value_str.empty()) | |
154 properties_to_clear->push_back(iter.key()); | |
155 } | |
156 // Remove cleared properties from properties_to_set. | |
157 for (std::vector<std::string>::iterator iter = properties_to_clear->begin(); | |
158 iter != properties_to_clear->end(); ++iter) { | |
159 properties_to_set->RemoveWithoutPathExpansion(*iter, NULL); | |
160 } | |
161 } | |
162 | |
163 void ClearPropertiesAndConnect( | |
164 const std::string& service_path, | |
165 const std::vector<std::string>& properties_to_clear) { | |
166 NET_LOG_USER("ClearPropertiesAndConnect", service_path); | |
167 // After configuring a network, ignore any (possibly stale) error state. | |
168 const bool check_error_state = false; | |
169 const gfx::NativeWindow owning_window = NULL; | |
170 NetworkHandler::Get()->network_configuration_handler()->ClearProperties( | |
171 service_path, | |
172 properties_to_clear, | |
173 base::Bind(&CallConnectToNetwork, | |
174 service_path, check_error_state, | |
175 owning_window), | |
176 base::Bind(&SetPropertiesFailed, "ClearProperties", service_path)); | |
177 } | |
178 | |
179 std::string GetNetworkProfilePath(bool shared) { | |
180 // No need to specify a profile if not logged in and authenticated. | |
181 if (!chromeos::LoginState::Get()->IsUserAuthenticated() && !shared) { | |
pneubeck (no reviews)
2013/08/08 19:20:36
Ok. my concentration seem to falter. Sorry.
As I
| |
182 NET_LOG_ERROR("User profile specified before login", ""); | |
183 shared = true; | |
184 } | |
185 | |
186 if (!shared) { | |
187 const NetworkProfile* profile = | |
188 NetworkHandler::Get()->network_profile_handler()-> | |
189 GetDefaultUserProfile(); | |
190 if (profile) | |
191 return profile->path; | |
192 NET_LOG_ERROR("No user profile for unshared network configuration", ""); | |
193 } | |
194 | |
195 return NetworkProfileHandler::kSharedProfilePath; | |
196 } | |
197 | |
198 void ConfigureSetProfileSucceeded( | |
199 const std::string& service_path, | |
200 scoped_ptr<base::DictionaryValue> properties_to_set) { | |
201 std::vector<std::string> properties_to_clear; | |
202 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear); | |
203 NetworkHandler::Get()->network_configuration_handler()->SetProperties( | |
204 service_path, | |
205 *properties_to_set, | |
206 base::Bind(&ClearPropertiesAndConnect, | |
207 service_path, | |
208 properties_to_clear), | |
209 base::Bind(&SetPropertiesFailed, "SetProperties", service_path)); | |
210 } | |
211 | |
71 } // namespace | 212 } // namespace |
72 | 213 |
73 namespace network_connect { | 214 namespace network_connect { |
74 | 215 |
75 void ConnectToNetwork(const std::string& service_path) { | 216 void ConnectToNetwork(const std::string& service_path, |
76 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> | 217 gfx::NativeWindow owning_window) { |
218 const bool check_error_state = true; | |
219 CallConnectToNetwork(service_path, check_error_state, owning_window); | |
220 } | |
221 | |
222 void ActivateCellular(const std::string& service_path) { | |
223 NET_LOG_USER("ActivateCellular", service_path); | |
224 const DeviceState* cellular_device = | |
225 NetworkHandler::Get()->network_state_handler()-> | |
226 GetDeviceStateByType(flimflam::kTypeCellular); | |
227 if (!cellular_device) { | |
228 NET_LOG_ERROR("ActivateCellular with no Device", service_path); | |
229 return; | |
230 } | |
231 if (!IsDirectActivatedCarrier(cellular_device->carrier())) { | |
232 // For non direct activation, show the mobile setup dialog which can be | |
233 // used to activate the network. | |
234 ash::Shell::GetInstance()->system_tray_delegate()->ShowMobileSetup( | |
235 service_path); | |
236 return; | |
237 } | |
238 const NetworkState* cellular = | |
239 NetworkHandler::Get()->network_state_handler()-> | |
77 GetNetworkState(service_path); | 240 GetNetworkState(service_path); |
78 if (!network) | 241 if (!cellular || cellular->type() != flimflam::kTypeCellular) { |
242 NET_LOG_ERROR("ActivateCellular with no Service", service_path); | |
79 return; | 243 return; |
80 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( | 244 } |
81 NetworkObserver::ERROR_CONNECT_FAILED); | 245 if (cellular->activation_state() == flimflam::kActivationStateActivated) { |
82 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( | 246 NET_LOG_ERROR("ActivateCellular for activated service", service_path); |
247 return; | |
248 } | |
249 | |
250 NetworkHandler::Get()->network_connection_handler()->ActivateNetwork( | |
83 service_path, | 251 service_path, |
84 base::Bind(&OnConnectSucceeded, service_path), | 252 "", // carrier |
85 base::Bind(&OnConnectFailed, service_path), | 253 base::Bind(&OnActivateSucceeded, service_path), |
86 true /* check_error_state */); | 254 base::Bind(&OnActivateFailed, service_path)); |
255 } | |
256 | |
257 void ConfigureNetworkAndConnect(const std::string& service_path, | |
258 const base::DictionaryValue& properties, | |
259 bool shared) { | |
260 NET_LOG_USER("ConfigureNetworkAndConnect", service_path); | |
261 | |
262 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy()); | |
263 | |
264 std::string profile_path = GetNetworkProfilePath(shared); | |
265 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile( | |
266 service_path, profile_path, | |
267 base::Bind(&ConfigureSetProfileSucceeded, | |
268 service_path, base::Passed(&properties_to_set)), | |
269 base::Bind(&SetPropertiesFailed, | |
270 "SetProfile: " + profile_path, service_path)); | |
271 } | |
272 | |
273 void CreateConfigurationAndConnect(base::DictionaryValue* properties, | |
274 bool shared) { | |
275 NET_LOG_USER("CreateConfigurationAndConnect", ""); | |
276 std::string profile_path = GetNetworkProfilePath(shared); | |
277 properties->SetStringWithoutPathExpansion( | |
278 flimflam::kProfileProperty, profile_path); | |
279 NetworkHandler::Get()->network_configuration_handler()->CreateConfiguration( | |
280 *properties, | |
281 base::Bind(&OnConfigureSucceeded), | |
282 base::Bind(&OnConfigureFailed)); | |
87 } | 283 } |
88 | 284 |
89 string16 ErrorString(const std::string& error) { | 285 string16 ErrorString(const std::string& error) { |
90 if (error.empty()) | 286 if (error.empty()) |
91 return string16(); | 287 return string16(); |
92 if (error == flimflam::kErrorOutOfRange) | 288 if (error == flimflam::kErrorOutOfRange) |
93 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE); | 289 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE); |
94 if (error == flimflam::kErrorPinMissing) | 290 if (error == flimflam::kErrorPinMissing) |
95 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_PIN_MISSING); | 291 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_PIN_MISSING); |
96 if (error == flimflam::kErrorDhcpFailed) | 292 if (error == flimflam::kErrorDhcpFailed) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 if (StringToLowerASCII(error) == | 346 if (StringToLowerASCII(error) == |
151 StringToLowerASCII(std::string(flimflam::kUnknownString))) { | 347 StringToLowerASCII(std::string(flimflam::kUnknownString))) { |
152 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); | 348 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); |
153 } | 349 } |
154 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR, | 350 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR, |
155 UTF8ToUTF16(error)); | 351 UTF8ToUTF16(error)); |
156 } | 352 } |
157 | 353 |
158 } // network_connect | 354 } // network_connect |
159 } // ash | 355 } // ash |
OLD | NEW |