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 "ui/chromeos/network/network_connect.h" | 5 #include "ui/chromeos/network/network_connect.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 service_path); | 56 service_path); |
57 } | 57 } |
58 | 58 |
59 class NetworkConnectImpl : public NetworkConnect { | 59 class NetworkConnectImpl : public NetworkConnect { |
60 public: | 60 public: |
61 explicit NetworkConnectImpl(Delegate* delegate); | 61 explicit NetworkConnectImpl(Delegate* delegate); |
62 ~NetworkConnectImpl() override; | 62 ~NetworkConnectImpl() override; |
63 | 63 |
64 // NetworkConnect | 64 // NetworkConnect |
65 void ConnectToNetwork(const std::string& service_path) override; | 65 void ConnectToNetwork(const std::string& service_path) override; |
| 66 bool MaybeShowConfigureUI(const std::string& service_path, |
| 67 const std::string& connect_error) override; |
66 void SetTechnologyEnabled(const chromeos::NetworkTypePattern& technology, | 68 void SetTechnologyEnabled(const chromeos::NetworkTypePattern& technology, |
67 bool enabled_state) override; | 69 bool enabled_state) override; |
68 void ActivateCellular(const std::string& service_path) override; | 70 void ActivateCellular(const std::string& service_path) override; |
69 void ShowMobileSetup(const std::string& service_path) override; | 71 void ShowMobileSetup(const std::string& service_path) override; |
70 void ConfigureNetworkAndConnect(const std::string& service_path, | 72 void ConfigureNetworkAndConnect(const std::string& service_path, |
71 const base::DictionaryValue& shill_properties, | 73 const base::DictionaryValue& shill_properties, |
72 bool shared) override; | 74 bool shared) override; |
73 void CreateConfigurationAndConnect(base::DictionaryValue* shill_properties, | 75 void CreateConfigurationAndConnect(base::DictionaryValue* shill_properties, |
74 bool shared) override; | 76 bool shared) override; |
75 void CreateConfiguration(base::DictionaryValue* shill_properties, | 77 void CreateConfiguration(base::DictionaryValue* shill_properties, |
76 bool shared) override; | 78 bool shared) override; |
77 base::string16 GetShillErrorString(const std::string& error, | 79 base::string16 GetShillErrorString(const std::string& error, |
78 const std::string& service_path) override; | 80 const std::string& service_path) override; |
79 void ShowNetworkSettingsForPath(const std::string& service_path) override; | 81 void ShowNetworkSettingsForPath(const std::string& service_path) override; |
80 | 82 |
81 private: | 83 private: |
82 void HandleUnconfiguredNetwork(const std::string& service_path); | 84 void HandleUnconfiguredNetwork(const std::string& service_path); |
83 void OnConnectFailed(const std::string& service_path, | 85 void OnConnectFailed(const std::string& service_path, |
84 const std::string& error_name, | 86 const std::string& error_name, |
85 scoped_ptr<base::DictionaryValue> error_data); | 87 scoped_ptr<base::DictionaryValue> error_data); |
| 88 bool MaybeShowConfigureUIImpl(const std::string& service_path, |
| 89 const std::string& connect_error); |
86 bool GetNetworkProfilePath(bool shared, std::string* profile_path); | 90 bool GetNetworkProfilePath(bool shared, std::string* profile_path); |
87 void OnConnectSucceeded(const std::string& service_path); | 91 void OnConnectSucceeded(const std::string& service_path); |
88 void CallConnectToNetwork(const std::string& service_path, | 92 void CallConnectToNetwork(const std::string& service_path, |
89 bool check_error_state); | 93 bool check_error_state); |
90 void OnActivateFailed(const std::string& service_path, | 94 void OnActivateFailed(const std::string& service_path, |
91 const std::string& error_name, | 95 const std::string& error_name, |
92 scoped_ptr<base::DictionaryValue> error_data); | 96 scoped_ptr<base::DictionaryValue> error_data); |
93 void OnActivateSucceeded(const std::string& service_path); | 97 void OnActivateSucceeded(const std::string& service_path); |
94 void OnConfigureFailed(const std::string& error_name, | 98 void OnConfigureFailed(const std::string& error_name, |
95 scoped_ptr<base::DictionaryValue> error_data); | 99 scoped_ptr<base::DictionaryValue> error_data); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 NetworkHandler::Get()->network_profile_handler()->GetDefaultUserProfile(); | 195 NetworkHandler::Get()->network_profile_handler()->GetDefaultUserProfile(); |
192 if (!profile) { | 196 if (!profile) { |
193 NET_LOG_ERROR("No user profile for unshared network configuration", ""); | 197 NET_LOG_ERROR("No user profile for unshared network configuration", ""); |
194 return false; | 198 return false; |
195 } | 199 } |
196 | 200 |
197 *profile_path = profile->path; | 201 *profile_path = profile->path; |
198 return true; | 202 return true; |
199 } | 203 } |
200 | 204 |
| 205 void NetworkConnectImpl::OnConnectFailed( |
| 206 const std::string& service_path, |
| 207 const std::string& error_name, |
| 208 scoped_ptr<base::DictionaryValue> error_data) { |
| 209 MaybeShowConfigureUIImpl(service_path, error_name); |
| 210 } |
| 211 |
201 // This handles connect failures that are a direct result of a user initiated | 212 // This handles connect failures that are a direct result of a user initiated |
202 // connect request and result in a new UI being shown. Note: notifications are | 213 // connect request and result in a new UI being shown. Note: notifications are |
203 // handled by NetworkStateNotifier. | 214 // handled by NetworkStateNotifier. |
204 void NetworkConnectImpl::OnConnectFailed( | 215 bool NetworkConnectImpl::MaybeShowConfigureUIImpl( |
205 const std::string& service_path, | 216 const std::string& service_path, |
206 const std::string& error_name, | 217 const std::string& connect_error) { |
207 scoped_ptr<base::DictionaryValue> error_data) { | 218 NET_LOG_ERROR("Connect Failed: " + connect_error, service_path); |
208 NET_LOG_ERROR("Connect Failed: " + error_name, service_path); | |
209 | 219 |
210 if (error_name == NetworkConnectionHandler::kErrorBadPassphrase || | 220 if (connect_error == NetworkConnectionHandler::kErrorBadPassphrase || |
211 error_name == NetworkConnectionHandler::kErrorPassphraseRequired || | 221 connect_error == NetworkConnectionHandler::kErrorPassphraseRequired || |
212 error_name == NetworkConnectionHandler::kErrorConfigurationRequired || | 222 connect_error == NetworkConnectionHandler::kErrorConfigurationRequired || |
213 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) { | 223 connect_error == NetworkConnectionHandler::kErrorAuthenticationRequired) { |
214 HandleUnconfiguredNetwork(service_path); | 224 HandleUnconfiguredNetwork(service_path); |
215 return; | 225 return true; |
216 } | 226 } |
217 | 227 |
218 if (error_name == NetworkConnectionHandler::kErrorCertificateRequired) { | 228 if (connect_error == NetworkConnectionHandler::kErrorCertificateRequired) { |
219 if (!delegate_->ShowEnrollNetwork(service_path)) | 229 if (!delegate_->ShowEnrollNetwork(service_path)) |
220 HandleUnconfiguredNetwork(service_path); | 230 HandleUnconfiguredNetwork(service_path); |
221 return; | 231 return true; |
222 } | 232 } |
223 | 233 |
224 // Only show a configure dialog if there was a ConnectFailed error. The dialog | 234 // Only show a configure dialog if there was a ConnectFailed error. The dialog |
225 // allows the user to request a new connect attempt or cancel. Note: a | 235 // allows the user to request a new connect attempt or cancel. Note: a |
226 // notification may also be displayed by NetworkStateNotifier in this case. | 236 // notification may also be displayed by NetworkStateNotifier in this case. |
227 if (error_name == NetworkConnectionHandler::kErrorConnectFailed) | 237 if (connect_error == NetworkConnectionHandler::kErrorConnectFailed) { |
228 HandleUnconfiguredNetwork(service_path); | 238 HandleUnconfiguredNetwork(service_path); |
| 239 return true; |
| 240 } |
229 | 241 |
230 // Notifications for other connect failures are handled by | 242 // Notifications for other connect failures are handled by |
231 // NetworkStateNotifier, so no need to do anything else here. | 243 // NetworkStateNotifier, so no need to do anything else here. |
| 244 return false; |
232 } | 245 } |
233 | 246 |
234 void NetworkConnectImpl::OnConnectSucceeded(const std::string& service_path) { | 247 void NetworkConnectImpl::OnConnectSucceeded(const std::string& service_path) { |
235 NET_LOG_USER("Connect Succeeded", service_path); | 248 NET_LOG_USER("Connect Succeeded", service_path); |
236 } | 249 } |
237 | 250 |
238 // If |check_error_state| is true, error state for the network is checked, | 251 // If |check_error_state| is true, error state for the network is checked, |
239 // otherwise any current error state is ignored (e.g. for recently configured | 252 // otherwise any current error state is ignored (e.g. for recently configured |
240 // networks or repeat connect attempts). | 253 // networks or repeat connect attempts). |
241 void NetworkConnectImpl::CallConnectToNetwork(const std::string& service_path, | 254 void NetworkConnectImpl::CallConnectToNetwork(const std::string& service_path, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 return; | 383 return; |
371 } else if (network->RequiresActivation()) { | 384 } else if (network->RequiresActivation()) { |
372 ActivateCellular(service_path); | 385 ActivateCellular(service_path); |
373 return; | 386 return; |
374 } | 387 } |
375 } | 388 } |
376 const bool check_error_state = true; | 389 const bool check_error_state = true; |
377 CallConnectToNetwork(service_path, check_error_state); | 390 CallConnectToNetwork(service_path, check_error_state); |
378 } | 391 } |
379 | 392 |
| 393 bool NetworkConnectImpl::MaybeShowConfigureUI( |
| 394 const std::string& service_path, |
| 395 const std::string& connect_error) { |
| 396 return MaybeShowConfigureUIImpl(service_path, connect_error); |
| 397 } |
| 398 |
380 void NetworkConnectImpl::SetTechnologyEnabled( | 399 void NetworkConnectImpl::SetTechnologyEnabled( |
381 const NetworkTypePattern& technology, | 400 const NetworkTypePattern& technology, |
382 bool enabled_state) { | 401 bool enabled_state) { |
383 std::string log_string = base::StringPrintf( | 402 std::string log_string = base::StringPrintf( |
384 "technology %s, target state: %s", technology.ToDebugString().c_str(), | 403 "technology %s, target state: %s", technology.ToDebugString().c_str(), |
385 (enabled_state ? "ENABLED" : "DISABLED")); | 404 (enabled_state ? "ENABLED" : "DISABLED")); |
386 NET_LOG_USER("SetTechnologyEnabled", log_string); | 405 NET_LOG_USER("SetTechnologyEnabled", log_string); |
387 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 406 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
388 bool enabled = handler->IsTechnologyEnabled(technology); | 407 bool enabled = handler->IsTechnologyEnabled(technology); |
389 if (enabled_state == enabled) { | 408 if (enabled_state == enabled) { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 return g_network_connect; | 648 return g_network_connect; |
630 } | 649 } |
631 | 650 |
632 NetworkConnect::NetworkConnect() { | 651 NetworkConnect::NetworkConnect() { |
633 } | 652 } |
634 | 653 |
635 NetworkConnect::~NetworkConnect() { | 654 NetworkConnect::~NetworkConnect() { |
636 } | 655 } |
637 | 656 |
638 } // namespace ui | 657 } // namespace ui |
OLD | NEW |