| 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 |
| 39 int GetInteractiveDelay() { |
| 40 return DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 41 GetInteractiveDelay(); |
| 42 } |
| 43 |
| 42 } // namespace | 44 } // namespace |
| 43 | 45 |
| 44 FakeShillServiceClient::FakeShillServiceClient() : weak_ptr_factory_(this) { | 46 FakeShillServiceClient::FakeShillServiceClient() : weak_ptr_factory_(this) { |
| 45 } | 47 } |
| 46 | 48 |
| 47 FakeShillServiceClient::~FakeShillServiceClient() { | 49 FakeShillServiceClient::~FakeShillServiceClient() { |
| 48 STLDeleteContainerPairSecondPointers( | 50 STLDeleteContainerPairSecondPointers( |
| 49 observer_list_.begin(), observer_list_.end()); | 51 observer_list_.begin(), observer_list_.end()); |
| 50 } | 52 } |
| 51 | 53 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // sending an update. | 183 // sending an update. |
| 182 SetOtherServicesOffline(service_path.value()); | 184 SetOtherServicesOffline(service_path.value()); |
| 183 | 185 |
| 184 // Set Associating. | 186 // Set Associating. |
| 185 base::StringValue associating_value(shill::kStateAssociation); | 187 base::StringValue associating_value(shill::kStateAssociation); |
| 186 SetServiceProperty(service_path.value(), | 188 SetServiceProperty(service_path.value(), |
| 187 shill::kStateProperty, | 189 shill::kStateProperty, |
| 188 associating_value); | 190 associating_value); |
| 189 | 191 |
| 190 // Stay Associating until the state is changed again after a delay. | 192 // Stay Associating until the state is changed again after a delay. |
| 191 base::TimeDelta delay; | |
| 192 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 193 chromeos::switches::kEnableStubInteractive)) { | |
| 194 const int kConnectDelaySeconds = 5; | |
| 195 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); | |
| 196 } | |
| 197 base::MessageLoop::current()->PostDelayedTask( | 193 base::MessageLoop::current()->PostDelayedTask( |
| 198 FROM_HERE, | 194 FROM_HERE, |
| 199 base::Bind(&FakeShillServiceClient::ContinueConnect, | 195 base::Bind(&FakeShillServiceClient::ContinueConnect, |
| 200 weak_ptr_factory_.GetWeakPtr(), | 196 weak_ptr_factory_.GetWeakPtr(), |
| 201 service_path.value()), | 197 service_path.value()), |
| 202 delay); | 198 base::TimeDelta::FromSeconds(GetInteractiveDelay())); |
| 203 | 199 |
| 204 callback.Run(); | 200 callback.Run(); |
| 205 } | 201 } |
| 206 | 202 |
| 207 void FakeShillServiceClient::Disconnect(const dbus::ObjectPath& service_path, | 203 void FakeShillServiceClient::Disconnect(const dbus::ObjectPath& service_path, |
| 208 const base::Closure& callback, | 204 const base::Closure& callback, |
| 209 const ErrorCallback& error_callback) { | 205 const ErrorCallback& error_callback) { |
| 210 base::Value* service; | 206 base::Value* service; |
| 211 if (!stub_services_.Get(service_path.value(), &service)) { | 207 if (!stub_services_.Get(service_path.value(), &service)) { |
| 212 error_callback.Run("Error.InvalidService", "Invalid Service"); | 208 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 213 return; | 209 return; |
| 214 } | 210 } |
| 215 base::TimeDelta delay; | |
| 216 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 217 chromeos::switches::kEnableStubInteractive)) { | |
| 218 const int kConnectDelaySeconds = 2; | |
| 219 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); | |
| 220 } | |
| 221 // Set Idle after a delay | 211 // Set Idle after a delay |
| 222 base::StringValue idle_value(shill::kStateIdle); | 212 base::StringValue idle_value(shill::kStateIdle); |
| 223 base::MessageLoop::current()->PostDelayedTask( | 213 base::MessageLoop::current()->PostDelayedTask( |
| 224 FROM_HERE, | 214 FROM_HERE, |
| 225 base::Bind(&FakeShillServiceClient::SetProperty, | 215 base::Bind(&FakeShillServiceClient::SetProperty, |
| 226 weak_ptr_factory_.GetWeakPtr(), | 216 weak_ptr_factory_.GetWeakPtr(), |
| 227 service_path, | 217 service_path, |
| 228 shill::kStateProperty, | 218 shill::kStateProperty, |
| 229 idle_value, | 219 idle_value, |
| 230 base::Bind(&base::DoNothing), | 220 base::Bind(&base::DoNothing), |
| 231 error_callback), | 221 error_callback), |
| 232 delay); | 222 base::TimeDelta::FromSeconds(GetInteractiveDelay())); |
| 233 callback.Run(); | 223 callback.Run(); |
| 234 } | 224 } |
| 235 | 225 |
| 236 void FakeShillServiceClient::Remove(const dbus::ObjectPath& service_path, | 226 void FakeShillServiceClient::Remove(const dbus::ObjectPath& service_path, |
| 237 const base::Closure& callback, | 227 const base::Closure& callback, |
| 238 const ErrorCallback& error_callback) { | 228 const ErrorCallback& error_callback) { |
| 239 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 229 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 240 } | 230 } |
| 241 | 231 |
| 242 void FakeShillServiceClient::ActivateCellularModem( | 232 void FakeShillServiceClient::ActivateCellularModem( |
| 243 const dbus::ObjectPath& service_path, | 233 const dbus::ObjectPath& service_path, |
| 244 const std::string& carrier, | 234 const std::string& carrier, |
| 245 const base::Closure& callback, | 235 const base::Closure& callback, |
| 246 const ErrorCallback& error_callback) { | 236 const ErrorCallback& error_callback) { |
| 247 base::DictionaryValue* service_properties = | 237 base::DictionaryValue* service_properties = |
| 248 GetModifiableServiceProperties(service_path.value(), false); | 238 GetModifiableServiceProperties(service_path.value(), false); |
| 249 if (!service_properties) { | 239 if (!service_properties) { |
| 250 LOG(ERROR) << "Service not found: " << service_path.value(); | 240 LOG(ERROR) << "Service not found: " << service_path.value(); |
| 251 error_callback.Run("Error.InvalidService", "Invalid Service"); | 241 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 252 } | 242 } |
| 253 SetServiceProperty(service_path.value(), | 243 SetServiceProperty(service_path.value(), |
| 254 shill::kActivationStateProperty, | 244 shill::kActivationStateProperty, |
| 255 base::StringValue(shill::kActivationStateActivating)); | 245 base::StringValue(shill::kActivationStateActivating)); |
| 256 base::TimeDelta delay; | |
| 257 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 258 chromeos::switches::kEnableStubInteractive)) { | |
| 259 const int kConnectDelaySeconds = 2; | |
| 260 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); | |
| 261 } | |
| 262 // Set Activated after a delay | 246 // Set Activated after a delay |
| 263 base::MessageLoop::current()->PostDelayedTask( | 247 base::MessageLoop::current()->PostDelayedTask( |
| 264 FROM_HERE, | 248 FROM_HERE, |
| 265 base::Bind(&FakeShillServiceClient::SetCellularActivated, | 249 base::Bind(&FakeShillServiceClient::SetCellularActivated, |
| 266 weak_ptr_factory_.GetWeakPtr(), | 250 weak_ptr_factory_.GetWeakPtr(), |
| 267 service_path, | 251 service_path, |
| 268 error_callback), | 252 error_callback), |
| 269 delay); | 253 base::TimeDelta::FromSeconds(GetInteractiveDelay())); |
| 270 | 254 |
| 271 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 255 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 272 } | 256 } |
| 273 | 257 |
| 274 void FakeShillServiceClient::CompleteCellularActivation( | 258 void FakeShillServiceClient::CompleteCellularActivation( |
| 275 const dbus::ObjectPath& service_path, | 259 const dbus::ObjectPath& service_path, |
| 276 const base::Closure& callback, | 260 const base::Closure& callback, |
| 277 const ErrorCallback& error_callback) { | 261 const ErrorCallback& error_callback) { |
| 278 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 262 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 279 } | 263 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 } | 296 } |
| 313 | 297 |
| 314 // ShillServiceClient::TestInterface overrides. | 298 // ShillServiceClient::TestInterface overrides. |
| 315 | 299 |
| 316 void FakeShillServiceClient::AddService(const std::string& service_path, | 300 void FakeShillServiceClient::AddService(const std::string& service_path, |
| 317 const std::string& name, | 301 const std::string& name, |
| 318 const std::string& type, | 302 const std::string& type, |
| 319 const std::string& state, | 303 const std::string& state, |
| 320 bool add_to_visible_list, | 304 bool add_to_visible_list, |
| 321 bool add_to_watch_list) { | 305 bool add_to_watch_list) { |
| 322 std::string nstate = state; | 306 AddServiceWithIPConfig(service_path, name, type, state, "", |
| 323 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 324 chromeos::switches::kDefaultStubNetworkStateIdle)) { | |
| 325 nstate = shill::kStateIdle; | |
| 326 } | |
| 327 AddServiceWithIPConfig(service_path, name, type, nstate, "", | |
| 328 add_to_visible_list, add_to_watch_list); | 307 add_to_visible_list, add_to_watch_list); |
| 329 } | 308 } |
| 330 | 309 |
| 331 void FakeShillServiceClient::AddServiceWithIPConfig( | 310 void FakeShillServiceClient::AddServiceWithIPConfig( |
| 332 const std::string& service_path, | 311 const std::string& service_path, |
| 333 const std::string& name, | 312 const std::string& name, |
| 334 const std::string& type, | 313 const std::string& type, |
| 335 const std::string& state, | 314 const std::string& state, |
| 336 const std::string& ipconfig_path, | 315 const std::string& ipconfig_path, |
| 337 bool add_to_visible_list, | 316 bool add_to_visible_list, |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 base::StringValue(shill::kErrorBadPassphrase))); | 537 base::StringValue(shill::kErrorBadPassphrase))); |
| 559 } else { | 538 } else { |
| 560 // Set Online. | 539 // Set Online. |
| 561 SetServiceProperty(service_path, | 540 SetServiceProperty(service_path, |
| 562 shill::kStateProperty, | 541 shill::kStateProperty, |
| 563 base::StringValue(shill::kStateOnline)); | 542 base::StringValue(shill::kStateOnline)); |
| 564 } | 543 } |
| 565 } | 544 } |
| 566 | 545 |
| 567 } // namespace chromeos | 546 } // namespace chromeos |
| OLD | NEW |