OLD | NEW |
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 "chromeos/dbus/fake_shill_service_client.h" | 5 #include "chromeos/dbus/fake_shill_service_client.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/command_line.h" | |
10 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
11 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
12 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
13 #include "base/values.h" | 12 #include "base/values.h" |
14 #include "chromeos/chromeos_switches.h" | |
15 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 #include "chromeos/dbus/shill_device_client.h" |
16 #include "chromeos/dbus/shill_manager_client.h" | 15 #include "chromeos/dbus/shill_manager_client.h" |
17 #include "chromeos/dbus/shill_property_changed_observer.h" | 16 #include "chromeos/dbus/shill_property_changed_observer.h" |
18 #include "chromeos/dbus/shill_stub_helper.h" | |
19 #include "chromeos/network/shill_property_util.h" | 17 #include "chromeos/network/shill_property_util.h" |
20 #include "dbus/bus.h" | 18 #include "dbus/bus.h" |
21 #include "dbus/message.h" | 19 #include "dbus/message.h" |
22 #include "dbus/object_path.h" | 20 #include "dbus/object_path.h" |
23 #include "third_party/cros_system_api/dbus/service_constants.h" | 21 #include "third_party/cros_system_api/dbus/service_constants.h" |
24 | 22 |
25 namespace chromeos { | 23 namespace chromeos { |
26 | 24 |
27 namespace { | 25 namespace { |
28 | 26 |
29 void PassStubListValue(const ShillServiceClient::ListValueCallback& callback, | 27 void PassStubListValue(const ShillServiceClient::ListValueCallback& callback, |
30 base::ListValue* value) { | 28 base::ListValue* value) { |
31 callback.Run(*value); | 29 callback.Run(*value); |
32 } | 30 } |
33 | 31 |
34 void PassStubServiceProperties( | 32 void PassStubServiceProperties( |
35 const ShillServiceClient::DictionaryValueCallback& callback, | 33 const ShillServiceClient::DictionaryValueCallback& callback, |
36 DBusMethodCallStatus call_status, | 34 DBusMethodCallStatus call_status, |
37 const base::DictionaryValue* properties) { | 35 const base::DictionaryValue* properties) { |
38 callback.Run(call_status, *properties); | 36 callback.Run(call_status, *properties); |
39 } | 37 } |
40 | 38 |
| 39 int GetInteractiveDelay() { |
| 40 return DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 41 GetInteractiveDelay(); |
| 42 } |
| 43 |
41 } // namespace | 44 } // namespace |
42 | 45 |
43 FakeShillServiceClient::FakeShillServiceClient() : weak_ptr_factory_(this) { | 46 FakeShillServiceClient::FakeShillServiceClient() : weak_ptr_factory_(this) { |
44 } | 47 } |
45 | 48 |
46 FakeShillServiceClient::~FakeShillServiceClient() { | 49 FakeShillServiceClient::~FakeShillServiceClient() { |
47 STLDeleteContainerPairSecondPointers( | 50 STLDeleteContainerPairSecondPointers( |
48 observer_list_.begin(), observer_list_.end()); | 51 observer_list_.begin(), observer_list_.end()); |
49 } | 52 } |
50 | 53 |
51 | 54 |
52 // ShillServiceClient overrides. | 55 // ShillServiceClient overrides. |
53 | 56 |
54 void FakeShillServiceClient::Init(dbus::Bus* bus) { | 57 void FakeShillServiceClient::Init(dbus::Bus* bus) { |
| 58 // Note: FakeShillManagerClient sets up default services before this is |
| 59 // called. |
55 } | 60 } |
56 | 61 |
57 void FakeShillServiceClient::AddPropertyChangedObserver( | 62 void FakeShillServiceClient::AddPropertyChangedObserver( |
58 const dbus::ObjectPath& service_path, | 63 const dbus::ObjectPath& service_path, |
59 ShillPropertyChangedObserver* observer) { | 64 ShillPropertyChangedObserver* observer) { |
60 GetObserverList(service_path).AddObserver(observer); | 65 GetObserverList(service_path).AddObserver(observer); |
61 } | 66 } |
62 | 67 |
63 void FakeShillServiceClient::RemovePropertyChangedObserver( | 68 void FakeShillServiceClient::RemovePropertyChangedObserver( |
64 const dbus::ObjectPath& service_path, | 69 const dbus::ObjectPath& service_path, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // sending an update. | 185 // sending an update. |
181 SetOtherServicesOffline(service_path.value()); | 186 SetOtherServicesOffline(service_path.value()); |
182 | 187 |
183 // Set Associating. | 188 // Set Associating. |
184 base::StringValue associating_value(shill::kStateAssociation); | 189 base::StringValue associating_value(shill::kStateAssociation); |
185 SetServiceProperty(service_path.value(), | 190 SetServiceProperty(service_path.value(), |
186 shill::kStateProperty, | 191 shill::kStateProperty, |
187 associating_value); | 192 associating_value); |
188 | 193 |
189 // Stay Associating until the state is changed again after a delay. | 194 // Stay Associating until the state is changed again after a delay. |
190 base::TimeDelta delay; | |
191 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
192 chromeos::switches::kEnableStubInteractive)) { | |
193 const int kConnectDelaySeconds = 5; | |
194 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); | |
195 } | |
196 base::MessageLoop::current()->PostDelayedTask( | 195 base::MessageLoop::current()->PostDelayedTask( |
197 FROM_HERE, | 196 FROM_HERE, |
198 base::Bind(&FakeShillServiceClient::ContinueConnect, | 197 base::Bind(&FakeShillServiceClient::ContinueConnect, |
199 weak_ptr_factory_.GetWeakPtr(), | 198 weak_ptr_factory_.GetWeakPtr(), |
200 service_path.value()), | 199 service_path.value()), |
201 delay); | 200 base::TimeDelta::FromSeconds(GetInteractiveDelay())); |
202 | 201 |
203 callback.Run(); | 202 callback.Run(); |
204 } | 203 } |
205 | 204 |
206 void FakeShillServiceClient::Disconnect(const dbus::ObjectPath& service_path, | 205 void FakeShillServiceClient::Disconnect(const dbus::ObjectPath& service_path, |
207 const base::Closure& callback, | 206 const base::Closure& callback, |
208 const ErrorCallback& error_callback) { | 207 const ErrorCallback& error_callback) { |
209 base::Value* service; | 208 base::Value* service; |
210 if (!stub_services_.Get(service_path.value(), &service)) { | 209 if (!stub_services_.Get(service_path.value(), &service)) { |
211 error_callback.Run("Error.InvalidService", "Invalid Service"); | 210 error_callback.Run("Error.InvalidService", "Invalid Service"); |
212 return; | 211 return; |
213 } | 212 } |
214 base::TimeDelta delay; | |
215 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
216 chromeos::switches::kEnableStubInteractive)) { | |
217 const int kConnectDelaySeconds = 2; | |
218 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); | |
219 } | |
220 // Set Idle after a delay | 213 // Set Idle after a delay |
221 base::StringValue idle_value(shill::kStateIdle); | 214 base::StringValue idle_value(shill::kStateIdle); |
222 base::MessageLoop::current()->PostDelayedTask( | 215 base::MessageLoop::current()->PostDelayedTask( |
223 FROM_HERE, | 216 FROM_HERE, |
224 base::Bind(&FakeShillServiceClient::SetProperty, | 217 base::Bind(&FakeShillServiceClient::SetProperty, |
225 weak_ptr_factory_.GetWeakPtr(), | 218 weak_ptr_factory_.GetWeakPtr(), |
226 service_path, | 219 service_path, |
227 shill::kStateProperty, | 220 shill::kStateProperty, |
228 idle_value, | 221 idle_value, |
229 base::Bind(&base::DoNothing), | 222 base::Bind(&base::DoNothing), |
230 error_callback), | 223 error_callback), |
231 delay); | 224 base::TimeDelta::FromSeconds(GetInteractiveDelay())); |
232 callback.Run(); | 225 callback.Run(); |
233 } | 226 } |
234 | 227 |
235 void FakeShillServiceClient::Remove(const dbus::ObjectPath& service_path, | 228 void FakeShillServiceClient::Remove(const dbus::ObjectPath& service_path, |
236 const base::Closure& callback, | 229 const base::Closure& callback, |
237 const ErrorCallback& error_callback) { | 230 const ErrorCallback& error_callback) { |
238 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 231 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
239 } | 232 } |
240 | 233 |
241 void FakeShillServiceClient::ActivateCellularModem( | 234 void FakeShillServiceClient::ActivateCellularModem( |
242 const dbus::ObjectPath& service_path, | 235 const dbus::ObjectPath& service_path, |
243 const std::string& carrier, | 236 const std::string& carrier, |
244 const base::Closure& callback, | 237 const base::Closure& callback, |
245 const ErrorCallback& error_callback) { | 238 const ErrorCallback& error_callback) { |
246 base::DictionaryValue* service_properties = | 239 base::DictionaryValue* service_properties = |
247 GetModifiableServiceProperties(service_path.value(), false); | 240 GetModifiableServiceProperties(service_path.value(), false); |
248 if (!service_properties) { | 241 if (!service_properties) { |
249 LOG(ERROR) << "Service not found: " << service_path.value(); | 242 LOG(ERROR) << "Service not found: " << service_path.value(); |
250 error_callback.Run("Error.InvalidService", "Invalid Service"); | 243 error_callback.Run("Error.InvalidService", "Invalid Service"); |
251 } | 244 } |
252 SetServiceProperty(service_path.value(), | 245 SetServiceProperty(service_path.value(), |
253 shill::kActivationStateProperty, | 246 shill::kActivationStateProperty, |
254 base::StringValue(shill::kActivationStateActivating)); | 247 base::StringValue(shill::kActivationStateActivating)); |
255 base::TimeDelta delay; | |
256 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
257 chromeos::switches::kEnableStubInteractive)) { | |
258 const int kConnectDelaySeconds = 2; | |
259 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); | |
260 } | |
261 // Set Activated after a delay | 248 // Set Activated after a delay |
262 base::MessageLoop::current()->PostDelayedTask( | 249 base::MessageLoop::current()->PostDelayedTask( |
263 FROM_HERE, | 250 FROM_HERE, |
264 base::Bind(&FakeShillServiceClient::SetCellularActivated, | 251 base::Bind(&FakeShillServiceClient::SetCellularActivated, |
265 weak_ptr_factory_.GetWeakPtr(), | 252 weak_ptr_factory_.GetWeakPtr(), |
266 service_path, | 253 service_path, |
267 error_callback), | 254 error_callback), |
268 delay); | 255 base::TimeDelta::FromSeconds(GetInteractiveDelay())); |
269 | 256 |
270 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 257 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
271 } | 258 } |
272 | 259 |
273 void FakeShillServiceClient::CompleteCellularActivation( | 260 void FakeShillServiceClient::CompleteCellularActivation( |
274 const dbus::ObjectPath& service_path, | 261 const dbus::ObjectPath& service_path, |
275 const base::Closure& callback, | 262 const base::Closure& callback, |
276 const ErrorCallback& error_callback) { | 263 const ErrorCallback& error_callback) { |
277 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 264 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
278 } | 265 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 } | 298 } |
312 | 299 |
313 // ShillServiceClient::TestInterface overrides. | 300 // ShillServiceClient::TestInterface overrides. |
314 | 301 |
315 void FakeShillServiceClient::AddService(const std::string& service_path, | 302 void FakeShillServiceClient::AddService(const std::string& service_path, |
316 const std::string& name, | 303 const std::string& name, |
317 const std::string& type, | 304 const std::string& type, |
318 const std::string& state, | 305 const std::string& state, |
319 bool add_to_visible_list, | 306 bool add_to_visible_list, |
320 bool add_to_watch_list) { | 307 bool add_to_watch_list) { |
321 std::string nstate = state; | 308 AddServiceWithIPConfig(service_path, name, type, state, "", |
322 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
323 chromeos::switches::kDefaultStubNetworkStateIdle)) { | |
324 nstate = shill::kStateIdle; | |
325 } | |
326 AddServiceWithIPConfig(service_path, name, type, nstate, "", | |
327 add_to_visible_list, add_to_watch_list); | 309 add_to_visible_list, add_to_watch_list); |
328 } | 310 } |
329 | 311 |
330 void FakeShillServiceClient::AddServiceWithIPConfig( | 312 void FakeShillServiceClient::AddServiceWithIPConfig( |
331 const std::string& service_path, | 313 const std::string& service_path, |
332 const std::string& name, | 314 const std::string& name, |
333 const std::string& type, | 315 const std::string& type, |
334 const std::string& state, | 316 const std::string& state, |
335 const std::string& ipconfig_path, | 317 const std::string& ipconfig_path, |
336 bool add_to_visible_list, | 318 bool add_to_visible_list, |
337 bool add_to_watch_list) { | 319 bool add_to_watch_list) { |
338 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 320 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
339 AddManagerService(service_path, add_to_visible_list, add_to_watch_list); | 321 AddManagerService(service_path, add_to_visible_list, add_to_watch_list); |
| 322 ShillDeviceClient::TestInterface* device_client = |
| 323 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); |
340 | 324 |
341 base::DictionaryValue* properties = | 325 base::DictionaryValue* properties = |
342 GetModifiableServiceProperties(service_path, true); | 326 GetModifiableServiceProperties(service_path, true); |
343 connect_behavior_.erase(service_path); | 327 connect_behavior_.erase(service_path); |
344 shill_property_util::SetSSID(name, properties); | 328 shill_property_util::SetSSID(name, properties); |
345 properties->SetWithoutPathExpansion( | 329 properties->SetWithoutPathExpansion( |
346 shill::kNameProperty, | 330 shill::kNameProperty, |
347 base::Value::CreateStringValue(name)); | 331 base::Value::CreateStringValue(name)); |
348 properties->SetWithoutPathExpansion( | 332 properties->SetWithoutPathExpansion( |
349 shill::kDeviceProperty, | 333 shill::kDeviceProperty, |
350 base::Value::CreateStringValue( | 334 base::Value::CreateStringValue( |
351 shill_stub_helper::DevicePathForType(type))); | 335 device_client->GetDevicePathForType(type))); |
352 properties->SetWithoutPathExpansion( | 336 properties->SetWithoutPathExpansion( |
353 shill::kTypeProperty, | 337 shill::kTypeProperty, |
354 base::Value::CreateStringValue(type)); | 338 base::Value::CreateStringValue(type)); |
355 properties->SetWithoutPathExpansion( | 339 properties->SetWithoutPathExpansion( |
356 shill::kStateProperty, | 340 shill::kStateProperty, |
357 base::Value::CreateStringValue(state)); | 341 base::Value::CreateStringValue(state)); |
358 if (!ipconfig_path.empty()) | 342 if (!ipconfig_path.empty()) |
359 properties->SetWithoutPathExpansion( | 343 properties->SetWithoutPathExpansion( |
360 shill::kIPConfigProperty, | 344 shill::kIPConfigProperty, |
361 base::Value::CreateStringValue(ipconfig_path)); | 345 base::Value::CreateStringValue(ipconfig_path)); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 base::StringValue(shill::kErrorBadPassphrase))); | 539 base::StringValue(shill::kErrorBadPassphrase))); |
556 } else { | 540 } else { |
557 // Set Online. | 541 // Set Online. |
558 SetServiceProperty(service_path, | 542 SetServiceProperty(service_path, |
559 shill::kStateProperty, | 543 shill::kStateProperty, |
560 base::StringValue(shill::kStateOnline)); | 544 base::StringValue(shill::kStateOnline)); |
561 } | 545 } |
562 } | 546 } |
563 | 547 |
564 } // namespace chromeos | 548 } // namespace chromeos |
OLD | NEW |