| 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_manager_client_stub.h" | 5 #include "chromeos/dbus/shill_manager_client_stub.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/chromeos/chromeos_version.h" | 8 #include "base/chromeos/chromeos_version.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 if (!stub_properties_.GetListWithoutPathExpansion( | 110 if (!stub_properties_.GetListWithoutPathExpansion( |
| 111 flimflam::kEnabledTechnologiesProperty, &enabled_list)) { | 111 flimflam::kEnabledTechnologiesProperty, &enabled_list)) { |
| 112 if (!error_callback.is_null()) { | 112 if (!error_callback.is_null()) { |
| 113 MessageLoop::current()->PostTask(FROM_HERE, callback); | 113 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 114 MessageLoop::current()->PostTask( | 114 MessageLoop::current()->PostTask( |
| 115 FROM_HERE, | 115 FROM_HERE, |
| 116 base::Bind(error_callback, "StubError", "Property not found")); | 116 base::Bind(error_callback, "StubError", "Property not found")); |
| 117 } | 117 } |
| 118 return; | 118 return; |
| 119 } | 119 } |
| 120 enabled_list->AppendIfNotPresent(new base::StringValue(type)); | 120 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 121 CallNotifyObserversPropertyChanged( | 121 chromeos::switches::kEnableStubInteractive)) { |
| 122 flimflam::kEnabledTechnologiesProperty, 0); | 122 const int kEnableTechnologyDelaySeconds = 3; |
| 123 if (!callback.is_null()) | 123 MessageLoop::current()->PostDelayedTask( |
| 124 MessageLoop::current()->PostTask(FROM_HERE, callback); | 124 FROM_HERE, |
| 125 // May affect available services | 125 base::Bind(&ShillManagerClientStub::SetTechnologyEnabled, |
| 126 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | 126 weak_ptr_factory_.GetWeakPtr(), type, callback, true), |
| 127 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, 0); | 127 base::TimeDelta::FromSeconds(kEnableTechnologyDelaySeconds)); |
| 128 } else { |
| 129 SetTechnologyEnabled(type, callback, true); |
| 130 } |
| 128 } | 131 } |
| 129 | 132 |
| 130 void ShillManagerClientStub::DisableTechnology( | 133 void ShillManagerClientStub::DisableTechnology( |
| 131 const std::string& type, | 134 const std::string& type, |
| 132 const base::Closure& callback, | 135 const base::Closure& callback, |
| 133 const ErrorCallback& error_callback) { | 136 const ErrorCallback& error_callback) { |
| 134 base::ListValue* enabled_list = NULL; | 137 base::ListValue* enabled_list = NULL; |
| 135 if (!stub_properties_.GetListWithoutPathExpansion( | 138 if (!stub_properties_.GetListWithoutPathExpansion( |
| 136 flimflam::kEnabledTechnologiesProperty, &enabled_list)) { | 139 flimflam::kEnabledTechnologiesProperty, &enabled_list)) { |
| 137 if (!error_callback.is_null()) { | 140 if (!error_callback.is_null()) { |
| 138 MessageLoop::current()->PostTask( | 141 MessageLoop::current()->PostTask( |
| 139 FROM_HERE, | 142 FROM_HERE, |
| 140 base::Bind(error_callback, "StubError", "Property not found")); | 143 base::Bind(error_callback, "StubError", "Property not found")); |
| 141 } | 144 } |
| 142 return; | 145 return; |
| 143 } | 146 } |
| 144 base::StringValue type_value(type); | 147 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 145 enabled_list->Remove(type_value, NULL); | 148 chromeos::switches::kEnableStubInteractive)) { |
| 146 CallNotifyObserversPropertyChanged( | 149 const int kDisableTechnologyDelaySeconds = 3; |
| 147 flimflam::kEnabledTechnologiesProperty, 0); | 150 MessageLoop::current()->PostDelayedTask( |
| 148 if (!callback.is_null()) | 151 FROM_HERE, |
| 149 MessageLoop::current()->PostTask(FROM_HERE, callback); | 152 base::Bind(&ShillManagerClientStub::SetTechnologyEnabled, |
| 150 // May affect available services | 153 weak_ptr_factory_.GetWeakPtr(), type, callback, false), |
| 151 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | 154 base::TimeDelta::FromSeconds(kDisableTechnologyDelaySeconds)); |
| 152 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, 0); | 155 } else { |
| 153 } | 156 SetTechnologyEnabled(type, callback, false); |
| 157 } |
| 158 } |
| 154 | 159 |
| 155 void ShillManagerClientStub::ConfigureService( | 160 void ShillManagerClientStub::ConfigureService( |
| 156 const base::DictionaryValue& properties, | 161 const base::DictionaryValue& properties, |
| 157 const ObjectPathCallback& callback, | 162 const ObjectPathCallback& callback, |
| 158 const ErrorCallback& error_callback) { | 163 const ErrorCallback& error_callback) { |
| 159 if (callback.is_null()) | 164 if (callback.is_null()) |
| 160 return; | 165 return; |
| 161 | 166 |
| 162 // For the purposes of this stub, we're going to assume that the GUID property | 167 // For the purposes of this stub, we're going to assume that the GUID property |
| 163 // is set to the service path because we don't want to re-implement Shill's | 168 // is set to the service path because we don't want to re-implement Shill's |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_geo_networks_); | 423 callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_geo_networks_); |
| 419 } | 424 } |
| 420 | 425 |
| 421 void ShillManagerClientStub::CallNotifyObserversPropertyChanged( | 426 void ShillManagerClientStub::CallNotifyObserversPropertyChanged( |
| 422 const std::string& property, | 427 const std::string& property, |
| 423 int delay_ms) { | 428 int delay_ms) { |
| 424 // Avoid unnecessary delayed task if we have no observers (e.g. during | 429 // Avoid unnecessary delayed task if we have no observers (e.g. during |
| 425 // initial setup). | 430 // initial setup). |
| 426 if (observer_list_.size() == 0) | 431 if (observer_list_.size() == 0) |
| 427 return; | 432 return; |
| 433 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 434 chromeos::switches::kEnableStubInteractive)) { |
| 435 delay_ms = 0; |
| 436 } |
| 428 MessageLoop::current()->PostDelayedTask( | 437 MessageLoop::current()->PostDelayedTask( |
| 429 FROM_HERE, | 438 FROM_HERE, |
| 430 base::Bind(&ShillManagerClientStub::NotifyObserversPropertyChanged, | 439 base::Bind(&ShillManagerClientStub::NotifyObserversPropertyChanged, |
| 431 weak_ptr_factory_.GetWeakPtr(), | 440 weak_ptr_factory_.GetWeakPtr(), |
| 432 property), | 441 property), |
| 433 base::TimeDelta::FromMilliseconds(delay_ms)); | 442 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 434 } | 443 } |
| 435 | 444 |
| 436 void ShillManagerClientStub::NotifyObserversPropertyChanged( | 445 void ShillManagerClientStub::NotifyObserversPropertyChanged( |
| 437 const std::string& property) { | 446 const std::string& property) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 const base::ListValue* technologies; | 480 const base::ListValue* technologies; |
| 472 if (stub_properties_.GetListWithoutPathExpansion( | 481 if (stub_properties_.GetListWithoutPathExpansion( |
| 473 flimflam::kEnabledTechnologiesProperty, &technologies)) { | 482 flimflam::kEnabledTechnologiesProperty, &technologies)) { |
| 474 base::StringValue type_value(type); | 483 base::StringValue type_value(type); |
| 475 if (technologies->Find(type_value) != technologies->end()) | 484 if (technologies->Find(type_value) != technologies->end()) |
| 476 enabled = true; | 485 enabled = true; |
| 477 } | 486 } |
| 478 return enabled; | 487 return enabled; |
| 479 } | 488 } |
| 480 | 489 |
| 490 void ShillManagerClientStub::SetTechnologyEnabled( |
| 491 const std::string& type, |
| 492 const base::Closure& callback, |
| 493 bool enabled) { |
| 494 base::ListValue* enabled_list = NULL; |
| 495 stub_properties_.GetListWithoutPathExpansion( |
| 496 flimflam::kEnabledTechnologiesProperty, &enabled_list); |
| 497 DCHECK(enabled_list); |
| 498 if (enabled) |
| 499 enabled_list->AppendIfNotPresent(new base::StringValue(type)); |
| 500 else |
| 501 enabled_list->Remove(base::StringValue(type), NULL); |
| 502 CallNotifyObserversPropertyChanged( |
| 503 flimflam::kEnabledTechnologiesProperty, 0 /* already delayed */); |
| 504 if (!callback.is_null()) |
| 505 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 506 // May affect available services |
| 507 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); |
| 508 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, 0); |
| 509 } |
| 510 |
| 481 base::ListValue* ShillManagerClientStub::GetEnabledServiceList( | 511 base::ListValue* ShillManagerClientStub::GetEnabledServiceList( |
| 482 const std::string& property) const { | 512 const std::string& property) const { |
| 483 base::ListValue* new_service_list = new base::ListValue; | 513 base::ListValue* new_service_list = new base::ListValue; |
| 484 const base::ListValue* service_list; | 514 const base::ListValue* service_list; |
| 485 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) { | 515 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) { |
| 486 ShillServiceClient::TestInterface* service_client = | 516 ShillServiceClient::TestInterface* service_client = |
| 487 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 517 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 488 for (base::ListValue::const_iterator iter = service_list->begin(); | 518 for (base::ListValue::const_iterator iter = service_list->begin(); |
| 489 iter != service_list->end(); ++iter) { | 519 iter != service_list->end(); ++iter) { |
| 490 std::string service_path; | 520 std::string service_path; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 501 std::string type; | 531 std::string type; |
| 502 properties->GetString(flimflam::kTypeProperty, &type); | 532 properties->GetString(flimflam::kTypeProperty, &type); |
| 503 if (TechnologyEnabled(type)) | 533 if (TechnologyEnabled(type)) |
| 504 new_service_list->Append((*iter)->DeepCopy()); | 534 new_service_list->Append((*iter)->DeepCopy()); |
| 505 } | 535 } |
| 506 } | 536 } |
| 507 return new_service_list; | 537 return new_service_list; |
| 508 } | 538 } |
| 509 | 539 |
| 510 } // namespace chromeos | 540 } // namespace chromeos |
| OLD | NEW |