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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 scoped_ptr<std::string> error, | 108 scoped_ptr<std::string> error, |
109 const NetworkingPrivateDelegate::VoidCallback& success_callback, | 109 const NetworkingPrivateDelegate::VoidCallback& success_callback, |
110 const NetworkingPrivateDelegate::FailureCallback& failure_callback) { | 110 const NetworkingPrivateDelegate::FailureCallback& failure_callback) { |
111 if (!error->empty()) { | 111 if (!error->empty()) { |
112 failure_callback.Run(*error); | 112 failure_callback.Run(*error); |
113 return; | 113 return; |
114 } | 114 } |
115 success_callback.Run(); | 115 success_callback.Run(); |
116 } | 116 } |
117 | 117 |
118 // Fires the appropriate callback when the network disconnection succeeds or | |
119 // fails. | |
stevenjb
2014/12/05 20:39:43
Since this is identical to OnNetworkConnected, may
zentaro
2014/12/05 21:39:33
Done.
| |
120 void OnNetworkDisconnected( | |
121 scoped_ptr<std::string> error, | |
122 const NetworkingPrivateDelegate::VoidCallback& success_callback, | |
123 const NetworkingPrivateDelegate::FailureCallback& failure_callback) { | |
124 if (!error->empty()) { | |
125 failure_callback.Run(*error); | |
126 return; | |
127 } | |
128 success_callback.Run(); | |
129 } | |
130 | |
118 } // namespace | 131 } // namespace |
119 | 132 |
120 NetworkingPrivateLinux::NetworkingPrivateLinux( | 133 NetworkingPrivateLinux::NetworkingPrivateLinux( |
121 content::BrowserContext* browser_context, | 134 content::BrowserContext* browser_context, |
122 scoped_ptr<VerifyDelegate> verify_delegate) | 135 scoped_ptr<VerifyDelegate> verify_delegate) |
123 : NetworkingPrivateDelegate(verify_delegate.Pass()), | 136 : NetworkingPrivateDelegate(verify_delegate.Pass()), |
124 browser_context_(browser_context), | 137 browser_context_(browser_context), |
125 dbus_thread_("Networking Private DBus"), | 138 dbus_thread_("Networking Private DBus"), |
126 network_manager_proxy_(NULL) { | 139 network_manager_proxy_(NULL) { |
127 base::Thread::Options thread_options(base::MessageLoop::Type::TYPE_IO, 0); | 140 base::Thread::Options thread_options(base::MessageLoop::Type::TYPE_IO, 0); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 if (!reader.PopObjectPath(&active_connection_path)) { | 345 if (!reader.PopObjectPath(&active_connection_path)) { |
333 LOG(ERROR) << "Unexpected response for connection path " | 346 LOG(ERROR) << "Unexpected response for connection path " |
334 << ": " << response->ToString(); | 347 << ": " << response->ToString(); |
335 *error = "Failed to connect."; | 348 *error = "Failed to connect."; |
336 return; | 349 return; |
337 } | 350 } |
338 | 351 |
339 return; | 352 return; |
340 } | 353 } |
341 | 354 |
355 void NetworkingPrivateLinux::DisconnectFromNetwork(const std::string& guid, | |
356 std::string* error) { | |
357 AssertOnDBusThread(); | |
358 std::string device_path_str; | |
359 std::string access_point_path_str; | |
360 std::string ssid; | |
361 DVLOG(1) << "Disconnecting from network GUID " << guid; | |
362 | |
363 if (!ParseNetworkGuid(guid, &device_path_str, &access_point_path_str, | |
364 &ssid)) { | |
365 *error = "Invalid Network GUID format"; | |
366 return; | |
367 } | |
368 | |
369 dbus::ObjectPath device_path(device_path_str); | |
stevenjb
2014/12/05 20:39:43
This is only used once below (the other time shoul
zentaro
2014/12/05 21:39:33
It's used in the log statement on 397 too.
| |
370 | |
371 scoped_ptr<NetworkMap> network_map(new NetworkMap); | |
372 GetAllWiFiAccessPoints(/* configured_only */ false, /* visible_only */ false, | |
stevenjb
2014/12/05 20:39:43
switch order: (false /* configured_only */, ...)
zentaro
2014/12/05 21:39:33
Done.
| |
373 /* limit */ 0, network_map.get()); | |
374 | |
375 NetworkMap::const_iterator network_iter = | |
376 network_map->find(base::UTF8ToUTF16(ssid)); | |
377 if (network_iter == network_map->end()) { | |
378 // This network doesn't exist so there's nothing to do. | |
379 return; | |
380 } | |
381 | |
382 std::string connection_state; | |
383 network_iter->second->GetString(kAccessPointInfoConnectionState, | |
384 &connection_state); | |
385 if (connection_state != ::onc::connection_state::kNotConnected) { | |
stevenjb
2014/12/05 20:39:43
Invert + early exit
zentaro
2014/12/05 21:39:33
Done.
| |
386 // It's not disconnected so disconnect it. | |
387 dbus::ObjectProxy* device_proxy = dbus_->GetObjectProxy( | |
388 networking_private::kNetworkManagerNamespace, device_path); | |
389 dbus::MethodCall method_call( | |
390 networking_private::kNetworkManagerDeviceNamespace, | |
391 networking_private::kNetworkManagerDisconnectMethod); | |
392 scoped_ptr<dbus::Response> response(device_proxy->CallMethodAndBlock( | |
393 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
394 | |
395 if (!response) { | |
396 LOG(WARNING) << "Failed to disconnect network on device " | |
397 << device_path.value(); | |
398 *error = "Failed to disconnect network"; | |
399 return; | |
400 } | |
401 } | |
402 } | |
403 | |
342 void NetworkingPrivateLinux::StartConnect( | 404 void NetworkingPrivateLinux::StartConnect( |
343 const std::string& guid, | 405 const std::string& guid, |
344 const VoidCallback& success_callback, | 406 const VoidCallback& success_callback, |
345 const FailureCallback& failure_callback) { | 407 const FailureCallback& failure_callback) { |
346 if (!CheckNetworkManagerSupported(failure_callback)) | 408 if (!CheckNetworkManagerSupported(failure_callback)) |
347 return; | 409 return; |
348 | 410 |
349 scoped_ptr<std::string> error(new std::string); | 411 scoped_ptr<std::string> error(new std::string); |
350 | 412 |
351 // Runs ConnectToNetwork on |dbus_thread|. | 413 // Runs ConnectToNetwork on |dbus_thread|. |
352 dbus_thread_.task_runner()->PostTaskAndReply( | 414 dbus_thread_.task_runner()->PostTaskAndReply( |
353 FROM_HERE, | 415 FROM_HERE, |
354 base::Bind(&NetworkingPrivateLinux::ConnectToNetwork, | 416 base::Bind(&NetworkingPrivateLinux::ConnectToNetwork, |
355 base::Unretained(this), | 417 base::Unretained(this), |
356 guid, | 418 guid, |
357 base::Unretained(error.get())), | 419 base::Unretained(error.get())), |
358 base::Bind(&OnNetworkConnected, | 420 base::Bind(&OnNetworkConnected, |
359 base::Passed(&error), | 421 base::Passed(&error), |
360 success_callback, | 422 success_callback, |
361 failure_callback)); | 423 failure_callback)); |
362 } | 424 } |
363 | 425 |
364 void NetworkingPrivateLinux::StartDisconnect( | 426 void NetworkingPrivateLinux::StartDisconnect( |
365 const std::string& guid, | 427 const std::string& guid, |
366 const VoidCallback& success_callback, | 428 const VoidCallback& success_callback, |
367 const FailureCallback& failure_callback) { | 429 const FailureCallback& failure_callback) { |
368 ReportNotSupported("StartDisconnect", failure_callback); | 430 if (!CheckNetworkManagerSupported(failure_callback)) |
431 return; | |
432 | |
433 scoped_ptr<std::string> error(new std::string); | |
434 | |
435 // Runs DisconnectFromNetwork on |dbus_thread|. | |
436 dbus_thread_.task_runner()->PostTaskAndReply( | |
437 FROM_HERE, | |
438 base::Bind(&NetworkingPrivateLinux::DisconnectFromNetwork, | |
439 base::Unretained(this), guid, base::Unretained(error.get())), | |
440 base::Bind(&OnNetworkDisconnected, base::Passed(&error), success_callback, | |
441 failure_callback)); | |
369 } | 442 } |
370 | 443 |
371 void NetworkingPrivateLinux::SetWifiTDLSEnabledState( | 444 void NetworkingPrivateLinux::SetWifiTDLSEnabledState( |
372 const std::string& ip_or_mac_address, | 445 const std::string& ip_or_mac_address, |
373 bool enabled, | 446 bool enabled, |
374 const StringCallback& success_callback, | 447 const StringCallback& success_callback, |
375 const FailureCallback& failure_callback) { | 448 const FailureCallback& failure_callback) { |
376 ReportNotSupported("SetWifiTDLSEnabledState", failure_callback); | 449 ReportNotSupported("SetWifiTDLSEnabledState", failure_callback); |
377 } | 450 } |
378 | 451 |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
874 | 947 |
875 if (!variant_reader.PopObjectPath(access_point_path)) { | 948 if (!variant_reader.PopObjectPath(access_point_path)) { |
876 LOG(ERROR) << "Unexpected response: " << response->ToString(); | 949 LOG(ERROR) << "Unexpected response: " << response->ToString(); |
877 return false; | 950 return false; |
878 } | 951 } |
879 | 952 |
880 return true; | 953 return true; |
881 } | 954 } |
882 | 955 |
883 } // namespace extensions | 956 } // namespace extensions |
OLD | NEW |