OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/automation/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/automation/automation_provider_json.h" | 8 #include "chrome/browser/automation/automation_provider_json.h" |
9 #include "chrome/browser/automation/automation_provider_observers.h" | 9 #include "chrome/browser/automation/automation_provider_observers.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 new LoginManagerObserver(this, reply_message); | 59 new LoginManagerObserver(this, reply_message); |
60 controller->LoginAsGuest(); | 60 controller->LoginAsGuest(); |
61 } | 61 } |
62 | 62 |
63 void TestingAutomationProvider::Login(DictionaryValue* args, | 63 void TestingAutomationProvider::Login(DictionaryValue* args, |
64 IPC::Message* reply_message) { | 64 IPC::Message* reply_message) { |
65 std::string username, password; | 65 std::string username, password; |
66 if (!args->GetString("username", &username) || | 66 if (!args->GetString("username", &username) || |
67 !args->GetString("password", &password)) { | 67 !args->GetString("password", &password)) { |
68 AutomationJSONReply(this, reply_message).SendError( | 68 AutomationJSONReply(this, reply_message).SendError( |
69 "Invalid or missing args"); | 69 "Invalid or missing args."); |
70 return; | 70 return; |
71 } | 71 } |
72 | 72 |
73 chromeos::ExistingUserController* controller = | 73 chromeos::ExistingUserController* controller = |
74 chromeos::ExistingUserController::current_controller(); | 74 chromeos::ExistingUserController::current_controller(); |
75 // Set up an observer (it will delete itself). | 75 // Set up an observer (it will delete itself). |
76 new LoginManagerObserver(this, reply_message); | 76 new LoginManagerObserver(this, reply_message); |
77 controller->Login(username, password); | 77 controller->Login(username, password); |
78 } | 78 } |
79 | 79 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 item->SetString("roaming_state", | 189 item->SetString("roaming_state", |
190 cellular_networks[i]->GetRoamingStateString()); | 190 cellular_networks[i]->GetRoamingStateString()); |
191 items->Append(item); | 191 items->Append(item); |
192 } | 192 } |
193 return_value->Set("cellular_networks", items); | 193 return_value->Set("cellular_networks", items); |
194 } | 194 } |
195 | 195 |
196 reply.SendSuccess(return_value.get()); | 196 reply.SendSuccess(return_value.get()); |
197 } | 197 } |
198 | 198 |
| 199 void TestingAutomationProvider::NetworkScan(DictionaryValue* args, |
| 200 IPC::Message* reply_message) { |
| 201 AutomationJSONReply reply(this, reply_message); |
| 202 |
| 203 if (!CrosLibrary::Get()->EnsureLoaded()) { |
| 204 reply.SendError("Could not load cros library."); |
| 205 return; |
| 206 } |
| 207 |
| 208 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); |
| 209 network_library->RequestNetworkScan(); |
| 210 |
| 211 // Set up an observer (it will delete itself). |
| 212 new NetworkScanObserver(this, reply_message); |
| 213 } |
| 214 |
199 void TestingAutomationProvider::ConnectToWifiNetwork( | 215 void TestingAutomationProvider::ConnectToWifiNetwork( |
200 DictionaryValue* args, IPC::Message* reply_message) { | 216 DictionaryValue* args, IPC::Message* reply_message) { |
201 AutomationJSONReply reply(this, reply_message); | 217 AutomationJSONReply reply(this, reply_message); |
202 std::string service_path, password, identity, certpath; | 218 std::string service_path, password, identity, certpath; |
203 if (!args->GetString("service_path", &service_path) || | 219 if (!args->GetString("service_path", &service_path) || |
204 !args->GetString("password", &password) || | 220 !args->GetString("password", &password) || |
205 !args->GetString("identity", &identity) || | 221 !args->GetString("identity", &identity) || |
206 !args->GetString("certpath", &certpath)) { | 222 !args->GetString("certpath", &certpath)) { |
207 reply.SendError("Invalid or missing args"); | 223 reply.SendError("Invalid or missing args."); |
208 return; | 224 return; |
209 } | 225 } |
210 | 226 |
211 if (!CrosLibrary::Get()->EnsureLoaded()) { | 227 if (!CrosLibrary::Get()->EnsureLoaded()) { |
212 reply.SendError("Could not load cros library."); | 228 reply.SendError("Could not load cros library."); |
213 return; | 229 return; |
214 } | 230 } |
215 | 231 |
216 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); | 232 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); |
217 chromeos::WifiNetwork* wifi = | 233 chromeos::WifiNetwork* wifi = |
218 network_library->FindWifiNetworkByPath(service_path); | 234 network_library->FindWifiNetworkByPath(service_path); |
219 if (!wifi) { | 235 if (!wifi) { |
220 reply.SendError("Failed to connect"); | 236 reply.SendError("No network found with specified service path."); |
221 return; | 237 return; |
222 } | 238 } |
223 if (!password.empty()) | 239 if (!password.empty()) |
224 wifi->SetPassphrase(password); | 240 wifi->SetPassphrase(password); |
225 if (!identity.empty()) | 241 if (!identity.empty()) |
226 wifi->SetIdentity(identity); | 242 wifi->SetIdentity(identity); |
227 if (!certpath.empty()) | 243 if (!certpath.empty()) |
228 wifi->SetCertPath(certpath); | 244 wifi->SetCertPath(certpath); |
229 network_library->ConnectToWifiNetwork(service_path); | |
230 | 245 |
231 // TODO(stevenjb): Observe the network library and check for a successful | 246 // Set up an observer (it will delete itself). |
232 // connection. | 247 new NetworkConnectObserver(this, reply_message, service_path); |
233 | 248 |
| 249 network_library->ConnectToWifiNetwork(wifi); |
| 250 network_library->RequestNetworkScan(); |
| 251 } |
| 252 |
| 253 void TestingAutomationProvider::DisconnectFromWifiNetwork( |
| 254 DictionaryValue* args, IPC::Message* reply_message) { |
| 255 AutomationJSONReply reply(this, reply_message); |
| 256 std::string service_path; |
| 257 if (!args->GetString("service_path", &service_path)) { |
| 258 reply.SendError("Invalid or missing args."); |
| 259 return; |
| 260 } |
| 261 |
| 262 if (!CrosLibrary::Get()->EnsureLoaded()) { |
| 263 reply.SendError("Could not load cros library."); |
| 264 return; |
| 265 } |
| 266 |
| 267 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); |
| 268 chromeos::WifiNetwork* wifi = |
| 269 network_library->FindWifiNetworkByPath(service_path); |
| 270 if (!wifi) { |
| 271 reply.SendError("No network found with specified service path."); |
| 272 return; |
| 273 } |
| 274 |
| 275 network_library->DisconnectFromWirelessNetwork(wifi); |
234 reply.SendSuccess(NULL); | 276 reply.SendSuccess(NULL); |
235 } | 277 } |
OLD | NEW |