OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chromeos/dbus/shill_service_client_stub.h" | 5 #include "chromeos/dbus/shill_service_client_stub.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 error_callback.Run("Error.InvalidService", "Invalid Service"); | 105 error_callback.Run("Error.InvalidService", "Invalid Service"); |
106 return; | 106 return; |
107 } | 107 } |
108 if (name == flimflam::kStateProperty) { | 108 if (name == flimflam::kStateProperty) { |
109 // If we connect to a service, then we move it to the top of the list in | 109 // If we connect to a service, then we move it to the top of the list in |
110 // the manager client. | 110 // the manager client. |
111 std::string state; | 111 std::string state; |
112 if (value.GetAsString(&state) && state == flimflam::kStateOnline) { | 112 if (value.GetAsString(&state) && state == flimflam::kStateOnline) { |
113 ShillManagerClient* manager_client = | 113 ShillManagerClient* manager_client = |
114 DBusThreadManager::Get()->GetShillManagerClient(); | 114 DBusThreadManager::Get()->GetShillManagerClient(); |
115 manager_client->GetTestInterface()->RemoveService(service_path.value()); | 115 manager_client->GetTestInterface()->MoveServiceToIndex( |
116 manager_client->GetTestInterface()->AddServiceAtIndex( | |
117 service_path.value(), 0, true); | 116 service_path.value(), 0, true); |
118 } | 117 } |
119 } | 118 } |
120 dict->SetWithoutPathExpansion(name, value.DeepCopy()); | 119 dict->SetWithoutPathExpansion(name, value.DeepCopy()); |
121 MessageLoop::current()->PostTask( | 120 MessageLoop::current()->PostTask( |
122 FROM_HERE, | 121 FROM_HERE, |
123 base::Bind(&ShillServiceClientStub::NotifyObserversPropertyChanged, | 122 base::Bind(&ShillServiceClientStub::NotifyObserversPropertyChanged, |
124 weak_ptr_factory_.GetWeakPtr(), service_path, name)); | 123 weak_ptr_factory_.GetWeakPtr(), service_path, name)); |
125 if (callback.is_null()) | 124 if (callback.is_null()) |
126 return; | 125 return; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 181 } |
183 | 182 |
184 void ShillServiceClientStub::Connect(const dbus::ObjectPath& service_path, | 183 void ShillServiceClientStub::Connect(const dbus::ObjectPath& service_path, |
185 const base::Closure& callback, | 184 const base::Closure& callback, |
186 const ErrorCallback& error_callback) { | 185 const ErrorCallback& error_callback) { |
187 base::Value* service; | 186 base::Value* service; |
188 if (!stub_services_.Get(service_path.value(), &service)) { | 187 if (!stub_services_.Get(service_path.value(), &service)) { |
189 error_callback.Run("Error.InvalidService", "Invalid Service"); | 188 error_callback.Run("Error.InvalidService", "Invalid Service"); |
190 return; | 189 return; |
191 } | 190 } |
192 // Set Associating | 191 base::TimeDelta delay; |
193 base::StringValue associating_value(flimflam::kStateAssociation); | 192 if (CommandLine::ForCurrentProcess()->HasSwitch( |
194 SetServiceProperty(service_path.value(), | 193 chromeos::switches::kEnableStubInteractive)) { |
195 flimflam::kStateProperty, | 194 // Set Associating |
196 associating_value); | 195 base::StringValue associating_value(flimflam::kStateAssociation); |
| 196 SetServiceProperty(service_path.value(), |
| 197 flimflam::kStateProperty, |
| 198 associating_value); |
| 199 const int kConnectDelaySeconds = 5; |
| 200 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); |
| 201 } |
197 // Set Online after a delay | 202 // Set Online after a delay |
198 const int kConnectDelaySeconds = 5; | |
199 base::StringValue online_value(flimflam::kStateOnline); | 203 base::StringValue online_value(flimflam::kStateOnline); |
200 MessageLoop::current()->PostDelayedTask( | 204 MessageLoop::current()->PostDelayedTask( |
201 FROM_HERE, | 205 FROM_HERE, |
202 base::Bind(&ShillServiceClientStub::SetProperty, | 206 base::Bind(&ShillServiceClientStub::SetProperty, |
203 weak_ptr_factory_.GetWeakPtr(), | 207 weak_ptr_factory_.GetWeakPtr(), |
204 service_path, | 208 service_path, |
205 flimflam::kStateProperty, | 209 flimflam::kStateProperty, |
206 online_value, | 210 online_value, |
207 base::Bind(&base::DoNothing), | 211 base::Bind(&base::DoNothing), |
208 error_callback), | 212 error_callback), |
209 base::TimeDelta::FromSeconds(kConnectDelaySeconds)); | 213 delay); |
210 callback.Run(); | 214 callback.Run(); |
211 } | 215 } |
212 | 216 |
213 void ShillServiceClientStub::Disconnect(const dbus::ObjectPath& service_path, | 217 void ShillServiceClientStub::Disconnect(const dbus::ObjectPath& service_path, |
214 const base::Closure& callback, | 218 const base::Closure& callback, |
215 const ErrorCallback& error_callback) { | 219 const ErrorCallback& error_callback) { |
216 base::Value* service; | 220 base::Value* service; |
217 if (!stub_services_.Get(service_path.value(), &service)) { | 221 if (!stub_services_.Get(service_path.value(), &service)) { |
218 error_callback.Run("Error.InvalidService", "Invalid Service"); | 222 error_callback.Run("Error.InvalidService", "Invalid Service"); |
219 return; | 223 return; |
220 } | 224 } |
| 225 base::TimeDelta delay; |
| 226 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 227 chromeos::switches::kEnableStubInteractive)) { |
| 228 const int kConnectDelaySeconds = 2; |
| 229 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); |
| 230 } |
221 // Set Idle after a delay | 231 // Set Idle after a delay |
222 const int kConnectDelaySeconds = 2; | |
223 base::StringValue idle_value(flimflam::kStateIdle); | 232 base::StringValue idle_value(flimflam::kStateIdle); |
224 MessageLoop::current()->PostDelayedTask( | 233 MessageLoop::current()->PostDelayedTask( |
225 FROM_HERE, | 234 FROM_HERE, |
226 base::Bind(&ShillServiceClientStub::SetProperty, | 235 base::Bind(&ShillServiceClientStub::SetProperty, |
227 weak_ptr_factory_.GetWeakPtr(), | 236 weak_ptr_factory_.GetWeakPtr(), |
228 service_path, | 237 service_path, |
229 flimflam::kStateProperty, | 238 flimflam::kStateProperty, |
230 idle_value, | 239 idle_value, |
231 base::Bind(&base::DoNothing), | 240 base::Bind(&base::DoNothing), |
232 error_callback), | 241 error_callback), |
233 base::TimeDelta::FromSeconds(kConnectDelaySeconds)); | 242 delay); |
234 callback.Run(); | 243 callback.Run(); |
235 } | 244 } |
236 | 245 |
237 void ShillServiceClientStub::Remove(const dbus::ObjectPath& service_path, | 246 void ShillServiceClientStub::Remove(const dbus::ObjectPath& service_path, |
238 const base::Closure& callback, | 247 const base::Closure& callback, |
239 const ErrorCallback& error_callback) { | 248 const ErrorCallback& error_callback) { |
240 if (callback.is_null()) | 249 if (callback.is_null()) |
241 return; | 250 return; |
242 MessageLoop::current()->PostTask(FROM_HERE, callback); | 251 MessageLoop::current()->PostTask(FROM_HERE, callback); |
243 } | 252 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 } | 292 } |
284 | 293 |
285 void ShillServiceClientStub::AddServiceWithIPConfig( | 294 void ShillServiceClientStub::AddServiceWithIPConfig( |
286 const std::string& service_path, | 295 const std::string& service_path, |
287 const std::string& name, | 296 const std::string& name, |
288 const std::string& type, | 297 const std::string& type, |
289 const std::string& state, | 298 const std::string& state, |
290 const std::string& ipconfig_path, | 299 const std::string& ipconfig_path, |
291 bool add_to_watch_list) { | 300 bool add_to_watch_list) { |
292 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 301 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
293 AddService(service_path, add_to_watch_list); | 302 AddManagerService(service_path, add_to_watch_list); |
294 | 303 |
295 base::DictionaryValue* properties = | 304 base::DictionaryValue* properties = |
296 GetModifiableServiceProperties(service_path); | 305 GetModifiableServiceProperties(service_path); |
297 properties->SetWithoutPathExpansion( | 306 properties->SetWithoutPathExpansion( |
298 flimflam::kSSIDProperty, | 307 flimflam::kSSIDProperty, |
299 base::Value::CreateStringValue(service_path)); | 308 base::Value::CreateStringValue(service_path)); |
300 properties->SetWithoutPathExpansion( | 309 properties->SetWithoutPathExpansion( |
301 flimflam::kNameProperty, | 310 flimflam::kNameProperty, |
302 base::Value::CreateStringValue(name)); | 311 base::Value::CreateStringValue(name)); |
303 properties->SetWithoutPathExpansion( | 312 properties->SetWithoutPathExpansion( |
304 flimflam::kTypeProperty, | 313 flimflam::kTypeProperty, |
305 base::Value::CreateStringValue(type)); | 314 base::Value::CreateStringValue(type)); |
306 properties->SetWithoutPathExpansion( | 315 properties->SetWithoutPathExpansion( |
307 flimflam::kStateProperty, | 316 flimflam::kStateProperty, |
308 base::Value::CreateStringValue(state)); | 317 base::Value::CreateStringValue(state)); |
309 if (!ipconfig_path.empty()) | 318 if (!ipconfig_path.empty()) |
310 properties->SetWithoutPathExpansion( | 319 properties->SetWithoutPathExpansion( |
311 shill::kIPConfigProperty, | 320 shill::kIPConfigProperty, |
312 base::Value::CreateStringValue(ipconfig_path)); | 321 base::Value::CreateStringValue(ipconfig_path)); |
313 } | 322 } |
314 | 323 |
315 void ShillServiceClientStub::RemoveService(const std::string& service_path) { | 324 void ShillServiceClientStub::RemoveService(const std::string& service_path) { |
316 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 325 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
317 RemoveService(service_path); | 326 RemoveManagerService(service_path); |
318 | 327 |
319 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); | 328 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); |
320 } | 329 } |
321 | 330 |
322 void ShillServiceClientStub::SetServiceProperty(const std::string& service_path, | 331 void ShillServiceClientStub::SetServiceProperty(const std::string& service_path, |
323 const std::string& property, | 332 const std::string& property, |
324 const base::Value& value) { | 333 const base::Value& value) { |
325 SetProperty(dbus::ObjectPath(service_path), property, value, | 334 SetProperty(dbus::ObjectPath(service_path), property, value, |
326 base::Bind(&base::DoNothing), | 335 base::Bind(&base::DoNothing), |
327 base::Bind(&ErrorFunction)); | 336 base::Bind(&ErrorFunction)); |
328 } | 337 } |
329 | 338 |
330 const base::DictionaryValue* ShillServiceClientStub::GetServiceProperties( | 339 const base::DictionaryValue* ShillServiceClientStub::GetServiceProperties( |
331 const std::string& service_path) const { | 340 const std::string& service_path) const { |
332 const base::DictionaryValue* properties = NULL; | 341 const base::DictionaryValue* properties = NULL; |
333 stub_services_.GetDictionaryWithoutPathExpansion(service_path, &properties); | 342 stub_services_.GetDictionaryWithoutPathExpansion(service_path, &properties); |
334 return properties; | 343 return properties; |
335 } | 344 } |
336 | 345 |
337 void ShillServiceClientStub::ClearServices() { | 346 void ShillServiceClientStub::ClearServices() { |
338 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 347 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
339 ClearServices(); | 348 ClearManagerServices(); |
340 | 349 |
341 stub_services_.Clear(); | 350 stub_services_.Clear(); |
342 } | 351 } |
343 | 352 |
344 void ShillServiceClientStub::SetDefaultProperties() { | 353 void ShillServiceClientStub::SetDefaultProperties() { |
345 const bool add_to_watchlist = true; | 354 const bool add_to_watchlist = true; |
346 | 355 |
347 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 356 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
348 chromeos::switches::kDisableStubEthernet)) { | 357 chromeos::switches::kDisableStubEthernet)) { |
349 AddService("stub_ethernet", "eth0", | 358 AddService("stub_ethernet", "eth0", |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = | 443 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = |
435 observer_list_.find(device_path); | 444 observer_list_.find(device_path); |
436 if (iter != observer_list_.end()) | 445 if (iter != observer_list_.end()) |
437 return *(iter->second); | 446 return *(iter->second); |
438 PropertyObserverList* observer_list = new PropertyObserverList(); | 447 PropertyObserverList* observer_list = new PropertyObserverList(); |
439 observer_list_[device_path] = observer_list; | 448 observer_list_[device_path] = observer_list; |
440 return *observer_list; | 449 return *observer_list; |
441 } | 450 } |
442 | 451 |
443 } // namespace chromeos | 452 } // namespace chromeos |
OLD | NEW |