| 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" |
| 16 #include "chromeos/dbus/shill_device_client.h" | 14 #include "chromeos/dbus/shill_device_client.h" |
| 17 #include "chromeos/dbus/shill_manager_client.h" | 15 #include "chromeos/dbus/shill_manager_client.h" |
| 18 #include "chromeos/dbus/shill_property_changed_observer.h" | 16 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 19 #include "chromeos/dbus/shill_stub_helper.h" | |
| 20 #include "chromeos/network/shill_property_util.h" | 17 #include "chromeos/network/shill_property_util.h" |
| 21 #include "dbus/bus.h" | 18 #include "dbus/bus.h" |
| 22 #include "dbus/message.h" | 19 #include "dbus/message.h" |
| 23 #include "dbus/object_path.h" | 20 #include "dbus/object_path.h" |
| 24 #include "third_party/cros_system_api/dbus/service_constants.h" | 21 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 25 | 22 |
| 26 namespace chromeos { | 23 namespace chromeos { |
| 27 | 24 |
| 28 namespace { | 25 namespace { |
| 29 | 26 |
| 30 void PassStubListValue(const ShillServiceClient::ListValueCallback& callback, | 27 void PassStubListValue(const ShillServiceClient::ListValueCallback& callback, |
| 31 base::ListValue* value) { | 28 base::ListValue* value) { |
| 32 callback.Run(*value); | 29 callback.Run(*value); |
| 33 } | 30 } |
| 34 | 31 |
| 35 void PassStubServiceProperties( | 32 void PassStubServiceProperties( |
| 36 const ShillServiceClient::DictionaryValueCallback& callback, | 33 const ShillServiceClient::DictionaryValueCallback& callback, |
| 37 DBusMethodCallStatus call_status, | 34 DBusMethodCallStatus call_status, |
| 38 const base::DictionaryValue* properties) { | 35 const base::DictionaryValue* properties) { |
| 39 callback.Run(call_status, *properties); | 36 callback.Run(call_status, *properties); |
| 40 } | 37 } |
| 41 | 38 |
| 42 void CallSortManagerServices() { | 39 void CallSortManagerServices() { |
| 43 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 40 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 44 SortManagerServices(); | 41 SortManagerServices(); |
| 45 } | 42 } |
| 46 | 43 |
| 44 int GetInteractiveDelay() { |
| 45 return DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 46 GetInteractiveDelay(); |
| 47 } |
| 48 |
| 47 } // namespace | 49 } // namespace |
| 48 | 50 |
| 49 FakeShillServiceClient::FakeShillServiceClient() : weak_ptr_factory_(this) { | 51 FakeShillServiceClient::FakeShillServiceClient() : weak_ptr_factory_(this) { |
| 50 } | 52 } |
| 51 | 53 |
| 52 FakeShillServiceClient::~FakeShillServiceClient() { | 54 FakeShillServiceClient::~FakeShillServiceClient() { |
| 53 STLDeleteContainerPairSecondPointers( | 55 STLDeleteContainerPairSecondPointers( |
| 54 observer_list_.begin(), observer_list_.end()); | 56 observer_list_.begin(), observer_list_.end()); |
| 55 } | 57 } |
| 56 | 58 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 // sending an update. | 188 // sending an update. |
| 187 SetOtherServicesOffline(service_path.value()); | 189 SetOtherServicesOffline(service_path.value()); |
| 188 | 190 |
| 189 // Set Associating. | 191 // Set Associating. |
| 190 base::StringValue associating_value(shill::kStateAssociation); | 192 base::StringValue associating_value(shill::kStateAssociation); |
| 191 SetServiceProperty(service_path.value(), | 193 SetServiceProperty(service_path.value(), |
| 192 shill::kStateProperty, | 194 shill::kStateProperty, |
| 193 associating_value); | 195 associating_value); |
| 194 | 196 |
| 195 // Stay Associating until the state is changed again after a delay. | 197 // Stay Associating until the state is changed again after a delay. |
| 196 base::TimeDelta delay; | |
| 197 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 198 chromeos::switches::kEnableStubInteractive)) { | |
| 199 const int kConnectDelaySeconds = 5; | |
| 200 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); | |
| 201 } | |
| 202 base::MessageLoop::current()->PostDelayedTask( | 198 base::MessageLoop::current()->PostDelayedTask( |
| 203 FROM_HERE, | 199 FROM_HERE, |
| 204 base::Bind(&FakeShillServiceClient::ContinueConnect, | 200 base::Bind(&FakeShillServiceClient::ContinueConnect, |
| 205 weak_ptr_factory_.GetWeakPtr(), | 201 weak_ptr_factory_.GetWeakPtr(), |
| 206 service_path.value()), | 202 service_path.value()), |
| 207 delay); | 203 base::TimeDelta::FromSeconds(GetInteractiveDelay())); |
| 208 | 204 |
| 209 callback.Run(); | 205 callback.Run(); |
| 210 } | 206 } |
| 211 | 207 |
| 212 void FakeShillServiceClient::Disconnect(const dbus::ObjectPath& service_path, | 208 void FakeShillServiceClient::Disconnect(const dbus::ObjectPath& service_path, |
| 213 const base::Closure& callback, | 209 const base::Closure& callback, |
| 214 const ErrorCallback& error_callback) { | 210 const ErrorCallback& error_callback) { |
| 215 base::Value* service; | 211 base::Value* service; |
| 216 if (!stub_services_.Get(service_path.value(), &service)) { | 212 if (!stub_services_.Get(service_path.value(), &service)) { |
| 217 error_callback.Run("Error.InvalidService", "Invalid Service"); | 213 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 218 return; | 214 return; |
| 219 } | 215 } |
| 220 base::TimeDelta delay; | |
| 221 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 222 chromeos::switches::kEnableStubInteractive)) { | |
| 223 const int kConnectDelaySeconds = 2; | |
| 224 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); | |
| 225 } | |
| 226 // Set Idle after a delay | 216 // Set Idle after a delay |
| 227 base::StringValue idle_value(shill::kStateIdle); | 217 base::StringValue idle_value(shill::kStateIdle); |
| 228 base::MessageLoop::current()->PostDelayedTask( | 218 base::MessageLoop::current()->PostDelayedTask( |
| 229 FROM_HERE, | 219 FROM_HERE, |
| 230 base::Bind(&FakeShillServiceClient::SetProperty, | 220 base::Bind(&FakeShillServiceClient::SetProperty, |
| 231 weak_ptr_factory_.GetWeakPtr(), | 221 weak_ptr_factory_.GetWeakPtr(), |
| 232 service_path, | 222 service_path, |
| 233 shill::kStateProperty, | 223 shill::kStateProperty, |
| 234 idle_value, | 224 idle_value, |
| 235 base::Bind(&base::DoNothing), | 225 base::Bind(&base::DoNothing), |
| 236 error_callback), | 226 error_callback), |
| 237 delay); | 227 base::TimeDelta::FromSeconds(GetInteractiveDelay())); |
| 238 callback.Run(); | 228 callback.Run(); |
| 239 } | 229 } |
| 240 | 230 |
| 241 void FakeShillServiceClient::Remove(const dbus::ObjectPath& service_path, | 231 void FakeShillServiceClient::Remove(const dbus::ObjectPath& service_path, |
| 242 const base::Closure& callback, | 232 const base::Closure& callback, |
| 243 const ErrorCallback& error_callback) { | 233 const ErrorCallback& error_callback) { |
| 244 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 234 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 245 } | 235 } |
| 246 | 236 |
| 247 void FakeShillServiceClient::ActivateCellularModem( | 237 void FakeShillServiceClient::ActivateCellularModem( |
| 248 const dbus::ObjectPath& service_path, | 238 const dbus::ObjectPath& service_path, |
| 249 const std::string& carrier, | 239 const std::string& carrier, |
| 250 const base::Closure& callback, | 240 const base::Closure& callback, |
| 251 const ErrorCallback& error_callback) { | 241 const ErrorCallback& error_callback) { |
| 252 base::DictionaryValue* service_properties = | 242 base::DictionaryValue* service_properties = |
| 253 GetModifiableServiceProperties(service_path.value(), false); | 243 GetModifiableServiceProperties(service_path.value(), false); |
| 254 if (!service_properties) { | 244 if (!service_properties) { |
| 255 LOG(ERROR) << "Service not found: " << service_path.value(); | 245 LOG(ERROR) << "Service not found: " << service_path.value(); |
| 256 error_callback.Run("Error.InvalidService", "Invalid Service"); | 246 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 257 } | 247 } |
| 258 SetServiceProperty(service_path.value(), | 248 SetServiceProperty(service_path.value(), |
| 259 shill::kActivationStateProperty, | 249 shill::kActivationStateProperty, |
| 260 base::StringValue(shill::kActivationStateActivating)); | 250 base::StringValue(shill::kActivationStateActivating)); |
| 261 base::TimeDelta delay; | |
| 262 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 263 chromeos::switches::kEnableStubInteractive)) { | |
| 264 const int kConnectDelaySeconds = 2; | |
| 265 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); | |
| 266 } | |
| 267 // Set Activated after a delay | 251 // Set Activated after a delay |
| 268 base::MessageLoop::current()->PostDelayedTask( | 252 base::MessageLoop::current()->PostDelayedTask( |
| 269 FROM_HERE, | 253 FROM_HERE, |
| 270 base::Bind(&FakeShillServiceClient::SetCellularActivated, | 254 base::Bind(&FakeShillServiceClient::SetCellularActivated, |
| 271 weak_ptr_factory_.GetWeakPtr(), | 255 weak_ptr_factory_.GetWeakPtr(), |
| 272 service_path, | 256 service_path, |
| 273 error_callback), | 257 error_callback), |
| 274 delay); | 258 base::TimeDelta::FromSeconds(GetInteractiveDelay())); |
| 275 | 259 |
| 276 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 260 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 277 } | 261 } |
| 278 | 262 |
| 279 void FakeShillServiceClient::CompleteCellularActivation( | 263 void FakeShillServiceClient::CompleteCellularActivation( |
| 280 const dbus::ObjectPath& service_path, | 264 const dbus::ObjectPath& service_path, |
| 281 const base::Closure& callback, | 265 const base::Closure& callback, |
| 282 const ErrorCallback& error_callback) { | 266 const ErrorCallback& error_callback) { |
| 283 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 267 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 284 } | 268 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 } | 301 } |
| 318 | 302 |
| 319 // ShillServiceClient::TestInterface overrides. | 303 // ShillServiceClient::TestInterface overrides. |
| 320 | 304 |
| 321 void FakeShillServiceClient::AddService(const std::string& service_path, | 305 void FakeShillServiceClient::AddService(const std::string& service_path, |
| 322 const std::string& name, | 306 const std::string& name, |
| 323 const std::string& type, | 307 const std::string& type, |
| 324 const std::string& state, | 308 const std::string& state, |
| 325 bool add_to_visible_list, | 309 bool add_to_visible_list, |
| 326 bool add_to_watch_list) { | 310 bool add_to_watch_list) { |
| 327 std::string nstate = state; | 311 AddServiceWithIPConfig(service_path, name, type, state, "", |
| 328 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 329 chromeos::switches::kDefaultStubNetworkStateIdle)) { | |
| 330 nstate = shill::kStateIdle; | |
| 331 } | |
| 332 AddServiceWithIPConfig(service_path, name, type, nstate, "", | |
| 333 add_to_visible_list, add_to_watch_list); | 312 add_to_visible_list, add_to_watch_list); |
| 334 } | 313 } |
| 335 | 314 |
| 336 void FakeShillServiceClient::AddServiceWithIPConfig( | 315 void FakeShillServiceClient::AddServiceWithIPConfig( |
| 337 const std::string& service_path, | 316 const std::string& service_path, |
| 338 const std::string& name, | 317 const std::string& name, |
| 339 const std::string& type, | 318 const std::string& type, |
| 340 const std::string& state, | 319 const std::string& state, |
| 341 const std::string& ipconfig_path, | 320 const std::string& ipconfig_path, |
| 342 bool add_to_visible_list, | 321 bool add_to_visible_list, |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 base::StringValue(shill::kErrorBadPassphrase))); | 556 base::StringValue(shill::kErrorBadPassphrase))); |
| 578 } else { | 557 } else { |
| 579 // Set Online. | 558 // Set Online. |
| 580 SetServiceProperty(service_path, | 559 SetServiceProperty(service_path, |
| 581 shill::kStateProperty, | 560 shill::kStateProperty, |
| 582 base::StringValue(shill::kStateOnline)); | 561 base::StringValue(shill::kStateOnline)); |
| 583 } | 562 } |
| 584 } | 563 } |
| 585 | 564 |
| 586 } // namespace chromeos | 565 } // namespace chromeos |
| OLD | NEW |