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 <memory> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "chromeos/login/login_state.h" | 14 #include "chromeos/login/login_state.h" |
14 #include "chromeos/network/device_state.h" | 15 #include "chromeos/network/device_state.h" |
15 #include "chromeos/network/network_activation_handler.h" | 16 #include "chromeos/network/network_activation_handler.h" |
16 #include "chromeos/network/network_configuration_handler.h" | 17 #include "chromeos/network/network_configuration_handler.h" |
17 #include "chromeos/network/network_connection_handler.h" | 18 #include "chromeos/network/network_connection_handler.h" |
18 #include "chromeos/network/network_event_log.h" | 19 #include "chromeos/network/network_event_log.h" |
19 #include "chromeos/network/network_handler_callbacks.h" | 20 #include "chromeos/network/network_handler_callbacks.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 void CreateConfiguration(base::DictionaryValue* shill_properties, | 79 void CreateConfiguration(base::DictionaryValue* shill_properties, |
79 bool shared) override; | 80 bool shared) override; |
80 base::string16 GetShillErrorString(const std::string& error, | 81 base::string16 GetShillErrorString(const std::string& error, |
81 const std::string& service_path) override; | 82 const std::string& service_path) override; |
82 void ShowNetworkSettingsForPath(const std::string& service_path) override; | 83 void ShowNetworkSettingsForPath(const std::string& service_path) override; |
83 | 84 |
84 private: | 85 private: |
85 void HandleUnconfiguredNetwork(const std::string& service_path); | 86 void HandleUnconfiguredNetwork(const std::string& service_path); |
86 void OnConnectFailed(const std::string& service_path, | 87 void OnConnectFailed(const std::string& service_path, |
87 const std::string& error_name, | 88 const std::string& error_name, |
88 scoped_ptr<base::DictionaryValue> error_data); | 89 std::unique_ptr<base::DictionaryValue> error_data); |
89 bool MaybeShowConfigureUIImpl(const std::string& service_path, | 90 bool MaybeShowConfigureUIImpl(const std::string& service_path, |
90 const std::string& connect_error); | 91 const std::string& connect_error); |
91 bool GetNetworkProfilePath(bool shared, std::string* profile_path); | 92 bool GetNetworkProfilePath(bool shared, std::string* profile_path); |
92 void OnConnectSucceeded(const std::string& service_path); | 93 void OnConnectSucceeded(const std::string& service_path); |
93 void CallConnectToNetwork(const std::string& service_path, | 94 void CallConnectToNetwork(const std::string& service_path, |
94 bool check_error_state); | 95 bool check_error_state); |
95 void OnActivateFailed(const std::string& service_path, | 96 void OnActivateFailed(const std::string& service_path, |
96 const std::string& error_name, | 97 const std::string& error_name, |
97 scoped_ptr<base::DictionaryValue> error_data); | 98 std::unique_ptr<base::DictionaryValue> error_data); |
98 void OnActivateSucceeded(const std::string& service_path); | 99 void OnActivateSucceeded(const std::string& service_path); |
99 void OnConfigureFailed(const std::string& error_name, | 100 void OnConfigureFailed(const std::string& error_name, |
100 scoped_ptr<base::DictionaryValue> error_data); | 101 std::unique_ptr<base::DictionaryValue> error_data); |
101 void OnConfigureSucceeded(bool connect_on_configure, | 102 void OnConfigureSucceeded(bool connect_on_configure, |
102 const std::string& service_path, | 103 const std::string& service_path, |
103 const std::string& guid); | 104 const std::string& guid); |
104 void CallCreateConfiguration(base::DictionaryValue* properties, | 105 void CallCreateConfiguration(base::DictionaryValue* properties, |
105 bool shared, | 106 bool shared, |
106 bool connect_on_configure); | 107 bool connect_on_configure); |
107 void SetPropertiesFailed(const std::string& desc, | 108 void SetPropertiesFailed(const std::string& desc, |
108 const std::string& service_path, | 109 const std::string& service_path, |
109 const std::string& config_error_name, | 110 const std::string& config_error_name, |
110 scoped_ptr<base::DictionaryValue> error_data); | 111 std::unique_ptr<base::DictionaryValue> error_data); |
111 void SetPropertiesToClear(base::DictionaryValue* properties_to_set, | 112 void SetPropertiesToClear(base::DictionaryValue* properties_to_set, |
112 std::vector<std::string>* properties_to_clear); | 113 std::vector<std::string>* properties_to_clear); |
113 void ClearPropertiesAndConnect( | 114 void ClearPropertiesAndConnect( |
114 const std::string& service_path, | 115 const std::string& service_path, |
115 const std::vector<std::string>& properties_to_clear); | 116 const std::vector<std::string>& properties_to_clear); |
116 void ConfigureSetProfileSucceeded( | 117 void ConfigureSetProfileSucceeded( |
117 const std::string& service_path, | 118 const std::string& service_path, |
118 scoped_ptr<base::DictionaryValue> properties_to_set); | 119 std::unique_ptr<base::DictionaryValue> properties_to_set); |
119 | 120 |
120 Delegate* delegate_; | 121 Delegate* delegate_; |
121 scoped_ptr<NetworkStateNotifier> network_state_notifier_; | 122 std::unique_ptr<NetworkStateNotifier> network_state_notifier_; |
122 base::WeakPtrFactory<NetworkConnectImpl> weak_factory_; | 123 base::WeakPtrFactory<NetworkConnectImpl> weak_factory_; |
123 | 124 |
124 DISALLOW_COPY_AND_ASSIGN(NetworkConnectImpl); | 125 DISALLOW_COPY_AND_ASSIGN(NetworkConnectImpl); |
125 }; | 126 }; |
126 | 127 |
127 NetworkConnectImpl::NetworkConnectImpl(Delegate* delegate) | 128 NetworkConnectImpl::NetworkConnectImpl(Delegate* delegate) |
128 : delegate_(delegate), weak_factory_(this) { | 129 : delegate_(delegate), weak_factory_(this) { |
129 network_state_notifier_.reset(new NetworkStateNotifier(this)); | 130 network_state_notifier_.reset(new NetworkStateNotifier(this)); |
130 } | 131 } |
131 | 132 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 return false; | 201 return false; |
201 } | 202 } |
202 | 203 |
203 *profile_path = profile->path; | 204 *profile_path = profile->path; |
204 return true; | 205 return true; |
205 } | 206 } |
206 | 207 |
207 void NetworkConnectImpl::OnConnectFailed( | 208 void NetworkConnectImpl::OnConnectFailed( |
208 const std::string& service_path, | 209 const std::string& service_path, |
209 const std::string& error_name, | 210 const std::string& error_name, |
210 scoped_ptr<base::DictionaryValue> error_data) { | 211 std::unique_ptr<base::DictionaryValue> error_data) { |
211 MaybeShowConfigureUIImpl(service_path, error_name); | 212 MaybeShowConfigureUIImpl(service_path, error_name); |
212 } | 213 } |
213 | 214 |
214 // This handles connect failures that are a direct result of a user initiated | 215 // This handles connect failures that are a direct result of a user initiated |
215 // connect request and result in a new UI being shown. Note: notifications are | 216 // connect request and result in a new UI being shown. Note: notifications are |
216 // handled by NetworkStateNotifier. | 217 // handled by NetworkStateNotifier. |
217 bool NetworkConnectImpl::MaybeShowConfigureUIImpl( | 218 bool NetworkConnectImpl::MaybeShowConfigureUIImpl( |
218 const std::string& service_path, | 219 const std::string& service_path, |
219 const std::string& connect_error) { | 220 const std::string& connect_error) { |
220 NET_LOG_ERROR("Connect Failed: " + connect_error, service_path); | 221 NET_LOG_ERROR("Connect Failed: " + connect_error, service_path); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 service_path, base::Bind(&NetworkConnectImpl::OnConnectSucceeded, | 260 service_path, base::Bind(&NetworkConnectImpl::OnConnectSucceeded, |
260 weak_factory_.GetWeakPtr(), service_path), | 261 weak_factory_.GetWeakPtr(), service_path), |
261 base::Bind(&NetworkConnectImpl::OnConnectFailed, | 262 base::Bind(&NetworkConnectImpl::OnConnectFailed, |
262 weak_factory_.GetWeakPtr(), service_path), | 263 weak_factory_.GetWeakPtr(), service_path), |
263 check_error_state); | 264 check_error_state); |
264 } | 265 } |
265 | 266 |
266 void NetworkConnectImpl::OnActivateFailed( | 267 void NetworkConnectImpl::OnActivateFailed( |
267 const std::string& service_path, | 268 const std::string& service_path, |
268 const std::string& error_name, | 269 const std::string& error_name, |
269 scoped_ptr<base::DictionaryValue> error_data) { | 270 std::unique_ptr<base::DictionaryValue> error_data) { |
270 NET_LOG_ERROR("Unable to activate network", service_path); | 271 NET_LOG_ERROR("Unable to activate network", service_path); |
271 network_state_notifier_->ShowNetworkConnectError(kErrorActivateFailed, | 272 network_state_notifier_->ShowNetworkConnectError(kErrorActivateFailed, |
272 service_path); | 273 service_path); |
273 } | 274 } |
274 | 275 |
275 void NetworkConnectImpl::OnActivateSucceeded(const std::string& service_path) { | 276 void NetworkConnectImpl::OnActivateSucceeded(const std::string& service_path) { |
276 NET_LOG_USER("Activation Succeeded", service_path); | 277 NET_LOG_USER("Activation Succeeded", service_path); |
277 } | 278 } |
278 | 279 |
279 void NetworkConnectImpl::OnConfigureFailed( | 280 void NetworkConnectImpl::OnConfigureFailed( |
280 const std::string& error_name, | 281 const std::string& error_name, |
281 scoped_ptr<base::DictionaryValue> error_data) { | 282 std::unique_ptr<base::DictionaryValue> error_data) { |
282 NET_LOG_ERROR("Unable to configure network", ""); | 283 NET_LOG_ERROR("Unable to configure network", ""); |
283 network_state_notifier_->ShowNetworkConnectError( | 284 network_state_notifier_->ShowNetworkConnectError( |
284 NetworkConnectionHandler::kErrorConfigureFailed, ""); | 285 NetworkConnectionHandler::kErrorConfigureFailed, ""); |
285 } | 286 } |
286 | 287 |
287 void NetworkConnectImpl::OnConfigureSucceeded(bool connect_on_configure, | 288 void NetworkConnectImpl::OnConfigureSucceeded(bool connect_on_configure, |
288 const std::string& service_path, | 289 const std::string& service_path, |
289 const std::string& guid) { | 290 const std::string& guid) { |
290 NET_LOG_USER("Configure Succeeded", service_path); | 291 NET_LOG_USER("Configure Succeeded", service_path); |
291 if (!connect_on_configure) | 292 if (!connect_on_configure) |
(...skipping 22 matching lines...) Expand all Loading... |
314 base::Bind(&NetworkConnectImpl::OnConfigureSucceeded, | 315 base::Bind(&NetworkConnectImpl::OnConfigureSucceeded, |
315 weak_factory_.GetWeakPtr(), connect_on_configure), | 316 weak_factory_.GetWeakPtr(), connect_on_configure), |
316 base::Bind(&NetworkConnectImpl::OnConfigureFailed, | 317 base::Bind(&NetworkConnectImpl::OnConfigureFailed, |
317 weak_factory_.GetWeakPtr())); | 318 weak_factory_.GetWeakPtr())); |
318 } | 319 } |
319 | 320 |
320 void NetworkConnectImpl::SetPropertiesFailed( | 321 void NetworkConnectImpl::SetPropertiesFailed( |
321 const std::string& desc, | 322 const std::string& desc, |
322 const std::string& service_path, | 323 const std::string& service_path, |
323 const std::string& config_error_name, | 324 const std::string& config_error_name, |
324 scoped_ptr<base::DictionaryValue> error_data) { | 325 std::unique_ptr<base::DictionaryValue> error_data) { |
325 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path); | 326 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path); |
326 network_state_notifier_->ShowNetworkConnectError( | 327 network_state_notifier_->ShowNetworkConnectError( |
327 NetworkConnectionHandler::kErrorConfigureFailed, service_path); | 328 NetworkConnectionHandler::kErrorConfigureFailed, service_path); |
328 } | 329 } |
329 | 330 |
330 void NetworkConnectImpl::SetPropertiesToClear( | 331 void NetworkConnectImpl::SetPropertiesToClear( |
331 base::DictionaryValue* properties_to_set, | 332 base::DictionaryValue* properties_to_set, |
332 std::vector<std::string>* properties_to_clear) { | 333 std::vector<std::string>* properties_to_clear) { |
333 // Move empty string properties to properties_to_clear. | 334 // Move empty string properties to properties_to_clear. |
334 for (base::DictionaryValue::Iterator iter(*properties_to_set); | 335 for (base::DictionaryValue::Iterator iter(*properties_to_set); |
(...skipping 18 matching lines...) Expand all Loading... |
353 NetworkHandler::Get()->network_configuration_handler()->ClearShillProperties( | 354 NetworkHandler::Get()->network_configuration_handler()->ClearShillProperties( |
354 service_path, properties_to_clear, | 355 service_path, properties_to_clear, |
355 base::Bind(&NetworkConnectImpl::CallConnectToNetwork, | 356 base::Bind(&NetworkConnectImpl::CallConnectToNetwork, |
356 weak_factory_.GetWeakPtr(), service_path, check_error_state), | 357 weak_factory_.GetWeakPtr(), service_path, check_error_state), |
357 base::Bind(&NetworkConnectImpl::SetPropertiesFailed, | 358 base::Bind(&NetworkConnectImpl::SetPropertiesFailed, |
358 weak_factory_.GetWeakPtr(), "ClearProperties", service_path)); | 359 weak_factory_.GetWeakPtr(), "ClearProperties", service_path)); |
359 } | 360 } |
360 | 361 |
361 void NetworkConnectImpl::ConfigureSetProfileSucceeded( | 362 void NetworkConnectImpl::ConfigureSetProfileSucceeded( |
362 const std::string& service_path, | 363 const std::string& service_path, |
363 scoped_ptr<base::DictionaryValue> properties_to_set) { | 364 std::unique_ptr<base::DictionaryValue> properties_to_set) { |
364 std::vector<std::string> properties_to_clear; | 365 std::vector<std::string> properties_to_clear; |
365 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear); | 366 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear); |
366 NetworkHandler::Get()->network_configuration_handler()->SetShillProperties( | 367 NetworkHandler::Get()->network_configuration_handler()->SetShillProperties( |
367 service_path, *properties_to_set, | 368 service_path, *properties_to_set, |
368 NetworkConfigurationObserver::SOURCE_USER_ACTION, | 369 NetworkConfigurationObserver::SOURCE_USER_ACTION, |
369 base::Bind(&NetworkConnectImpl::ClearPropertiesAndConnect, | 370 base::Bind(&NetworkConnectImpl::ClearPropertiesAndConnect, |
370 weak_factory_.GetWeakPtr(), service_path, properties_to_clear), | 371 weak_factory_.GetWeakPtr(), service_path, properties_to_clear), |
371 base::Bind(&NetworkConnectImpl::SetPropertiesFailed, | 372 base::Bind(&NetworkConnectImpl::SetPropertiesFailed, |
372 weak_factory_.GetWeakPtr(), "SetProperties", service_path)); | 373 weak_factory_.GetWeakPtr(), "SetProperties", service_path)); |
373 } | 374 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 } | 499 } |
499 delegate_->ShowMobileSetupDialog(service_path); | 500 delegate_->ShowMobileSetupDialog(service_path); |
500 } | 501 } |
501 | 502 |
502 void NetworkConnectImpl::ConfigureNetworkAndConnect( | 503 void NetworkConnectImpl::ConfigureNetworkAndConnect( |
503 const std::string& service_path, | 504 const std::string& service_path, |
504 const base::DictionaryValue& properties, | 505 const base::DictionaryValue& properties, |
505 bool shared) { | 506 bool shared) { |
506 NET_LOG_USER("ConfigureNetworkAndConnect", service_path); | 507 NET_LOG_USER("ConfigureNetworkAndConnect", service_path); |
507 | 508 |
508 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy()); | 509 std::unique_ptr<base::DictionaryValue> properties_to_set( |
| 510 properties.DeepCopy()); |
509 | 511 |
510 std::string profile_path; | 512 std::string profile_path; |
511 if (!GetNetworkProfilePath(shared, &profile_path)) { | 513 if (!GetNetworkProfilePath(shared, &profile_path)) { |
512 network_state_notifier_->ShowNetworkConnectError( | 514 network_state_notifier_->ShowNetworkConnectError( |
513 NetworkConnectionHandler::kErrorConfigureFailed, service_path); | 515 NetworkConnectionHandler::kErrorConfigureFailed, service_path); |
514 return; | 516 return; |
515 } | 517 } |
516 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile( | 518 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile( |
517 service_path, profile_path, | 519 service_path, profile_path, |
518 NetworkConfigurationObserver::SOURCE_USER_ACTION, | 520 NetworkConfigurationObserver::SOURCE_USER_ACTION, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 return g_network_connect; | 652 return g_network_connect; |
651 } | 653 } |
652 | 654 |
653 NetworkConnect::NetworkConnect() { | 655 NetworkConnect::NetworkConnect() { |
654 } | 656 } |
655 | 657 |
656 NetworkConnect::~NetworkConnect() { | 658 NetworkConnect::~NetworkConnect() { |
657 } | 659 } |
658 | 660 |
659 } // namespace ui | 661 } // namespace ui |
OLD | NEW |