Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: components/wifi/wifi_test.cc

Issue 86123003: Use WiFi.Frequency property to set desired band for networkingPrivateApi.StartConnect() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Antonio's comment. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « components/wifi/wifi_service_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 <stdio.h> 5 #include <stdio.h>
6 #include <iostream>
7 #include <string> 6 #include <string>
8 7
9 #include "base/at_exit.h" 8 #include "base/at_exit.h"
10 #include "base/bind.h" 9 #include "base/bind.h"
11 #include "base/cancelable_callback.h" 10 #include "base/cancelable_callback.h"
12 #include "base/command_line.h" 11 #include "base/command_line.h"
13 #include "base/file_util.h" 12 #include "base/file_util.h"
14 #include "base/logging.h" 13 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #endif 57 #endif
59 58
60 // Need AtExitManager to support AsWeakPtr (in NetLog). 59 // Need AtExitManager to support AsWeakPtr (in NetLog).
61 base::AtExitManager exit_manager_; 60 base::AtExitManager exit_manager_;
62 61
63 Result result_; 62 Result result_;
64 }; 63 };
65 64
66 WiFiTest::Result WiFiTest::Main(int argc, const char* argv[]) { 65 WiFiTest::Result WiFiTest::Main(int argc, const char* argv[]) {
67 if (!ParseCommandLine(argc, argv)) { 66 if (!ParseCommandLine(argc, argv)) {
68 fprintf(stderr, 67 VLOG(0) << "Usage: " << argv[0] <<
69 "usage: %s [--list]" 68 " [--list]"
70 " [--get_properties]" 69 " [--get_properties]"
71 " [--connect]" 70 " [--connect]"
72 " [--disconnect]" 71 " [--disconnect]"
73 " [--network_guid=<network_guid>]" 72 " [--network_guid=<network_guid>]"
74 " [--frequency=0|2400|5000]" 73 " [--frequency=0|2400|5000]"
75 " [<network_guid>]\n", 74 " [<network_guid>]\n";
76 argv[0]);
77 return RESULT_WRONG_USAGE; 75 return RESULT_WRONG_USAGE;
78 } 76 }
79 77
80 base::MessageLoopForIO loop; 78 base::MessageLoopForIO loop;
81 result_ = RESULT_PENDING; 79 result_ = RESULT_PENDING;
82 80
83 return result_; 81 return result_;
84 } 82 }
85 83
86 bool WiFiTest::ParseCommandLine(int argc, const char* argv[]) { 84 bool WiFiTest::ParseCommandLine(int argc, const char* argv[]) {
87 CommandLine::Init(argc, argv); 85 CommandLine::Init(argc, argv);
88 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 86 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
89 std::string network_guid = 87 std::string network_guid =
90 parsed_command_line.GetSwitchValueASCII("network_guid"); 88 parsed_command_line.GetSwitchValueASCII("network_guid");
89 std::string frequency =
90 parsed_command_line.GetSwitchValueASCII("frequency");
91 91
92 if (parsed_command_line.GetArgs().size() == 1) { 92 if (parsed_command_line.GetArgs().size() == 1) {
93 #if defined(OS_WIN) 93 #if defined(OS_WIN)
94 network_guid = WideToASCII(parsed_command_line.GetArgs()[0]); 94 network_guid = WideToASCII(parsed_command_line.GetArgs()[0]);
95 #else 95 #else
96 network_guid = parsed_command_line.GetArgs()[0]; 96 network_guid = parsed_command_line.GetArgs()[0];
97 #endif 97 #endif
98 } 98 }
99 99
100 #if defined(OS_WIN) 100 #if defined(OS_WIN)
101 if (parsed_command_line.HasSwitch("debug")) 101 if (parsed_command_line.HasSwitch("debug"))
102 MessageBoxA(NULL, __FUNCTION__, "Debug Me!", MB_OK); 102 MessageBoxA(NULL, __FUNCTION__, "Debug Me!", MB_OK);
103 #endif 103 #endif
104 104
105 #if defined(OS_WIN) 105 #if defined(OS_WIN)
106 scoped_ptr<WiFiService> wifi_service(WiFiService::Create()); 106 scoped_ptr<WiFiService> wifi_service(WiFiService::Create());
107 #else 107 #else
108 scoped_ptr<WiFiService> wifi_service(WiFiService::CreateForTest()); 108 scoped_ptr<WiFiService> wifi_service(WiFiService::CreateForTest());
109 #endif 109 #endif
110 110
111 wifi_service->Initialize(NULL); 111 wifi_service->Initialize(NULL);
112 112
113 if (parsed_command_line.HasSwitch("list")) { 113 if (parsed_command_line.HasSwitch("list")) {
114 ListValue network_list; 114 ListValue network_list;
115 wifi_service->GetVisibleNetworks(std::string(), &network_list); 115 wifi_service->GetVisibleNetworks(std::string(), &network_list);
116 std::cout << network_list; 116 VLOG(0) << network_list;
117 return true; 117 return true;
118 } 118 }
119 119
120 if (parsed_command_line.HasSwitch("get_properties")) { 120 if (parsed_command_line.HasSwitch("get_properties")) {
121 if (network_guid.length() > 0) { 121 if (network_guid.length() > 0) {
122 DictionaryValue properties; 122 DictionaryValue properties;
123 std::string error; 123 std::string error;
124 wifi_service->GetProperties(network_guid, &properties, &error); 124 wifi_service->GetProperties(network_guid, &properties, &error);
125 std::cout << error << ":\n" << properties; 125 VLOG(0) << error << ":\n" << properties;
126 return true; 126 return true;
127 } 127 }
128 } 128 }
129 129
130 // Optional properties (frequency, password) to use for connect.
131 scoped_ptr<DictionaryValue> connect_properties(new DictionaryValue());
132
133 if (parsed_command_line.HasSwitch("frequency")) {
134 int value = 0;
135 if (!network_guid.empty() &&
136 !frequency.empty() &&
137 base::StringToInt(frequency, &value)) {
138 connect_properties->SetInteger("WiFi.Frequency", value);
139 // fall through to connect.
140 }
141 }
142
130 if (parsed_command_line.HasSwitch("connect")) { 143 if (parsed_command_line.HasSwitch("connect")) {
131 if (network_guid.length() > 0) { 144 if (network_guid.length() > 0) {
132 std::string error; 145 std::string error;
146 if (!connect_properties->empty()) {
147 VLOG(0) << "Using connect properties: " << *connect_properties;
148 wifi_service->SetProperties(network_guid,
149 connect_properties.Pass(),
150 &error);
151 }
133 wifi_service->StartConnect(network_guid, &error); 152 wifi_service->StartConnect(network_guid, &error);
134 std::cout << error; 153 VLOG(0) << error;
135 return true; 154 return true;
136 } 155 }
137 } 156 }
138 157
139 if (parsed_command_line.HasSwitch("disconnect")) { 158 if (parsed_command_line.HasSwitch("disconnect")) {
140 if (network_guid.length() > 0) { 159 if (network_guid.length() > 0) {
141 std::string error; 160 std::string error;
142 wifi_service->StartDisconnect(network_guid, &error); 161 wifi_service->StartDisconnect(network_guid, &error);
143 std::cout << error; 162 VLOG(0) << error;
144 return true; 163 return true;
145 } 164 }
146 } 165 }
147 166
148 return false; 167 return false;
149 } 168 }
150 169
151 } // namespace wifi 170 } // namespace wifi
152 171
153 int main(int argc, const char* argv[]) { 172 int main(int argc, const char* argv[]) {
173 CommandLine::Init(argc, argv);
174 logging::LoggingSettings settings;
175 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
176 logging::InitLogging(settings);
177
154 wifi::WiFiTest wifi_test; 178 wifi::WiFiTest wifi_test;
155 return wifi_test.Main(argc, argv); 179 return wifi_test.Main(argc, argv);
156 } 180 }
OLDNEW
« no previous file with comments | « components/wifi/wifi_service_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698