OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/extensions/api/networking_private/networking_private_li nux.h" | 5 #include "chrome/browser/extensions/api/networking_private/networking_private_li nux.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 | 96 |
97 // Logs that the method is not implemented and reports |kErrorNotSupported| | 97 // Logs that the method is not implemented and reports |kErrorNotSupported| |
98 // to the failure callback. | 98 // to the failure callback. |
99 void ReportNotSupported( | 99 void ReportNotSupported( |
100 const std::string& method_name, | 100 const std::string& method_name, |
101 const NetworkingPrivateDelegate::FailureCallback& failure_callback) { | 101 const NetworkingPrivateDelegate::FailureCallback& failure_callback) { |
102 LOG(WARNING) << method_name << " is not supported"; | 102 LOG(WARNING) << method_name << " is not supported"; |
103 failure_callback.Run(extensions::networking_private::kErrorNotSupported); | 103 failure_callback.Run(extensions::networking_private::kErrorNotSupported); |
104 } | 104 } |
105 | 105 |
106 // Fires the appropriate callback when the network connection succeeds or fails. | 106 // Fires the appropriate callback when the network connect operation succeeds |
107 void OnNetworkConnected( | 107 // or fails. |
108 void OnNetworkConnectOperationCompleted( | |
108 scoped_ptr<std::string> error, | 109 scoped_ptr<std::string> error, |
109 const NetworkingPrivateDelegate::VoidCallback& success_callback, | 110 const NetworkingPrivateDelegate::VoidCallback& success_callback, |
110 const NetworkingPrivateDelegate::FailureCallback& failure_callback) { | 111 const NetworkingPrivateDelegate::FailureCallback& failure_callback) { |
111 if (!error->empty()) { | 112 if (!error->empty()) { |
112 failure_callback.Run(*error); | 113 failure_callback.Run(*error); |
113 return; | 114 return; |
114 } | 115 } |
115 success_callback.Run(); | 116 success_callback.Run(); |
116 } | 117 } |
117 | 118 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 if (!reader.PopObjectPath(&active_connection_path)) { | 333 if (!reader.PopObjectPath(&active_connection_path)) { |
333 LOG(ERROR) << "Unexpected response for connection path " | 334 LOG(ERROR) << "Unexpected response for connection path " |
334 << ": " << response->ToString(); | 335 << ": " << response->ToString(); |
335 *error = "Failed to connect."; | 336 *error = "Failed to connect."; |
336 return; | 337 return; |
337 } | 338 } |
338 | 339 |
339 return; | 340 return; |
340 } | 341 } |
341 | 342 |
343 void NetworkingPrivateLinux::DisconnectFromNetwork(const std::string& guid, | |
344 std::string* error) { | |
345 AssertOnDBusThread(); | |
346 std::string device_path_str; | |
347 std::string access_point_path_str; | |
348 std::string ssid; | |
349 DVLOG(1) << "Disconnecting from network GUID " << guid; | |
350 | |
351 if (!ParseNetworkGuid(guid, &device_path_str, &access_point_path_str, | |
352 &ssid)) { | |
353 *error = "Invalid Network GUID format"; | |
354 return; | |
355 } | |
356 | |
357 scoped_ptr<NetworkMap> network_map(new NetworkMap); | |
358 GetAllWiFiAccessPoints(false /* configured_only */, false /* visible_only */, | |
359 0 /* limit */, network_map.get()); | |
360 | |
361 NetworkMap::const_iterator network_iter = | |
362 network_map->find(base::UTF8ToUTF16(ssid)); | |
363 if (network_iter == network_map->end()) { | |
364 // This network doesn't exist so there's nothing to do. | |
365 return; | |
366 } | |
367 | |
368 std::string connection_state; | |
369 network_iter->second->GetString(kAccessPointInfoConnectionState, | |
370 &connection_state); | |
371 if (connection_state == ::onc::connection_state::kNotConnected) { | |
372 // Already disconnected so nothing to do. | |
373 return; | |
374 } | |
375 | |
376 // It's not disconnected so disconnect it. | |
377 dbus::ObjectPath device_path(device_path_str); | |
378 dbus::ObjectProxy* device_proxy = dbus_->GetObjectProxy( | |
379 networking_private::kNetworkManagerNamespace, device_path); | |
380 dbus::MethodCall method_call( | |
381 networking_private::kNetworkManagerDeviceNamespace, | |
382 networking_private::kNetworkManagerDisconnectMethod); | |
383 scoped_ptr<dbus::Response> response(device_proxy->CallMethodAndBlock( | |
384 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
385 | |
386 if (!response) { | |
387 LOG(WARNING) << "Failed to disconnect network on device " | |
388 << device_path.value(); | |
stevenjb
2014/12/08 17:37:43
nit: This is just device_path_str, you really don'
zentaro
2014/12/08 17:52:06
Done.
| |
389 *error = "Failed to disconnect network"; | |
390 } | |
391 } | |
392 | |
342 void NetworkingPrivateLinux::StartConnect( | 393 void NetworkingPrivateLinux::StartConnect( |
343 const std::string& guid, | 394 const std::string& guid, |
344 const VoidCallback& success_callback, | 395 const VoidCallback& success_callback, |
345 const FailureCallback& failure_callback) { | 396 const FailureCallback& failure_callback) { |
346 if (!CheckNetworkManagerSupported(failure_callback)) | 397 if (!CheckNetworkManagerSupported(failure_callback)) |
347 return; | 398 return; |
348 | 399 |
349 scoped_ptr<std::string> error(new std::string); | 400 scoped_ptr<std::string> error(new std::string); |
350 | 401 |
351 // Runs ConnectToNetwork on |dbus_thread|. | 402 // Runs ConnectToNetwork on |dbus_thread|. |
352 dbus_thread_.task_runner()->PostTaskAndReply( | 403 dbus_thread_.task_runner()->PostTaskAndReply( |
353 FROM_HERE, | 404 FROM_HERE, |
354 base::Bind(&NetworkingPrivateLinux::ConnectToNetwork, | 405 base::Bind(&NetworkingPrivateLinux::ConnectToNetwork, |
355 base::Unretained(this), | 406 base::Unretained(this), guid, base::Unretained(error.get())), |
356 guid, | 407 base::Bind(&OnNetworkConnectOperationCompleted, base::Passed(&error), |
357 base::Unretained(error.get())), | 408 success_callback, failure_callback)); |
358 base::Bind(&OnNetworkConnected, | |
359 base::Passed(&error), | |
360 success_callback, | |
361 failure_callback)); | |
362 } | 409 } |
363 | 410 |
364 void NetworkingPrivateLinux::StartDisconnect( | 411 void NetworkingPrivateLinux::StartDisconnect( |
365 const std::string& guid, | 412 const std::string& guid, |
366 const VoidCallback& success_callback, | 413 const VoidCallback& success_callback, |
367 const FailureCallback& failure_callback) { | 414 const FailureCallback& failure_callback) { |
368 ReportNotSupported("StartDisconnect", failure_callback); | 415 if (!CheckNetworkManagerSupported(failure_callback)) |
416 return; | |
417 | |
418 scoped_ptr<std::string> error(new std::string); | |
419 | |
420 // Runs DisconnectFromNetwork on |dbus_thread|. | |
421 dbus_thread_.task_runner()->PostTaskAndReply( | |
422 FROM_HERE, | |
423 base::Bind(&NetworkingPrivateLinux::DisconnectFromNetwork, | |
424 base::Unretained(this), guid, base::Unretained(error.get())), | |
425 base::Bind(&OnNetworkConnectOperationCompleted, base::Passed(&error), | |
426 success_callback, failure_callback)); | |
369 } | 427 } |
370 | 428 |
371 void NetworkingPrivateLinux::SetWifiTDLSEnabledState( | 429 void NetworkingPrivateLinux::SetWifiTDLSEnabledState( |
372 const std::string& ip_or_mac_address, | 430 const std::string& ip_or_mac_address, |
373 bool enabled, | 431 bool enabled, |
374 const StringCallback& success_callback, | 432 const StringCallback& success_callback, |
375 const FailureCallback& failure_callback) { | 433 const FailureCallback& failure_callback) { |
376 ReportNotSupported("SetWifiTDLSEnabledState", failure_callback); | 434 ReportNotSupported("SetWifiTDLSEnabledState", failure_callback); |
377 } | 435 } |
378 | 436 |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
874 | 932 |
875 if (!variant_reader.PopObjectPath(access_point_path)) { | 933 if (!variant_reader.PopObjectPath(access_point_path)) { |
876 LOG(ERROR) << "Unexpected response: " << response->ToString(); | 934 LOG(ERROR) << "Unexpected response: " << response->ToString(); |
877 return false; | 935 return false; |
878 } | 936 } |
879 | 937 |
880 return true; | 938 return true; |
881 } | 939 } |
882 | 940 |
883 } // namespace extensions | 941 } // namespace extensions |
OLD | NEW |