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(service_path.value(), | 181 if (!stub_services_.GetDictionary( |
182 &service_properties)) { | 182 service_path.value(), &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 | |
196 // Set Associating. | 193 // Set Associating. |
197 base::StringValue associating_value(shill::kStateAssociation); | 194 base::StringValue associating_value(shill::kStateAssociation); |
198 SetServiceProperty(service_path.value(), shill::kStateProperty, | 195 SetServiceProperty(service_path.value(), |
| 196 shill::kStateProperty, |
199 associating_value); | 197 associating_value); |
200 | 198 |
201 // Stay Associating until the state is changed again after a delay. | 199 // Stay Associating until the state is changed again after a delay. |
202 base::MessageLoop::current()->PostDelayedTask( | 200 base::MessageLoop::current()->PostDelayedTask( |
203 FROM_HERE, | 201 FROM_HERE, |
204 base::Bind(&FakeShillServiceClient::ContinueConnect, | 202 base::Bind(&FakeShillServiceClient::ContinueConnect, |
205 weak_ptr_factory_.GetWeakPtr(), service_path.value()), | 203 weak_ptr_factory_.GetWeakPtr(), |
| 204 service_path.value()), |
206 base::TimeDelta::FromSeconds(GetInteractiveDelay())); | 205 base::TimeDelta::FromSeconds(GetInteractiveDelay())); |
207 | 206 |
208 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 207 callback.Run(); |
209 } | 208 } |
210 | 209 |
211 void FakeShillServiceClient::Disconnect(const dbus::ObjectPath& service_path, | 210 void FakeShillServiceClient::Disconnect(const dbus::ObjectPath& service_path, |
212 const base::Closure& callback, | 211 const base::Closure& callback, |
213 const ErrorCallback& error_callback) { | 212 const ErrorCallback& error_callback) { |
214 base::Value* service; | 213 base::Value* service; |
215 if (!stub_services_.Get(service_path.value(), &service)) { | 214 if (!stub_services_.Get(service_path.value(), &service)) { |
216 error_callback.Run("Error.InvalidService", "Invalid Service"); | 215 error_callback.Run("Error.InvalidService", "Invalid Service"); |
217 return; | 216 return; |
218 } | 217 } |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 base::StringValue(shill::kActivationStateActivated), | 599 base::StringValue(shill::kActivationStateActivated), |
601 base::Bind(&base::DoNothing), | 600 base::Bind(&base::DoNothing), |
602 error_callback); | 601 error_callback); |
603 SetProperty(service_path, | 602 SetProperty(service_path, |
604 shill::kConnectableProperty, | 603 shill::kConnectableProperty, |
605 base::FundamentalValue(true), | 604 base::FundamentalValue(true), |
606 base::Bind(&base::DoNothing), | 605 base::Bind(&base::DoNothing), |
607 error_callback); | 606 error_callback); |
608 } | 607 } |
609 | 608 |
610 void FakeShillServiceClient::ContinueConnect(const std::string& service_path) { | 609 void FakeShillServiceClient::ContinueConnect( |
| 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(shill::kPassphraseProperty, | 628 service_properties->GetStringWithoutPathExpansion( |
629 &passphrase); | 629 shill::kPassphraseProperty, &passphrase); |
630 if (passphrase == "failure") { | 630 if (passphrase == "failure") { |
631 // Simulate a password failure. | 631 // Simulate a password failure. |
632 SetServiceProperty(service_path, shill::kErrorProperty, | 632 SetServiceProperty(service_path, |
633 base::StringValue(shill::kErrorBadPassphrase)); | 633 shill::kStateProperty, |
634 SetServiceProperty(service_path, shill::kStateProperty, | |
635 base::StringValue(shill::kStateFailure)); | 634 base::StringValue(shill::kStateFailure)); |
636 base::MessageLoop::current()->PostTask( | 635 base::MessageLoop::current()->PostTask( |
637 FROM_HERE, | 636 FROM_HERE, |
638 base::Bind( | 637 base::Bind( |
639 base::IgnoreResult(&FakeShillServiceClient::SetServiceProperty), | 638 base::IgnoreResult(&FakeShillServiceClient::SetServiceProperty), |
640 weak_ptr_factory_.GetWeakPtr(), service_path, shill::kErrorProperty, | 639 weak_ptr_factory_.GetWeakPtr(), |
| 640 service_path, |
| 641 shill::kErrorProperty, |
641 base::StringValue(shill::kErrorBadPassphrase))); | 642 base::StringValue(shill::kErrorBadPassphrase))); |
642 } else { | 643 } else { |
643 // Set Online. | 644 // Set Online. |
644 VLOG(1) << "Setting state to Online " << service_path; | 645 VLOG(1) << "Setting state to Online " << service_path; |
645 SetServiceProperty(service_path, shill::kStateProperty, | 646 SetServiceProperty(service_path, |
| 647 shill::kStateProperty, |
646 base::StringValue(shill::kStateOnline)); | 648 base::StringValue(shill::kStateOnline)); |
647 } | 649 } |
648 } | 650 } |
649 | 651 |
650 } // namespace chromeos | 652 } // namespace chromeos |
OLD | NEW |