Chromium Code Reviews| 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_manager_client.h" | 5 #include "chromeos/dbus/fake_shill_manager_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | |
| 9 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/string_number_conversions.h" | |
| 10 #include "base/strings/string_util.h" | |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "chromeos/chromeos_switches.h" | 12 #include "chromeos/chromeos_switches.h" |
| 13 #include "chromeos/dbus/dbus_command_line_helper.h" | |
| 12 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
| 13 #include "chromeos/dbus/shill_device_client.h" | 15 #include "chromeos/dbus/shill_device_client.h" |
| 14 #include "chromeos/dbus/shill_profile_client.h" | 16 #include "chromeos/dbus/shill_profile_client.h" |
| 15 #include "chromeos/dbus/shill_property_changed_observer.h" | 17 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 16 #include "chromeos/dbus/shill_service_client.h" | 18 #include "chromeos/dbus/shill_service_client.h" |
| 17 #include "dbus/bus.h" | 19 #include "dbus/bus.h" |
| 18 #include "dbus/message.h" | 20 #include "dbus/message.h" |
| 19 #include "dbus/object_path.h" | 21 #include "dbus/object_path.h" |
| 20 #include "dbus/values_util.h" | 22 #include "dbus/values_util.h" |
| 21 #include "third_party/cros_system_api/dbus/service_constants.h" | 23 #include "third_party/cros_system_api/dbus/service_constants.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 state == shill::kStateConfiguration || | 68 state == shill::kStateConfiguration || |
| 67 state == shill::kStatePortal || | 69 state == shill::kStatePortal || |
| 68 state == shill::kStateReady) { | 70 state == shill::kStateReady) { |
| 69 active_service_list_out->push_back(service_path); | 71 active_service_list_out->push_back(service_path); |
| 70 } else { | 72 } else { |
| 71 inactive_service_list_out->push_back(service_path); | 73 inactive_service_list_out->push_back(service_path); |
| 72 } | 74 } |
| 73 } | 75 } |
| 74 } | 76 } |
| 75 | 77 |
| 78 void UpdatePortalledWifiState(const std::string& service_path) { | |
| 79 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface() | |
| 80 ->SetServiceProperty(service_path, | |
| 81 shill::kStateProperty, | |
| 82 base::StringValue(shill::kStatePortal)); | |
| 83 } | |
| 84 | |
| 76 } // namespace | 85 } // namespace |
| 77 | 86 |
| 78 FakeShillManagerClient::FakeShillManagerClient() | 87 FakeShillManagerClient::FakeShillManagerClient() |
| 79 : weak_ptr_factory_(this) { | 88 : interactive_delay_(0), |
| 89 weak_ptr_factory_(this) { | |
| 90 ParseCommandLineSwitch(); | |
| 80 } | 91 } |
| 81 | 92 |
| 82 FakeShillManagerClient::~FakeShillManagerClient() {} | 93 FakeShillManagerClient::~FakeShillManagerClient() {} |
| 83 | 94 |
| 84 // ShillManagerClient overrides. | 95 // ShillManagerClient overrides. |
| 85 | 96 |
| 86 void FakeShillManagerClient::Init(dbus::Bus* bus) {} | 97 void FakeShillManagerClient::Init(dbus::Bus* bus) {} |
| 87 | 98 |
| 88 void FakeShillManagerClient::AddPropertyChangedObserver( | 99 void FakeShillManagerClient::AddPropertyChangedObserver( |
| 89 ShillPropertyChangedObserver* observer) { | 100 ShillPropertyChangedObserver* observer) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 111 &FakeShillManagerClient::PassStubGeoNetworks, | 122 &FakeShillManagerClient::PassStubGeoNetworks, |
| 112 weak_ptr_factory_.GetWeakPtr(), | 123 weak_ptr_factory_.GetWeakPtr(), |
| 113 callback)); | 124 callback)); |
| 114 } | 125 } |
| 115 | 126 |
| 116 void FakeShillManagerClient::SetProperty(const std::string& name, | 127 void FakeShillManagerClient::SetProperty(const std::string& name, |
| 117 const base::Value& value, | 128 const base::Value& value, |
| 118 const base::Closure& callback, | 129 const base::Closure& callback, |
| 119 const ErrorCallback& error_callback) { | 130 const ErrorCallback& error_callback) { |
| 120 stub_properties_.SetWithoutPathExpansion(name, value.DeepCopy()); | 131 stub_properties_.SetWithoutPathExpansion(name, value.DeepCopy()); |
| 121 CallNotifyObserversPropertyChanged(name, 0); | 132 CallNotifyObserversPropertyChanged(name); |
| 122 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 133 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 123 } | 134 } |
| 124 | 135 |
| 125 void FakeShillManagerClient::RequestScan(const std::string& type, | 136 void FakeShillManagerClient::RequestScan(const std::string& type, |
| 126 const base::Closure& callback, | 137 const base::Closure& callback, |
| 127 const ErrorCallback& error_callback) { | 138 const ErrorCallback& error_callback) { |
| 128 // For Stub purposes, default to a Wifi scan. | 139 // For Stub purposes, default to a Wifi scan. |
| 129 std::string device_type = shill::kTypeWifi; | 140 std::string device_type = shill::kTypeWifi; |
| 130 if (!type.empty()) | 141 if (!type.empty()) |
| 131 device_type = type; | 142 device_type = type; |
| 132 ShillDeviceClient::TestInterface* device_client = | 143 ShillDeviceClient::TestInterface* device_client = |
| 133 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); | 144 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); |
| 134 std::string device_path = device_client->GetDevicePathForType(device_type); | 145 std::string device_path = device_client->GetDevicePathForType(device_type); |
| 135 if (!device_path.empty()) { | 146 if (!device_path.empty()) { |
| 136 device_client->SetDeviceProperty(device_path, | 147 device_client->SetDeviceProperty( |
| 137 shill::kScanningProperty, | 148 device_path, shill::kScanningProperty, base::FundamentalValue(true)); |
| 138 base::FundamentalValue(true)); | |
| 139 } | |
| 140 const int kScanDurationSeconds = 3; | |
| 141 int scan_duration_seconds = kScanDurationSeconds; | |
| 142 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 143 chromeos::switches::kEnableStubInteractive)) { | |
| 144 scan_duration_seconds = 0; | |
| 145 } | 149 } |
| 146 base::MessageLoop::current()->PostDelayedTask( | 150 base::MessageLoop::current()->PostDelayedTask( |
| 147 FROM_HERE, | 151 FROM_HERE, |
| 148 base::Bind(&FakeShillManagerClient::ScanCompleted, | 152 base::Bind(&FakeShillManagerClient::ScanCompleted, |
| 149 weak_ptr_factory_.GetWeakPtr(), device_path, callback), | 153 weak_ptr_factory_.GetWeakPtr(), |
| 150 base::TimeDelta::FromSeconds(scan_duration_seconds)); | 154 device_path, |
| 155 callback), | |
| 156 base::TimeDelta::FromSeconds(interactive_delay_)); | |
| 151 } | 157 } |
| 152 | 158 |
| 153 void FakeShillManagerClient::EnableTechnology( | 159 void FakeShillManagerClient::EnableTechnology( |
| 154 const std::string& type, | 160 const std::string& type, |
| 155 const base::Closure& callback, | 161 const base::Closure& callback, |
| 156 const ErrorCallback& error_callback) { | 162 const ErrorCallback& error_callback) { |
| 157 base::ListValue* enabled_list = NULL; | 163 base::ListValue* enabled_list = NULL; |
| 158 if (!stub_properties_.GetListWithoutPathExpansion( | 164 if (!stub_properties_.GetListWithoutPathExpansion( |
| 159 shill::kEnabledTechnologiesProperty, &enabled_list)) { | 165 shill::kAvailableTechnologiesProperty, &enabled_list)) { |
| 160 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 166 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 161 base::MessageLoop::current()->PostTask( | 167 base::MessageLoop::current()->PostTask( |
| 162 FROM_HERE, | 168 FROM_HERE, |
| 163 base::Bind(error_callback, "StubError", "Property not found")); | 169 base::Bind(error_callback, "StubError", "Property not found")); |
| 164 return; | 170 return; |
| 165 } | 171 } |
| 166 if (CommandLine::ForCurrentProcess()->HasSwitch( | 172 if (interactive_delay_) { |
|
pneubeck (no reviews)
2014/03/03 20:36:19
actually, why not PostDelayedTask(..., 0) and ther
stevenjb
2014/03/05 01:03:50
Good point, and I think that's pretty low risk; if
| |
| 167 chromeos::switches::kEnableStubInteractive)) { | |
| 168 const int kEnableTechnologyDelaySeconds = 3; | |
| 169 base::MessageLoop::current()->PostDelayedTask( | 173 base::MessageLoop::current()->PostDelayedTask( |
| 170 FROM_HERE, | 174 FROM_HERE, |
| 171 base::Bind(&FakeShillManagerClient::SetTechnologyEnabled, | 175 base::Bind(&FakeShillManagerClient::SetTechnologyEnabled, |
| 172 weak_ptr_factory_.GetWeakPtr(), type, callback, true), | 176 weak_ptr_factory_.GetWeakPtr(), |
| 173 base::TimeDelta::FromSeconds(kEnableTechnologyDelaySeconds)); | 177 type, |
| 178 callback, | |
| 179 true), | |
| 180 base::TimeDelta::FromSeconds(interactive_delay_)); | |
| 174 } else { | 181 } else { |
| 175 SetTechnologyEnabled(type, callback, true); | 182 SetTechnologyEnabled(type, callback, true); |
| 176 } | 183 } |
| 177 } | 184 } |
| 178 | 185 |
| 179 void FakeShillManagerClient::DisableTechnology( | 186 void FakeShillManagerClient::DisableTechnology( |
| 180 const std::string& type, | 187 const std::string& type, |
| 181 const base::Closure& callback, | 188 const base::Closure& callback, |
| 182 const ErrorCallback& error_callback) { | 189 const ErrorCallback& error_callback) { |
| 183 base::ListValue* enabled_list = NULL; | 190 base::ListValue* enabled_list = NULL; |
| 184 if (!stub_properties_.GetListWithoutPathExpansion( | 191 if (!stub_properties_.GetListWithoutPathExpansion( |
| 185 shill::kEnabledTechnologiesProperty, &enabled_list)) { | 192 shill::kAvailableTechnologiesProperty, &enabled_list)) { |
| 186 base::MessageLoop::current()->PostTask( | 193 base::MessageLoop::current()->PostTask( |
| 187 FROM_HERE, | 194 FROM_HERE, |
| 188 base::Bind(error_callback, "StubError", "Property not found")); | 195 base::Bind(error_callback, "StubError", "Property not found")); |
| 189 return; | 196 return; |
| 190 } | 197 } |
| 191 if (CommandLine::ForCurrentProcess()->HasSwitch( | 198 if (interactive_delay_) { |
| 192 chromeos::switches::kEnableStubInteractive)) { | |
| 193 const int kDisableTechnologyDelaySeconds = 3; | |
| 194 base::MessageLoop::current()->PostDelayedTask( | 199 base::MessageLoop::current()->PostDelayedTask( |
| 195 FROM_HERE, | 200 FROM_HERE, |
| 196 base::Bind(&FakeShillManagerClient::SetTechnologyEnabled, | 201 base::Bind(&FakeShillManagerClient::SetTechnologyEnabled, |
| 197 weak_ptr_factory_.GetWeakPtr(), type, callback, false), | 202 weak_ptr_factory_.GetWeakPtr(), |
| 198 base::TimeDelta::FromSeconds(kDisableTechnologyDelaySeconds)); | 203 type, |
| 204 callback, | |
| 205 false), | |
| 206 base::TimeDelta::FromSeconds(interactive_delay_)); | |
| 199 } else { | 207 } else { |
| 200 SetTechnologyEnabled(type, callback, false); | 208 SetTechnologyEnabled(type, callback, false); |
| 201 } | 209 } |
| 202 } | 210 } |
| 203 | 211 |
| 204 void FakeShillManagerClient::ConfigureService( | 212 void FakeShillManagerClient::ConfigureService( |
| 205 const base::DictionaryValue& properties, | 213 const base::DictionaryValue& properties, |
| 206 const ObjectPathCallback& callback, | 214 const ObjectPathCallback& callback, |
| 207 const ErrorCallback& error_callback) { | 215 const ErrorCallback& error_callback) { |
| 208 ShillServiceClient::TestInterface* service_client = | 216 ShillServiceClient::TestInterface* service_client = |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 const ErrorCallback& error_callback) { | 307 const ErrorCallback& error_callback) { |
| 300 base::MessageLoop::current()->PostTask( | 308 base::MessageLoop::current()->PostTask( |
| 301 FROM_HERE, base::Bind(callback, "encrypted_credentials")); | 309 FROM_HERE, base::Bind(callback, "encrypted_credentials")); |
| 302 } | 310 } |
| 303 | 311 |
| 304 void FakeShillManagerClient::VerifyAndEncryptData( | 312 void FakeShillManagerClient::VerifyAndEncryptData( |
| 305 const VerificationProperties& properties, | 313 const VerificationProperties& properties, |
| 306 const std::string& data, | 314 const std::string& data, |
| 307 const StringCallback& callback, | 315 const StringCallback& callback, |
| 308 const ErrorCallback& error_callback) { | 316 const ErrorCallback& error_callback) { |
| 309 base::MessageLoop::current()->PostTask(FROM_HERE, | 317 base::MessageLoop::current()->PostTask( |
| 310 base::Bind(callback, "encrypted_data")); | 318 FROM_HERE, base::Bind(callback, "encrypted_data")); |
| 311 } | 319 } |
| 312 | 320 |
| 313 void FakeShillManagerClient::ConnectToBestServices( | 321 void FakeShillManagerClient::ConnectToBestServices( |
| 314 const base::Closure& callback, | 322 const base::Closure& callback, |
| 315 const ErrorCallback& error_callback) { | 323 const ErrorCallback& error_callback) { |
| 316 } | 324 } |
| 317 | 325 |
| 318 ShillManagerClient::TestInterface* FakeShillManagerClient::GetTestInterface() { | 326 ShillManagerClient::TestInterface* FakeShillManagerClient::GetTestInterface() { |
| 319 return this; | 327 return this; |
| 320 } | 328 } |
| 321 | 329 |
| 322 // ShillManagerClient::TestInterface overrides. | 330 // ShillManagerClient::TestInterface overrides. |
| 323 | 331 |
| 324 void FakeShillManagerClient::AddDevice(const std::string& device_path) { | 332 void FakeShillManagerClient::AddDevice(const std::string& device_path) { |
| 325 if (GetListProperty(shill::kDevicesProperty)->AppendIfNotPresent( | 333 if (GetListProperty(shill::kDevicesProperty) |
| 326 base::Value::CreateStringValue(device_path))) { | 334 ->AppendIfNotPresent(base::Value::CreateStringValue(device_path))) { |
| 327 CallNotifyObserversPropertyChanged(shill::kDevicesProperty, 0); | 335 CallNotifyObserversPropertyChanged(shill::kDevicesProperty); |
| 328 } | 336 } |
| 329 } | 337 } |
| 330 | 338 |
| 331 void FakeShillManagerClient::RemoveDevice(const std::string& device_path) { | 339 void FakeShillManagerClient::RemoveDevice(const std::string& device_path) { |
| 332 base::StringValue device_path_value(device_path); | 340 base::StringValue device_path_value(device_path); |
| 333 if (GetListProperty(shill::kDevicesProperty)->Remove( | 341 if (GetListProperty(shill::kDevicesProperty) |
| 334 device_path_value, NULL)) { | 342 ->Remove(device_path_value, NULL)) { |
| 335 CallNotifyObserversPropertyChanged(shill::kDevicesProperty, 0); | 343 CallNotifyObserversPropertyChanged(shill::kDevicesProperty); |
| 336 } | 344 } |
| 337 } | 345 } |
| 338 | 346 |
| 339 void FakeShillManagerClient::ClearDevices() { | 347 void FakeShillManagerClient::ClearDevices() { |
| 340 GetListProperty(shill::kDevicesProperty)->Clear(); | 348 GetListProperty(shill::kDevicesProperty)->Clear(); |
| 341 CallNotifyObserversPropertyChanged(shill::kDevicesProperty, 0); | 349 CallNotifyObserversPropertyChanged(shill::kDevicesProperty); |
| 342 } | 350 } |
| 343 | 351 |
| 344 void FakeShillManagerClient::AddTechnology(const std::string& type, | 352 void FakeShillManagerClient::AddTechnology(const std::string& type, |
| 345 bool enabled) { | 353 bool enabled) { |
| 346 if (GetListProperty(shill::kAvailableTechnologiesProperty)-> | 354 if (GetListProperty(shill::kAvailableTechnologiesProperty) |
| 347 AppendIfNotPresent(base::Value::CreateStringValue(type))) { | 355 ->AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| 348 CallNotifyObserversPropertyChanged( | 356 CallNotifyObserversPropertyChanged(shill::kAvailableTechnologiesProperty); |
| 349 shill::kAvailableTechnologiesProperty, 0); | |
| 350 } | 357 } |
| 351 if (enabled && | 358 if (enabled && |
| 352 GetListProperty(shill::kEnabledTechnologiesProperty)-> | 359 GetListProperty(shill::kEnabledTechnologiesProperty) |
| 353 AppendIfNotPresent(base::Value::CreateStringValue(type))) { | 360 ->AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| 354 CallNotifyObserversPropertyChanged( | 361 CallNotifyObserversPropertyChanged(shill::kEnabledTechnologiesProperty); |
| 355 shill::kEnabledTechnologiesProperty, 0); | |
| 356 } | 362 } |
| 357 } | 363 } |
| 358 | 364 |
| 359 void FakeShillManagerClient::RemoveTechnology(const std::string& type) { | 365 void FakeShillManagerClient::RemoveTechnology(const std::string& type) { |
| 360 base::StringValue type_value(type); | 366 base::StringValue type_value(type); |
| 361 if (GetListProperty(shill::kAvailableTechnologiesProperty)->Remove( | 367 if (GetListProperty(shill::kAvailableTechnologiesProperty) |
| 362 type_value, NULL)) { | 368 ->Remove(type_value, NULL)) { |
| 363 CallNotifyObserversPropertyChanged( | 369 CallNotifyObserversPropertyChanged(shill::kAvailableTechnologiesProperty); |
| 364 shill::kAvailableTechnologiesProperty, 0); | |
| 365 } | 370 } |
| 366 if (GetListProperty(shill::kEnabledTechnologiesProperty)->Remove( | 371 if (GetListProperty(shill::kEnabledTechnologiesProperty) |
| 367 type_value, NULL)) { | 372 ->Remove(type_value, NULL)) { |
| 368 CallNotifyObserversPropertyChanged( | 373 CallNotifyObserversPropertyChanged(shill::kEnabledTechnologiesProperty); |
| 369 shill::kEnabledTechnologiesProperty, 0); | |
| 370 } | 374 } |
| 371 } | 375 } |
| 372 | 376 |
| 373 void FakeShillManagerClient::SetTechnologyInitializing(const std::string& type, | 377 void FakeShillManagerClient::SetTechnologyInitializing(const std::string& type, |
| 374 bool initializing) { | 378 bool initializing) { |
| 375 if (initializing) { | 379 if (initializing) { |
| 376 if (GetListProperty(shill::kUninitializedTechnologiesProperty)-> | 380 if (GetListProperty(shill::kUninitializedTechnologiesProperty) |
| 377 AppendIfNotPresent(base::Value::CreateStringValue(type))) { | 381 ->AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| 378 CallNotifyObserversPropertyChanged( | 382 CallNotifyObserversPropertyChanged( |
| 379 shill::kUninitializedTechnologiesProperty, 0); | 383 shill::kUninitializedTechnologiesProperty); |
| 380 } | 384 } |
| 381 } else { | 385 } else { |
| 382 if (GetListProperty(shill::kUninitializedTechnologiesProperty)->Remove( | 386 if (GetListProperty(shill::kUninitializedTechnologiesProperty) |
| 383 base::StringValue(type), NULL)) { | 387 ->Remove(base::StringValue(type), NULL)) { |
| 384 CallNotifyObserversPropertyChanged( | 388 CallNotifyObserversPropertyChanged( |
| 385 shill::kUninitializedTechnologiesProperty, 0); | 389 shill::kUninitializedTechnologiesProperty); |
| 386 } | 390 } |
| 387 } | 391 } |
| 388 } | 392 } |
| 389 | 393 |
| 394 void FakeShillManagerClient::AddGeoNetwork( | |
| 395 const std::string& technology, | |
| 396 const base::DictionaryValue& network) { | |
| 397 base::ListValue* list_value = NULL; | |
| 398 if (!stub_geo_networks_.GetListWithoutPathExpansion(technology, | |
| 399 &list_value)) { | |
| 400 list_value = new base::ListValue; | |
| 401 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); | |
| 402 } | |
| 403 list_value->Append(network.DeepCopy()); | |
| 404 } | |
| 405 | |
| 406 void FakeShillManagerClient::AddProfile(const std::string& profile_path) { | |
| 407 const char* key = shill::kProfilesProperty; | |
| 408 if (GetListProperty(key) | |
| 409 ->AppendIfNotPresent(new base::StringValue(profile_path))) { | |
| 410 CallNotifyObserversPropertyChanged(key); | |
| 411 } | |
| 412 } | |
| 413 | |
| 390 void FakeShillManagerClient::ClearProperties() { | 414 void FakeShillManagerClient::ClearProperties() { |
| 391 stub_properties_.Clear(); | 415 stub_properties_.Clear(); |
| 392 } | 416 } |
| 393 | 417 |
| 394 void FakeShillManagerClient::AddManagerService(const std::string& service_path, | 418 void FakeShillManagerClient::AddManagerService(const std::string& service_path, |
| 395 bool add_to_visible_list, | 419 bool add_to_visible_list, |
| 396 bool add_to_watch_list) { | 420 bool add_to_watch_list) { |
| 397 // Always add to ServiceCompleteListProperty. | 421 // Always add to ServiceCompleteListProperty. |
| 398 GetListProperty(shill::kServiceCompleteListProperty)->AppendIfNotPresent( | 422 GetListProperty(shill::kServiceCompleteListProperty)->AppendIfNotPresent( |
| 399 base::Value::CreateStringValue(service_path)); | 423 base::Value::CreateStringValue(service_path)); |
| 400 // If visible, add to Services and notify if new. | 424 // If visible, add to Services and notify if new. |
| 401 if (add_to_visible_list && | 425 if (add_to_visible_list && |
| 402 GetListProperty(shill::kServicesProperty)->AppendIfNotPresent( | 426 GetListProperty(shill::kServicesProperty) |
| 403 base::Value::CreateStringValue(service_path))) { | 427 ->AppendIfNotPresent(base::Value::CreateStringValue(service_path))) { |
| 404 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); | 428 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| 405 } | 429 } |
| 406 if (add_to_watch_list) | 430 if (add_to_watch_list) |
| 407 AddServiceToWatchList(service_path); | 431 AddServiceToWatchList(service_path); |
| 408 } | 432 } |
| 409 | 433 |
| 410 void FakeShillManagerClient::RemoveManagerService( | 434 void FakeShillManagerClient::RemoveManagerService( |
| 411 const std::string& service_path) { | 435 const std::string& service_path) { |
| 412 base::StringValue service_path_value(service_path); | 436 base::StringValue service_path_value(service_path); |
| 413 if (GetListProperty(shill::kServicesProperty)->Remove( | 437 if (GetListProperty(shill::kServicesProperty) |
| 414 service_path_value, NULL)) { | 438 ->Remove(service_path_value, NULL)) { |
| 415 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); | 439 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| 416 } | 440 } |
| 417 GetListProperty(shill::kServiceCompleteListProperty)->Remove( | 441 GetListProperty(shill::kServiceCompleteListProperty) |
| 418 service_path_value, NULL); | 442 ->Remove(service_path_value, NULL); |
| 419 if (GetListProperty(shill::kServiceWatchListProperty)->Remove( | 443 if (GetListProperty(shill::kServiceWatchListProperty) |
| 420 service_path_value, NULL)) { | 444 ->Remove(service_path_value, NULL)) { |
| 421 CallNotifyObserversPropertyChanged( | 445 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
| 422 shill::kServiceWatchListProperty, 0); | |
| 423 } | 446 } |
| 424 } | 447 } |
| 425 | 448 |
| 426 void FakeShillManagerClient::ClearManagerServices() { | 449 void FakeShillManagerClient::ClearManagerServices() { |
| 427 GetListProperty(shill::kServicesProperty)->Clear(); | 450 GetListProperty(shill::kServicesProperty)->Clear(); |
| 428 GetListProperty(shill::kServiceCompleteListProperty)->Clear(); | 451 GetListProperty(shill::kServiceCompleteListProperty)->Clear(); |
| 429 GetListProperty(shill::kServiceWatchListProperty)->Clear(); | 452 GetListProperty(shill::kServiceWatchListProperty)->Clear(); |
| 430 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); | 453 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| 431 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); | 454 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
| 432 } | 455 } |
| 433 | 456 |
| 434 void FakeShillManagerClient::SortManagerServices() { | 457 void FakeShillManagerClient::SortManagerServices() { |
| 435 static const char* ordered_types[] = { | 458 static const char* ordered_types[] = { |
| 436 shill::kTypeEthernet, | 459 shill::kTypeEthernet, |
| 437 shill::kTypeWifi, | 460 shill::kTypeWifi, |
| 438 shill::kTypeCellular, | 461 shill::kTypeCellular, |
| 439 shill::kTypeWimax, | 462 shill::kTypeWimax, |
| 440 shill::kTypeVPN | 463 shill::kTypeVPN |
| 441 }; | 464 }; |
| 442 base::ListValue* service_list = GetListProperty(shill::kServicesProperty); | 465 base::ListValue* service_list = GetListProperty(shill::kServicesProperty); |
| 443 if (!service_list || service_list->empty()) | 466 if (!service_list || service_list->empty()) |
| 444 return; | 467 return; |
| 445 std::vector<std::string> active_services; | 468 std::vector<std::string> active_services; |
| 446 std::vector<std::string> inactive_services; | 469 std::vector<std::string> inactive_services; |
| 447 for (size_t i = 0; i < arraysize(ordered_types); ++i) { | 470 for (size_t i = 0; i < arraysize(ordered_types); ++i) { |
| 448 AppendServicesForType(service_list, ordered_types[i], | 471 AppendServicesForType(service_list, ordered_types[i], |
| 449 &active_services, &inactive_services); | 472 &active_services, &inactive_services); |
| 450 } | 473 } |
| 451 service_list->Clear(); | 474 service_list->Clear(); |
| 452 for (size_t i = 0; i < active_services.size(); ++i) | 475 for (size_t i = 0; i < active_services.size(); ++i) |
| 453 service_list->AppendString(active_services[i]); | 476 service_list->AppendString(active_services[i]); |
| 454 for (size_t i = 0; i < inactive_services.size(); ++i) | 477 for (size_t i = 0; i < inactive_services.size(); ++i) |
| 455 service_list->AppendString(inactive_services[i]); | 478 service_list->AppendString(inactive_services[i]); |
| 456 | 479 |
| 457 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); | 480 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| 458 } | 481 } |
| 459 | 482 |
| 460 void FakeShillManagerClient::AddGeoNetwork( | 483 |
| 461 const std::string& technology, | 484 int FakeShillManagerClient::GetInteractiveDelay() const { |
| 462 const base::DictionaryValue& network) { | 485 return interactive_delay_; |
| 463 base::ListValue* list_value = NULL; | 486 } |
| 464 if (!stub_geo_networks_.GetListWithoutPathExpansion( | 487 |
| 465 technology, &list_value)) { | 488 std::string FakeShillManagerClient::GetInitialState( |
| 466 list_value = new base::ListValue; | 489 const std::string& type) const { |
| 467 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); | 490 std::map<std::string, std::string>::const_iterator iter = |
| 468 } | 491 shill_initial_state_map_.find(type); |
| 469 list_value->Append(network.DeepCopy()); | 492 if (iter == shill_initial_state_map_.end()) |
| 470 } | 493 return shill::kStateOffline; // Not available |
|
pneubeck (no reviews)
2014/03/03 20:36:19
this comment isn't not informative. please make it
stevenjb
2014/03/05 01:03:50
I made this function private now that the portal d
| |
| 471 | 494 return iter->second; |
| 472 void FakeShillManagerClient::AddProfile(const std::string& profile_path) { | 495 } |
| 473 const char* key = shill::kProfilesProperty; | 496 |
| 474 if (GetListProperty(key)->AppendIfNotPresent( | 497 void FakeShillManagerClient::SetupDefaultEnvironment() { |
| 475 new base::StringValue(profile_path))) { | 498 DBusThreadManager* dbus_manager = DBusThreadManager::Get(); |
| 476 CallNotifyObserversPropertyChanged(key, 0); | 499 ShillServiceClient::TestInterface* services = |
| 477 } | 500 dbus_manager->GetShillServiceClient()->GetTestInterface(); |
| 478 } | 501 ShillProfileClient::TestInterface* profiles = |
| 502 dbus_manager->GetShillProfileClient()->GetTestInterface(); | |
| 503 ShillDeviceClient::TestInterface* devices = | |
| 504 dbus_manager->GetShillDeviceClient()->GetTestInterface(); | |
| 505 if (!services || !profiles || !devices) | |
| 506 return; | |
| 507 | |
| 508 const std::string shared_profile = ShillProfileClient::GetSharedProfilePath(); | |
| 509 profiles->AddProfile(shared_profile, std::string()); | |
| 510 | |
| 511 const bool add_to_visible = true; | |
| 512 const bool add_to_watchlist = true; | |
| 513 | |
| 514 bool enabled, portaled; | |
| 515 std::string state; | |
| 516 | |
| 517 // Ethernet. No service is not added unless connected. | |
|
pneubeck (no reviews)
2014/03/03 20:36:19
'No ... not added unless' ?
Remove 'not'?
stevenjb
2014/03/05 01:03:50
Removed comment, behavior is now consistent across
| |
| 518 state = ParseInitialState(shill::kTypeEthernet, &enabled, &portaled); | |
| 519 if (state == shill::kStateOnline) { | |
| 520 AddTechnology(shill::kTypeEthernet, enabled); | |
| 521 devices->AddDevice( | |
| 522 "/device/eth1", shill::kTypeEthernet, "stub_eth_device1"); | |
| 523 services->AddService("eth1", "eth1", | |
| 524 shill::kTypeEthernet, | |
| 525 state, | |
| 526 add_to_visible, add_to_watchlist); | |
| 527 profiles->AddService(shared_profile, "eth1"); | |
| 528 } | |
| 529 | |
| 530 // Wifi | |
| 531 state = ParseInitialState(shill::kTypeWifi, &enabled, &portaled); | |
| 532 if (state != shill::kStateOffline) { | |
| 533 AddTechnology(shill::kTypeWifi, enabled); | |
| 534 devices->AddDevice("/device/wifi1", shill::kTypeWifi, "stub_wifi_device1"); | |
| 535 | |
| 536 services->AddService("wifi1", | |
| 537 "wifi1", | |
| 538 shill::kTypeWifi, | |
| 539 state, | |
| 540 add_to_visible, add_to_watchlist); | |
| 541 services->SetServiceProperty("wifi1", | |
| 542 shill::kSecurityProperty, | |
| 543 base::StringValue(shill::kSecurityWep)); | |
| 544 profiles->AddService(shared_profile, "wifi1"); | |
| 545 | |
| 546 services->AddService("wifi2", | |
| 547 "wifi2_PSK", | |
| 548 shill::kTypeWifi, | |
| 549 shill::kStateIdle, | |
| 550 add_to_visible, add_to_watchlist); | |
| 551 services->SetServiceProperty("wifi2", | |
| 552 shill::kSecurityProperty, | |
| 553 base::StringValue(shill::kSecurityPsk)); | |
| 554 | |
| 555 base::FundamentalValue strength_value(80); | |
| 556 services->SetServiceProperty( | |
| 557 "wifi2", shill::kSignalStrengthProperty, strength_value); | |
| 558 profiles->AddService(shared_profile, "wifi2"); | |
| 559 | |
| 560 if (portaled) { | |
| 561 const std::string kPortalledWifiPath = "portalled_wifi"; | |
| 562 services->AddService(kPortalledWifiPath, | |
| 563 "Portalled Wifi", | |
| 564 shill::kTypeWifi, | |
| 565 shill::kStatePortal, | |
| 566 add_to_visible, add_to_watchlist); | |
| 567 services->SetServiceProperty(kPortalledWifiPath, | |
| 568 shill::kSecurityProperty, | |
| 569 base::StringValue(shill::kSecurityNone)); | |
| 570 services->SetConnectBehavior(kPortalledWifiPath, | |
| 571 base::Bind(&UpdatePortalledWifiState, | |
| 572 "portalled_wifi")); | |
| 573 services->SetServiceProperty(kPortalledWifiPath, | |
| 574 shill::kConnectableProperty, | |
| 575 base::FundamentalValue(true)); | |
| 576 profiles->AddService(shared_profile, kPortalledWifiPath); | |
| 577 } | |
| 578 } | |
| 579 | |
| 580 // Wimax | |
| 581 state = ParseInitialState(shill::kTypeWimax, &enabled, &portaled); | |
| 582 if (state != shill::kStateOffline) { | |
| 583 AddTechnology(shill::kTypeWimax, enabled); | |
| 584 devices->AddDevice( | |
| 585 "/device/wimax1", shill::kTypeWimax, "stub_wimax_device1"); | |
| 586 | |
| 587 services->AddService("wimax1", | |
| 588 "wimax1", | |
| 589 shill::kTypeWimax, | |
| 590 state, | |
| 591 add_to_visible, add_to_watchlist); | |
| 592 services->SetServiceProperty( | |
| 593 "wimax1", shill::kConnectableProperty, base::FundamentalValue(true)); | |
| 594 } | |
| 595 | |
| 596 // Cellular | |
| 597 state = ParseInitialState(shill::kTypeCellular, &enabled, &portaled); | |
| 598 if (state != shill::kStateOffline) { | |
| 599 bool activated = false; | |
| 600 if (state == shill::kActivationStateActivated) { | |
| 601 activated = true; | |
| 602 state = shill::kStateIdle; | |
| 603 } | |
| 604 AddTechnology(shill::kTypeCellular, enabled); | |
| 605 devices->AddDevice( | |
| 606 "/device/cellular1", shill::kTypeCellular, "stub_cellular_device1"); | |
| 607 devices->SetDeviceProperty("/device/cellular1", | |
| 608 shill::kCarrierProperty, | |
| 609 base::StringValue(shill::kCarrierSprint)); | |
| 610 | |
| 611 services->AddService("cellular1", | |
| 612 "cellular1", | |
| 613 shill::kTypeCellular, | |
| 614 state, | |
| 615 add_to_visible, add_to_watchlist); | |
| 616 base::StringValue technology_value(shill::kNetworkTechnologyGsm); | |
| 617 services->SetServiceProperty( | |
| 618 "cellular1", shill::kNetworkTechnologyProperty, technology_value); | |
| 619 | |
| 620 if (activated) { | |
| 621 services->SetServiceProperty( | |
| 622 "cellular1", | |
| 623 shill::kActivationStateProperty, | |
| 624 base::StringValue(shill::kActivationStateActivated)); | |
| 625 services->SetServiceProperty("cellular1", | |
| 626 shill::kConnectableProperty, | |
| 627 base::FundamentalValue(true)); | |
| 628 } else { | |
| 629 services->SetServiceProperty( | |
| 630 "cellular1", | |
| 631 shill::kActivationStateProperty, | |
| 632 base::StringValue(shill::kActivationStateNotActivated)); | |
| 633 } | |
| 634 | |
| 635 services->SetServiceProperty("cellular1", | |
| 636 shill::kRoamingStateProperty, | |
| 637 base::StringValue(shill::kRoamingStateHome)); | |
| 638 } | |
| 639 | |
| 640 // VPN | |
| 641 state = ParseInitialState(shill::kTypeVPN, &enabled, &portaled); | |
| 642 if (state != shill::kStateOffline) { | |
| 643 // Set the "Provider" dictionary properties. Note: when setting these in | |
| 644 // Shill, "Provider.Type", etc keys are used, but when reading the values | |
| 645 // "Provider" . "Type", etc keys are used. Here we are setting the values | |
| 646 // that will be read (by the UI, tests, etc). | |
| 647 base::DictionaryValue provider_properties; | |
| 648 provider_properties.SetString(shill::kTypeProperty, | |
| 649 shill::kProviderOpenVpn); | |
| 650 provider_properties.SetString(shill::kHostProperty, "vpn_host"); | |
| 651 | |
| 652 services->AddService("vpn1", | |
| 653 "vpn1", | |
| 654 shill::kTypeVPN, | |
| 655 state, | |
| 656 add_to_visible, add_to_watchlist); | |
| 657 services->SetServiceProperty( | |
| 658 "vpn1", shill::kProviderProperty, provider_properties); | |
| 659 profiles->AddService(shared_profile, "vpn1"); | |
| 660 | |
| 661 services->AddService("vpn2", | |
| 662 "vpn2", | |
| 663 shill::kTypeVPN, | |
| 664 shill::kStateIdle, | |
| 665 add_to_visible, add_to_watchlist); | |
| 666 services->SetServiceProperty( | |
| 667 "vpn2", shill::kProviderProperty, provider_properties); | |
| 668 } | |
| 669 | |
| 670 SortManagerServices(); | |
| 671 } | |
| 672 | |
| 673 // Private methods | |
| 479 | 674 |
| 480 void FakeShillManagerClient::AddServiceToWatchList( | 675 void FakeShillManagerClient::AddServiceToWatchList( |
| 481 const std::string& service_path) { | 676 const std::string& service_path) { |
| 482 // Remove and insert the service, moving it to the front of the watch list. | 677 // Remove and insert the service, moving it to the front of the watch list. |
| 483 GetListProperty(shill::kServiceWatchListProperty)->Remove( | 678 GetListProperty(shill::kServiceWatchListProperty) |
| 484 base::StringValue(service_path), NULL); | 679 ->Remove(base::StringValue(service_path), NULL); |
| 485 GetListProperty(shill::kServiceWatchListProperty)->Insert( | 680 GetListProperty(shill::kServiceWatchListProperty) |
| 486 0, base::Value::CreateStringValue(service_path)); | 681 ->Insert(0, base::Value::CreateStringValue(service_path)); |
| 487 CallNotifyObserversPropertyChanged( | 682 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
| 488 shill::kServiceWatchListProperty, 0); | |
| 489 } | 683 } |
| 490 | 684 |
| 491 void FakeShillManagerClient::PassStubProperties( | 685 void FakeShillManagerClient::PassStubProperties( |
| 492 const DictionaryValueCallback& callback) const { | 686 const DictionaryValueCallback& callback) const { |
| 493 scoped_ptr<base::DictionaryValue> stub_properties( | 687 scoped_ptr<base::DictionaryValue> stub_properties( |
| 494 stub_properties_.DeepCopy()); | 688 stub_properties_.DeepCopy()); |
| 495 // Remove disabled services from the list. | 689 // Remove disabled services from the list. |
| 496 stub_properties->SetWithoutPathExpansion( | 690 stub_properties->SetWithoutPathExpansion( |
| 497 shill::kServicesProperty, | 691 shill::kServicesProperty, |
| 498 GetEnabledServiceList(shill::kServicesProperty)); | 692 GetEnabledServiceList(shill::kServicesProperty)); |
| 499 stub_properties->SetWithoutPathExpansion( | 693 stub_properties->SetWithoutPathExpansion( |
| 500 shill::kServiceWatchListProperty, | 694 shill::kServiceWatchListProperty, |
| 501 GetEnabledServiceList(shill::kServiceWatchListProperty)); | 695 GetEnabledServiceList(shill::kServiceWatchListProperty)); |
| 502 callback.Run(DBUS_METHOD_CALL_SUCCESS, *stub_properties); | 696 callback.Run(DBUS_METHOD_CALL_SUCCESS, *stub_properties); |
| 503 } | 697 } |
| 504 | 698 |
| 505 void FakeShillManagerClient::PassStubGeoNetworks( | 699 void FakeShillManagerClient::PassStubGeoNetworks( |
| 506 const DictionaryValueCallback& callback) const { | 700 const DictionaryValueCallback& callback) const { |
| 507 callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_geo_networks_); | 701 callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_geo_networks_); |
| 508 } | 702 } |
| 509 | 703 |
| 510 void FakeShillManagerClient::CallNotifyObserversPropertyChanged( | 704 void FakeShillManagerClient::CallNotifyObserversPropertyChanged( |
| 511 const std::string& property, | 705 const std::string& property) { |
| 512 int delay_ms) { | |
| 513 // Avoid unnecessary delayed task if we have no observers (e.g. during | 706 // Avoid unnecessary delayed task if we have no observers (e.g. during |
| 514 // initial setup). | 707 // initial setup). |
| 515 if (!observer_list_.might_have_observers()) | 708 if (!observer_list_.might_have_observers()) |
| 516 return; | 709 return; |
| 517 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 710 base::MessageLoop::current()->PostTask( |
| 518 chromeos::switches::kEnableStubInteractive)) { | |
| 519 delay_ms = 0; | |
| 520 } | |
| 521 base::MessageLoop::current()->PostDelayedTask( | |
| 522 FROM_HERE, | 711 FROM_HERE, |
| 523 base::Bind(&FakeShillManagerClient::NotifyObserversPropertyChanged, | 712 base::Bind(&FakeShillManagerClient::NotifyObserversPropertyChanged, |
| 524 weak_ptr_factory_.GetWeakPtr(), | 713 weak_ptr_factory_.GetWeakPtr(), |
| 525 property), | 714 property)); |
| 526 base::TimeDelta::FromMilliseconds(delay_ms)); | |
| 527 } | 715 } |
| 528 | 716 |
| 529 void FakeShillManagerClient::NotifyObserversPropertyChanged( | 717 void FakeShillManagerClient::NotifyObserversPropertyChanged( |
| 530 const std::string& property) { | 718 const std::string& property) { |
| 531 if (property == shill::kServicesProperty || | 719 if (property == shill::kServicesProperty || |
| 532 property == shill::kServiceWatchListProperty) { | 720 property == shill::kServiceWatchListProperty) { |
| 533 scoped_ptr<base::ListValue> services(GetEnabledServiceList(property)); | 721 scoped_ptr<base::ListValue> services(GetEnabledServiceList(property)); |
| 534 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, | 722 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, |
| 535 observer_list_, | 723 observer_list_, |
| 536 OnPropertyChanged(property, *(services.get()))); | 724 OnPropertyChanged(property, *(services.get()))); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 if (technologies->Find(type_value) != technologies->end()) | 766 if (technologies->Find(type_value) != technologies->end()) |
| 579 enabled = true; | 767 enabled = true; |
| 580 } | 768 } |
| 581 return enabled; | 769 return enabled; |
| 582 } | 770 } |
| 583 | 771 |
| 584 void FakeShillManagerClient::SetTechnologyEnabled( | 772 void FakeShillManagerClient::SetTechnologyEnabled( |
| 585 const std::string& type, | 773 const std::string& type, |
| 586 const base::Closure& callback, | 774 const base::Closure& callback, |
| 587 bool enabled) { | 775 bool enabled) { |
| 588 base::ListValue* enabled_list = NULL; | 776 base::ListValue* enabled_list = |
| 589 stub_properties_.GetListWithoutPathExpansion( | 777 GetListProperty(shill::kEnabledTechnologiesProperty); |
| 590 shill::kEnabledTechnologiesProperty, &enabled_list); | |
| 591 DCHECK(enabled_list); | |
| 592 if (enabled) | 778 if (enabled) |
| 593 enabled_list->AppendIfNotPresent(new base::StringValue(type)); | 779 enabled_list->AppendIfNotPresent(new base::StringValue(type)); |
| 594 else | 780 else |
| 595 enabled_list->Remove(base::StringValue(type), NULL); | 781 enabled_list->Remove(base::StringValue(type), NULL); |
| 596 CallNotifyObserversPropertyChanged( | 782 CallNotifyObserversPropertyChanged(shill::kEnabledTechnologiesProperty); |
| 597 shill::kEnabledTechnologiesProperty, 0 /* already delayed */); | |
| 598 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 783 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 599 // May affect available services | 784 // May affect available services |
| 600 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); | 785 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| 601 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); | 786 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
| 602 } | 787 } |
| 603 | 788 |
| 604 base::ListValue* FakeShillManagerClient::GetEnabledServiceList( | 789 base::ListValue* FakeShillManagerClient::GetEnabledServiceList( |
| 605 const std::string& property) const { | 790 const std::string& property) const { |
| 606 base::ListValue* new_service_list = new base::ListValue; | 791 base::ListValue* new_service_list = new base::ListValue; |
| 607 const base::ListValue* service_list; | 792 const base::ListValue* service_list; |
| 608 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) { | 793 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) { |
| 609 ShillServiceClient::TestInterface* service_client = | 794 ShillServiceClient::TestInterface* service_client = |
| 610 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 795 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 611 for (base::ListValue::const_iterator iter = service_list->begin(); | 796 for (base::ListValue::const_iterator iter = service_list->begin(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 631 } | 816 } |
| 632 | 817 |
| 633 void FakeShillManagerClient::ScanCompleted(const std::string& device_path, | 818 void FakeShillManagerClient::ScanCompleted(const std::string& device_path, |
| 634 const base::Closure& callback) { | 819 const base::Closure& callback) { |
| 635 if (!device_path.empty()) { | 820 if (!device_path.empty()) { |
| 636 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()-> | 821 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()-> |
| 637 SetDeviceProperty(device_path, | 822 SetDeviceProperty(device_path, |
| 638 shill::kScanningProperty, | 823 shill::kScanningProperty, |
| 639 base::FundamentalValue(false)); | 824 base::FundamentalValue(false)); |
| 640 } | 825 } |
| 641 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); | 826 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| 642 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); | 827 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
| 643 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 828 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 644 } | 829 } |
| 645 | 830 |
| 831 void FakeShillManagerClient::ParseCommandLineSwitch() { | |
|
pneubeck (no reviews)
2014/03/03 20:36:19
we need a documentation of the format of this comm
stevenjb
2014/03/05 01:03:50
Documentation is in dbus_command_line_helper plus
| |
| 832 if (dbus_command_line_helper::ParseOptions( | |
| 833 switches::kShillStub, | |
| 834 base::Bind(&FakeShillManagerClient::ParseOption, | |
| 835 base::Unretained(this)))) | |
|
pneubeck (no reviews)
2014/03/03 20:36:19
nit: missing { }
stevenjb
2014/03/05 01:03:50
Done.
| |
| 836 return; | |
| 837 // Default setup | |
| 838 SetInitialNetworkState(shill::kTypeEthernet, shill::kStateOnline); | |
| 839 SetInitialNetworkState(shill::kTypeWifi, shill::kStateOnline); | |
| 840 SetInitialNetworkState(shill::kTypeCellular, shill::kStateIdle); | |
| 841 SetInitialNetworkState(shill::kTypeVPN, shill::kStateIdle); | |
| 842 } | |
| 843 | |
| 844 bool FakeShillManagerClient::ParseOption(const std::string& arg0, | |
| 845 const std::string& arg1) { | |
| 846 if (arg0 == "interactive") { | |
| 847 int seconds = 3; | |
| 848 if (!arg1.empty()) | |
| 849 base::StringToInt(arg1, &seconds); | |
| 850 interactive_delay_ = seconds; | |
| 851 return true; | |
| 852 } | |
| 853 return SetInitialNetworkState(arg0, arg1); | |
| 854 } | |
| 855 | |
| 856 bool FakeShillManagerClient::SetInitialNetworkState(std::string type_arg, | |
| 857 std::string state_arg) { | |
|
pneubeck (no reviews)
2014/03/03 20:36:19
I'd fail on state_arg.empty() instead of doing a d
stevenjb
2014/03/05 01:03:50
I specifically want an empty state arg to default
| |
| 858 std::string state; | |
| 859 state_arg = StringToLowerASCII(state_arg); | |
| 860 if (state_arg == "0" || state_arg == "off" || state_arg == "inactive" || | |
|
pneubeck (no reviews)
2014/03/03 20:36:19
this is only a testing interface for developers/te
stevenjb
2014/03/05 01:03:50
I feel the opposite. Since it's a testing interfac
| |
| 861 state_arg == shill::kStateIdle) | |
| 862 state = shill::kStateIdle; // Enabled but not connected | |
| 863 else if (state_arg == "disabled" || state_arg == "disconnect") | |
| 864 state = shill::kStateDisconnect; // Diabled but available | |
|
pneubeck (no reviews)
2014/03/03 20:36:19
typo: Diabled -> Disabled
stevenjb
2014/03/05 01:03:50
Done.
| |
| 865 else if (state_arg == "none" || state_arg == "offline") | |
| 866 state = shill::kStateOffline; // Not available | |
|
pneubeck (no reviews)
2014/03/03 20:36:19
this comment doesn't seem very explanatory. maybe
stevenjb
2014/03/05 01:03:50
Improved all comments.
| |
| 867 else if (state_arg == "portal") | |
| 868 state = shill::kStatePortal; // Connected to portal | |
| 869 else if (state_arg == "active" || state_arg == "activated") | |
| 870 state = shill::kActivationStateActivated; // Connected and activated | |
|
pneubeck (no reviews)
2014/03/03 20:36:19
*teeth grinding*
maybe not such a good idea to ass
stevenjb
2014/03/05 01:03:50
1. I used local values for special states "Unavail
| |
| 871 else | |
| 872 state = shill::kStateOnline; // Connected | |
| 873 | |
| 874 std::string type; | |
| 875 type_arg = StringToLowerASCII(type_arg); | |
| 876 if (type_arg == "ethernet" || type_arg == "eth") { | |
| 877 if (state == shill::kStateIdle || state == shill::kStateDisconnect) | |
| 878 state = shill::kStateOffline; // No unconnected or disabled ethernet. | |
| 879 shill_initial_state_map_[shill::kTypeEthernet] = state; | |
|
pneubeck (no reviews)
2014/03/03 20:36:19
the if-branches could decide on the shill type str
stevenjb
2014/03/05 01:03:50
Sure. I thought I might have more synonyms, but I
| |
| 880 } else if (type_arg == "wifi") { | |
| 881 shill_initial_state_map_[shill::kTypeWifi] = state; | |
| 882 } else if (type_arg == "cellular") { | |
| 883 shill_initial_state_map_[shill::kTypeCellular] = state; | |
| 884 } else if (type_arg == "wireless") { | |
|
pneubeck (no reviews)
2014/03/03 20:36:19
considering that this is only an interface for tes
stevenjb
2014/03/05 01:03:50
Yes. This was easier/faster, but sure.
| |
| 885 shill_initial_state_map_[shill::kTypeWifi] = state; | |
| 886 shill_initial_state_map_[shill::kTypeCellular] = state; | |
| 887 } else if (type_arg == "wimax") { | |
| 888 shill_initial_state_map_[shill::kTypeWimax] = state; | |
| 889 } else if (type_arg == "vpn") { | |
| 890 shill_initial_state_map_[shill::kTypeVPN] = state; | |
| 891 } else { | |
| 892 LOG(WARNING) << "Unrecognized Shill network type: " << type_arg; | |
| 893 return false; | |
| 894 } | |
| 895 return true; | |
| 896 } | |
| 897 | |
| 898 std::string FakeShillManagerClient::ParseInitialState(const std::string& type, | |
|
pneubeck (no reviews)
2014/03/03 20:36:19
this is not really about parsing. maybe call it so
stevenjb
2014/03/05 01:03:50
Done.
| |
| 899 bool* enabled, | |
| 900 bool* portaled) { | |
| 901 std::string state = GetInitialState(type); | |
| 902 if (state == shill::kStateDisconnect) { | |
| 903 *enabled = false; | |
| 904 *portaled = false; | |
| 905 return shill::kStateIdle; | |
| 906 } | |
| 907 if (state == shill::kStatePortal) { | |
| 908 if (type != shill::kTypeWifi) | |
| 909 LOG(WARNING) << "Invalid state: " << state << " for " << type; | |
| 910 *enabled = true; | |
| 911 *portaled = true; | |
| 912 return shill::kStateIdle; | |
| 913 } | |
| 914 if (state == shill::kActivationStateActivated && | |
| 915 type != shill::kTypeCellular) { | |
|
pneubeck (no reviews)
2014/03/03 20:36:19
better make this the default case and let it skip
stevenjb
2014/03/05 01:03:50
Done.
| |
| 916 LOG(WARNING) << "Invalid state: " << state << " for " << type; | |
| 917 state = shill::kStateIdle; | |
| 918 } | |
| 919 *enabled = true; | |
| 920 *portaled = false; | |
| 921 return state; | |
| 922 } | |
| 923 | |
| 646 } // namespace chromeos | 924 } // namespace chromeos |
| OLD | NEW |