| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 if (!stub_properties_.GetListWithoutPathExpansion( | 128 if (!stub_properties_.GetListWithoutPathExpansion( |
| 129 flimflam::kEnabledTechnologiesProperty, &enabled_list)) { | 129 flimflam::kEnabledTechnologiesProperty, &enabled_list)) { |
| 130 if (!error_callback.is_null()) { | 130 if (!error_callback.is_null()) { |
| 131 MessageLoop::current()->PostTask(FROM_HERE, callback); | 131 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 132 MessageLoop::current()->PostTask( | 132 MessageLoop::current()->PostTask( |
| 133 FROM_HERE, | 133 FROM_HERE, |
| 134 base::Bind(error_callback, "StubError", "Property not found")); | 134 base::Bind(error_callback, "StubError", "Property not found")); |
| 135 } | 135 } |
| 136 return; | 136 return; |
| 137 } | 137 } |
| 138 enabled_list->AppendIfNotPresent(new base::StringValue(type)); | 138 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 139 CallNotifyObserversPropertyChanged( | 139 chromeos::switches::kEnableStubInteractive)) { |
| 140 flimflam::kEnabledTechnologiesProperty, 0); | 140 const int kEnableTechnologyDelaySeconds = 3; |
| 141 if (!callback.is_null()) | 141 MessageLoop::current()->PostDelayedTask( |
| 142 MessageLoop::current()->PostTask(FROM_HERE, callback); | 142 FROM_HERE, |
| 143 // May affect available services | 143 base::Bind(&ShillManagerClientStub::SetTechnologyEnabled, |
| 144 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | 144 weak_ptr_factory_.GetWeakPtr(), type, callback, true), |
| 145 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, 0); | 145 base::TimeDelta::FromSeconds(kEnableTechnologyDelaySeconds)); |
| 146 } else { |
| 147 SetTechnologyEnabled(type, callback, true); |
| 148 } |
| 146 } | 149 } |
| 147 | 150 |
| 148 void ShillManagerClientStub::DisableTechnology( | 151 void ShillManagerClientStub::DisableTechnology( |
| 149 const std::string& type, | 152 const std::string& type, |
| 150 const base::Closure& callback, | 153 const base::Closure& callback, |
| 151 const ErrorCallback& error_callback) { | 154 const ErrorCallback& error_callback) { |
| 152 base::ListValue* enabled_list = NULL; | 155 base::ListValue* enabled_list = NULL; |
| 153 if (!stub_properties_.GetListWithoutPathExpansion( | 156 if (!stub_properties_.GetListWithoutPathExpansion( |
| 154 flimflam::kEnabledTechnologiesProperty, &enabled_list)) { | 157 flimflam::kEnabledTechnologiesProperty, &enabled_list)) { |
| 155 if (!error_callback.is_null()) { | 158 if (!error_callback.is_null()) { |
| 156 MessageLoop::current()->PostTask( | 159 MessageLoop::current()->PostTask( |
| 157 FROM_HERE, | 160 FROM_HERE, |
| 158 base::Bind(error_callback, "StubError", "Property not found")); | 161 base::Bind(error_callback, "StubError", "Property not found")); |
| 159 } | 162 } |
| 160 return; | 163 return; |
| 161 } | 164 } |
| 162 base::StringValue type_value(type); | 165 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 163 enabled_list->Remove(type_value, NULL); | 166 chromeos::switches::kEnableStubInteractive)) { |
| 164 CallNotifyObserversPropertyChanged( | 167 const int kDisableTechnologyDelaySeconds = 3; |
| 165 flimflam::kEnabledTechnologiesProperty, 0); | 168 MessageLoop::current()->PostDelayedTask( |
| 166 if (!callback.is_null()) | 169 FROM_HERE, |
| 167 MessageLoop::current()->PostTask(FROM_HERE, callback); | 170 base::Bind(&ShillManagerClientStub::SetTechnologyEnabled, |
| 168 // May affect available services | 171 weak_ptr_factory_.GetWeakPtr(), type, callback, false), |
| 169 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | 172 base::TimeDelta::FromSeconds(kDisableTechnologyDelaySeconds)); |
| 170 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, 0); | 173 } else { |
| 171 } | 174 SetTechnologyEnabled(type, callback, false); |
| 175 } |
| 176 } |
| 172 | 177 |
| 173 void ShillManagerClientStub::ConfigureService( | 178 void ShillManagerClientStub::ConfigureService( |
| 174 const base::DictionaryValue& properties, | 179 const base::DictionaryValue& properties, |
| 175 const ObjectPathCallback& callback, | 180 const ObjectPathCallback& callback, |
| 176 const ErrorCallback& error_callback) { | 181 const ErrorCallback& error_callback) { |
| 177 if (callback.is_null()) | 182 if (callback.is_null()) |
| 178 return; | 183 return; |
| 179 | 184 |
| 180 // For the purposes of this stub, we're going to assume that the GUID property | 185 // For the purposes of this stub, we're going to assume that the GUID property |
| 181 // is set to the service path because we don't want to re-implement Shill's | 186 // is set to the service path because we don't want to re-implement Shill's |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 // Don't actually delay unless we're interactive. | 446 // Don't actually delay unless we're interactive. |
| 442 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 447 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 443 chromeos::switches::kEnableStubInteractive)) { | 448 chromeos::switches::kEnableStubInteractive)) { |
| 444 delay_ms = 0; | 449 delay_ms = 0; |
| 445 } | 450 } |
| 446 | 451 |
| 447 // Avoid unnecessary delayed task if we have no observers (e.g. during | 452 // Avoid unnecessary delayed task if we have no observers (e.g. during |
| 448 // initial setup). | 453 // initial setup). |
| 449 if (observer_list_.size() == 0) | 454 if (observer_list_.size() == 0) |
| 450 return; | 455 return; |
| 456 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 457 chromeos::switches::kEnableStubInteractive)) { |
| 458 delay_ms = 0; |
| 459 } |
| 451 MessageLoop::current()->PostDelayedTask( | 460 MessageLoop::current()->PostDelayedTask( |
| 452 FROM_HERE, | 461 FROM_HERE, |
| 453 base::Bind(&ShillManagerClientStub::NotifyObserversPropertyChanged, | 462 base::Bind(&ShillManagerClientStub::NotifyObserversPropertyChanged, |
| 454 weak_ptr_factory_.GetWeakPtr(), | 463 weak_ptr_factory_.GetWeakPtr(), |
| 455 property), | 464 property), |
| 456 base::TimeDelta::FromMilliseconds(delay_ms)); | 465 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 457 } | 466 } |
| 458 | 467 |
| 459 void ShillManagerClientStub::NotifyObserversPropertyChanged( | 468 void ShillManagerClientStub::NotifyObserversPropertyChanged( |
| 460 const std::string& property) { | 469 const std::string& property) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 const base::ListValue* technologies; | 503 const base::ListValue* technologies; |
| 495 if (stub_properties_.GetListWithoutPathExpansion( | 504 if (stub_properties_.GetListWithoutPathExpansion( |
| 496 flimflam::kEnabledTechnologiesProperty, &technologies)) { | 505 flimflam::kEnabledTechnologiesProperty, &technologies)) { |
| 497 base::StringValue type_value(type); | 506 base::StringValue type_value(type); |
| 498 if (technologies->Find(type_value) != technologies->end()) | 507 if (technologies->Find(type_value) != technologies->end()) |
| 499 enabled = true; | 508 enabled = true; |
| 500 } | 509 } |
| 501 return enabled; | 510 return enabled; |
| 502 } | 511 } |
| 503 | 512 |
| 513 void ShillManagerClientStub::SetTechnologyEnabled( |
| 514 const std::string& type, |
| 515 const base::Closure& callback, |
| 516 bool enabled) { |
| 517 base::ListValue* enabled_list = NULL; |
| 518 stub_properties_.GetListWithoutPathExpansion( |
| 519 flimflam::kEnabledTechnologiesProperty, &enabled_list); |
| 520 DCHECK(enabled_list); |
| 521 if (enabled) |
| 522 enabled_list->AppendIfNotPresent(new base::StringValue(type)); |
| 523 else |
| 524 enabled_list->Remove(base::StringValue(type), NULL); |
| 525 CallNotifyObserversPropertyChanged( |
| 526 flimflam::kEnabledTechnologiesProperty, 0 /* already delayed */); |
| 527 if (!callback.is_null()) |
| 528 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 529 // May affect available services |
| 530 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); |
| 531 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, 0); |
| 532 } |
| 533 |
| 504 base::ListValue* ShillManagerClientStub::GetEnabledServiceList( | 534 base::ListValue* ShillManagerClientStub::GetEnabledServiceList( |
| 505 const std::string& property) const { | 535 const std::string& property) const { |
| 506 base::ListValue* new_service_list = new base::ListValue; | 536 base::ListValue* new_service_list = new base::ListValue; |
| 507 const base::ListValue* service_list; | 537 const base::ListValue* service_list; |
| 508 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) { | 538 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) { |
| 509 ShillServiceClient::TestInterface* service_client = | 539 ShillServiceClient::TestInterface* service_client = |
| 510 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 540 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 511 for (base::ListValue::const_iterator iter = service_list->begin(); | 541 for (base::ListValue::const_iterator iter = service_list->begin(); |
| 512 iter != service_list->end(); ++iter) { | 542 iter != service_list->end(); ++iter) { |
| 513 std::string service_path; | 543 std::string service_path; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 539 base::FundamentalValue(false)); | 569 base::FundamentalValue(false)); |
| 540 } | 570 } |
| 541 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | 571 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); |
| 542 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, | 572 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, |
| 543 0); | 573 0); |
| 544 if (!callback.is_null()) | 574 if (!callback.is_null()) |
| 545 MessageLoop::current()->PostTask(FROM_HERE, callback); | 575 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 546 } | 576 } |
| 547 | 577 |
| 548 } // namespace chromeos | 578 } // namespace chromeos |
| OLD | NEW |