Chromium Code Reviews| Index: components/wifi/wifi_test.cc |
| diff --git a/components/wifi/wifi_test.cc b/components/wifi/wifi_test.cc |
| index d88232fab75366456f9a867802d9e7bb6394245f..e9af6dfad5c91968631d60deb53abfb65bd9ab3d 100644 |
| --- a/components/wifi/wifi_test.cc |
| +++ b/components/wifi/wifi_test.cc |
| @@ -13,6 +13,7 @@ |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/message_loop/message_loop.h" |
| +#include "base/run_loop.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_split.h" |
| #include "base/strings/string_util.h" |
| @@ -52,11 +53,27 @@ class WiFiTest { |
| base::MessageLoop::current()->Quit(); |
| } |
| + void OnNetworksChanged( |
| + const WiFiService::NetworkGuidList& network_guid_list) { |
| + VLOG(0) << "Networks Changed: " << network_guid_list[0]; |
| + base::DictionaryValue properties; |
| + std::string error; |
| + wifi_service_->GetProperties(network_guid_list[0], &properties, &error); |
|
tbarzic
2014/04/23 20:53:56
quit loop if the target network connection status
mef
2014/04/23 21:41:23
It also gets notified about previously connected n
|
| + VLOG(0) << error << ":\n" << properties; |
| + } |
| + |
| + void OnNetworkListChanged( |
| + const WiFiService::NetworkGuidList& network_guid_list) { |
| + VLOG(0) << "Network List Changed: " << network_guid_list.size(); |
| + } |
| + |
| #if defined(OS_MACOSX) |
| // Without this there will be a mem leak on osx. |
| base::mac::ScopedNSAutoreleasePool scoped_pool_; |
| #endif |
| + scoped_ptr<WiFiService> wifi_service_; |
| + |
| // Need AtExitManager to support AsWeakPtr (in NetLog). |
| base::AtExitManager exit_manager_; |
| @@ -111,17 +128,14 @@ bool WiFiTest::ParseCommandLine(int argc, const char* argv[]) { |
| MessageBoxA(NULL, __FUNCTION__, "Debug Me!", MB_OK); |
| #endif |
| -#if defined(OS_WIN) || defined(OS_MACOSX) |
| - scoped_ptr<WiFiService> wifi_service(WiFiService::Create()); |
| -#else |
| - scoped_ptr<WiFiService> wifi_service(WiFiService::CreateForTest()); |
| -#endif |
| + base::MessageLoopForIO loop; |
| - wifi_service->Initialize(NULL); |
| + wifi_service_.reset(WiFiService::Create()); |
| + wifi_service_->Initialize(loop.message_loop_proxy()); |
| if (parsed_command_line.HasSwitch("list")) { |
| base::ListValue network_list; |
| - wifi_service->GetVisibleNetworks(std::string(), &network_list); |
| + wifi_service_->GetVisibleNetworks(std::string(), &network_list); |
| VLOG(0) << network_list; |
| return true; |
| } |
| @@ -130,7 +144,7 @@ bool WiFiTest::ParseCommandLine(int argc, const char* argv[]) { |
| if (network_guid.length() > 0) { |
| base::DictionaryValue properties; |
| std::string error; |
| - wifi_service->GetProperties(network_guid, &properties, &error); |
| + wifi_service_->GetProperties(network_guid, &properties, &error); |
| VLOG(0) << error << ":\n" << properties; |
| return true; |
| } |
| @@ -159,7 +173,7 @@ bool WiFiTest::ParseCommandLine(int argc, const char* argv[]) { |
| std::string new_network_guid; |
| properties->SetString("WiFi.SSID", network_guid); |
| VLOG(0) << "Creating Network: " << *properties; |
| - wifi_service->CreateNetwork(false, |
| + wifi_service_->CreateNetwork(false, |
| properties.Pass(), |
|
tbarzic
2014/04/23 20:53:56
indent
mef
2014/04/23 21:41:23
Done.
|
| &new_network_guid, |
| &error); |
| @@ -173,12 +187,21 @@ bool WiFiTest::ParseCommandLine(int argc, const char* argv[]) { |
| std::string error; |
| if (!properties->empty()) { |
| VLOG(0) << "Using connect properties: " << *properties; |
| - wifi_service->SetProperties(network_guid, |
| + wifi_service_->SetProperties(network_guid, |
| properties.Pass(), |
| &error); |
| } |
| - wifi_service->StartConnect(network_guid, &error); |
| + |
| + wifi_service_->SetEventObservers( |
| + loop.message_loop_proxy(), |
| + base::Bind(&WiFiTest::OnNetworksChanged, |
| + base::Unretained(this)), |
| + base::Bind(&WiFiTest::OnNetworkListChanged, |
| + base::Unretained(this))); |
| + |
| + wifi_service_->StartConnect(network_guid, &error); |
| VLOG(0) << error; |
| + base::MessageLoop::current()->Run(); |
| return true; |
| } |
| } |
| @@ -186,7 +209,7 @@ bool WiFiTest::ParseCommandLine(int argc, const char* argv[]) { |
| if (parsed_command_line.HasSwitch("disconnect")) { |
| if (network_guid.length() > 0) { |
| std::string error; |
| - wifi_service->StartDisconnect(network_guid, &error); |
| + wifi_service_->StartDisconnect(network_guid, &error); |
| VLOG(0) << error; |
| return true; |
| } |
| @@ -196,7 +219,7 @@ bool WiFiTest::ParseCommandLine(int argc, const char* argv[]) { |
| if (network_guid.length() > 0) { |
| std::string error; |
| std::string key_data; |
| - wifi_service->GetKeyFromSystem(network_guid, |
| + wifi_service_->GetKeyFromSystem(network_guid, |
| &key_data, |
| &error); |
| VLOG(0) << key_data << error; |