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/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 FROM_HERE, | 171 FROM_HERE, |
172 base::Bind(&PassStubListValue, | 172 base::Bind(&PassStubListValue, |
173 callback, base::Owned(results.release()))); | 173 callback, base::Owned(results.release()))); |
174 } | 174 } |
175 | 175 |
176 void FakeShillServiceClient::Connect(const dbus::ObjectPath& service_path, | 176 void FakeShillServiceClient::Connect(const dbus::ObjectPath& service_path, |
177 const base::Closure& callback, | 177 const base::Closure& callback, |
178 const ErrorCallback& error_callback) { | 178 const ErrorCallback& error_callback) { |
179 VLOG(1) << "FakeShillServiceClient::Connect: " << service_path.value(); | 179 VLOG(1) << "FakeShillServiceClient::Connect: " << service_path.value(); |
180 base::DictionaryValue* service_properties = NULL; | 180 base::DictionaryValue* service_properties = NULL; |
181 if (!stub_services_.GetDictionary( | 181 if (!stub_services_.GetDictionary(service_path.value(), |
182 service_path.value(), &service_properties)) { | 182 &service_properties)) { |
183 LOG(ERROR) << "Service not found: " << service_path.value(); | 183 LOG(ERROR) << "Service not found: " << service_path.value(); |
184 error_callback.Run("Error.InvalidService", "Invalid Service"); | 184 error_callback.Run("Error.InvalidService", "Invalid Service"); |
185 return; | 185 return; |
186 } | 186 } |
187 | 187 |
188 // Set any other services of the same Type to 'offline' first, before setting | 188 // Set any other services of the same Type to 'offline' first, before setting |
189 // State to Association which will trigger sorting Manager.Services and | 189 // State to Association which will trigger sorting Manager.Services and |
190 // sending an update. | 190 // sending an update. |
191 SetOtherServicesOffline(service_path.value()); | 191 SetOtherServicesOffline(service_path.value()); |
192 | 192 |
| 193 // Clear Error. |
| 194 service_properties->SetStringWithoutPathExpansion(shill::kErrorProperty, ""); |
| 195 |
193 // Set Associating. | 196 // Set Associating. |
194 base::StringValue associating_value(shill::kStateAssociation); | 197 base::StringValue associating_value(shill::kStateAssociation); |
195 SetServiceProperty(service_path.value(), | 198 SetServiceProperty(service_path.value(), shill::kStateProperty, |
196 shill::kStateProperty, | |
197 associating_value); | 199 associating_value); |
198 | 200 |
199 // Stay Associating until the state is changed again after a delay. | 201 // Stay Associating until the state is changed again after a delay. |
200 base::MessageLoop::current()->PostDelayedTask( | 202 base::MessageLoop::current()->PostDelayedTask( |
201 FROM_HERE, | 203 FROM_HERE, |
202 base::Bind(&FakeShillServiceClient::ContinueConnect, | 204 base::Bind(&FakeShillServiceClient::ContinueConnect, |
203 weak_ptr_factory_.GetWeakPtr(), | 205 weak_ptr_factory_.GetWeakPtr(), service_path.value()), |
204 service_path.value()), | |
205 base::TimeDelta::FromSeconds(GetInteractiveDelay())); | 206 base::TimeDelta::FromSeconds(GetInteractiveDelay())); |
206 | 207 |
207 callback.Run(); | 208 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
208 } | 209 } |
209 | 210 |
210 void FakeShillServiceClient::Disconnect(const dbus::ObjectPath& service_path, | 211 void FakeShillServiceClient::Disconnect(const dbus::ObjectPath& service_path, |
211 const base::Closure& callback, | 212 const base::Closure& callback, |
212 const ErrorCallback& error_callback) { | 213 const ErrorCallback& error_callback) { |
213 base::Value* service; | 214 base::Value* service; |
214 if (!stub_services_.Get(service_path.value(), &service)) { | 215 if (!stub_services_.Get(service_path.value(), &service)) { |
215 error_callback.Run("Error.InvalidService", "Invalid Service"); | 216 error_callback.Run("Error.InvalidService", "Invalid Service"); |
216 return; | 217 return; |
217 } | 218 } |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 base::StringValue(shill::kActivationStateActivated), | 600 base::StringValue(shill::kActivationStateActivated), |
600 base::Bind(&base::DoNothing), | 601 base::Bind(&base::DoNothing), |
601 error_callback); | 602 error_callback); |
602 SetProperty(service_path, | 603 SetProperty(service_path, |
603 shill::kConnectableProperty, | 604 shill::kConnectableProperty, |
604 base::FundamentalValue(true), | 605 base::FundamentalValue(true), |
605 base::Bind(&base::DoNothing), | 606 base::Bind(&base::DoNothing), |
606 error_callback); | 607 error_callback); |
607 } | 608 } |
608 | 609 |
609 void FakeShillServiceClient::ContinueConnect( | 610 void FakeShillServiceClient::ContinueConnect(const std::string& service_path) { |
610 const std::string& service_path) { | |
611 VLOG(1) << "FakeShillServiceClient::ContinueConnect: " << service_path; | 611 VLOG(1) << "FakeShillServiceClient::ContinueConnect: " << service_path; |
612 base::DictionaryValue* service_properties = NULL; | 612 base::DictionaryValue* service_properties = NULL; |
613 if (!stub_services_.GetDictionary(service_path, &service_properties)) { | 613 if (!stub_services_.GetDictionary(service_path, &service_properties)) { |
614 LOG(ERROR) << "Service not found: " << service_path; | 614 LOG(ERROR) << "Service not found: " << service_path; |
615 return; | 615 return; |
616 } | 616 } |
617 | 617 |
618 if (ContainsKey(connect_behavior_, service_path)) { | 618 if (ContainsKey(connect_behavior_, service_path)) { |
619 const base::Closure& custom_connect_behavior = | 619 const base::Closure& custom_connect_behavior = |
620 connect_behavior_[service_path]; | 620 connect_behavior_[service_path]; |
621 VLOG(1) << "Running custom connect behavior for " << service_path; | 621 VLOG(1) << "Running custom connect behavior for " << service_path; |
622 custom_connect_behavior.Run(); | 622 custom_connect_behavior.Run(); |
623 return; | 623 return; |
624 } | 624 } |
625 | 625 |
626 // No custom connect behavior set, continue with the default connect behavior. | 626 // No custom connect behavior set, continue with the default connect behavior. |
627 std::string passphrase; | 627 std::string passphrase; |
628 service_properties->GetStringWithoutPathExpansion( | 628 service_properties->GetStringWithoutPathExpansion(shill::kPassphraseProperty, |
629 shill::kPassphraseProperty, &passphrase); | 629 &passphrase); |
630 if (passphrase == "failure") { | 630 if (passphrase == "failure") { |
631 // Simulate a password failure. | 631 // Simulate a password failure. |
632 SetServiceProperty(service_path, | 632 SetServiceProperty(service_path, shill::kErrorProperty, |
633 shill::kStateProperty, | 633 base::StringValue(shill::kErrorBadPassphrase)); |
| 634 SetServiceProperty(service_path, shill::kStateProperty, |
634 base::StringValue(shill::kStateFailure)); | 635 base::StringValue(shill::kStateFailure)); |
635 base::MessageLoop::current()->PostTask( | 636 base::MessageLoop::current()->PostTask( |
636 FROM_HERE, | 637 FROM_HERE, |
637 base::Bind( | 638 base::Bind( |
638 base::IgnoreResult(&FakeShillServiceClient::SetServiceProperty), | 639 base::IgnoreResult(&FakeShillServiceClient::SetServiceProperty), |
639 weak_ptr_factory_.GetWeakPtr(), | 640 weak_ptr_factory_.GetWeakPtr(), service_path, shill::kErrorProperty, |
640 service_path, | |
641 shill::kErrorProperty, | |
642 base::StringValue(shill::kErrorBadPassphrase))); | 641 base::StringValue(shill::kErrorBadPassphrase))); |
643 } else { | 642 } else { |
644 // Set Online. | 643 // Set Online. |
645 VLOG(1) << "Setting state to Online " << service_path; | 644 VLOG(1) << "Setting state to Online " << service_path; |
646 SetServiceProperty(service_path, | 645 SetServiceProperty(service_path, shill::kStateProperty, |
647 shill::kStateProperty, | |
648 base::StringValue(shill::kStateOnline)); | 646 base::StringValue(shill::kStateOnline)); |
649 } | 647 } |
650 } | 648 } |
651 | 649 |
652 } // namespace chromeos | 650 } // namespace chromeos |
OLD | NEW |