| 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_service_client_stub.h" | 5 #include "chromeos/dbus/shill_service_client_stub.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 base::MessageLoop::current()->PostTask( | 158 base::MessageLoop::current()->PostTask( |
| 159 FROM_HERE, | 159 FROM_HERE, |
| 160 base::Bind(&PassStubListValue, | 160 base::Bind(&PassStubListValue, |
| 161 callback, base::Owned(results.release()))); | 161 callback, base::Owned(results.release()))); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void ShillServiceClientStub::Connect(const dbus::ObjectPath& service_path, | 164 void ShillServiceClientStub::Connect(const dbus::ObjectPath& service_path, |
| 165 const base::Closure& callback, | 165 const base::Closure& callback, |
| 166 const ErrorCallback& error_callback) { | 166 const ErrorCallback& error_callback) { |
| 167 VLOG(1) << "ShillServiceClientStub::Connect: " << service_path.value(); | 167 VLOG(1) << "ShillServiceClientStub::Connect: " << service_path.value(); |
| 168 base::Value* service; | 168 base::DictionaryValue* service_properties; |
| 169 if (!stub_services_.Get(service_path.value(), &service)) { | 169 if (!stub_services_.GetDictionary( |
| 170 service_path.value(), &service_properties)) { |
| 170 LOG(ERROR) << "Service not found: " << service_path.value(); | 171 LOG(ERROR) << "Service not found: " << service_path.value(); |
| 171 error_callback.Run("Error.InvalidService", "Invalid Service"); | 172 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 172 return; | 173 return; |
| 173 } | 174 } |
| 174 | 175 |
| 175 // Set any other services of the same Type to 'offline' first, before setting | 176 // Set any other services of the same Type to 'offline' first, before setting |
| 176 // State to Association which will trigger sorting Manager.Services and | 177 // State to Association which will trigger sorting Manager.Services and |
| 177 // sending an update. | 178 // sending an update. |
| 178 SetOtherServicesOffline(service_path.value()); | 179 SetOtherServicesOffline(service_path.value()); |
| 179 | 180 |
| 180 // Set Associating. | 181 // Set Associating. |
| 181 base::StringValue associating_value(flimflam::kStateAssociation); | 182 base::StringValue associating_value(flimflam::kStateAssociation); |
| 182 SetServiceProperty(service_path.value(), | 183 SetServiceProperty(service_path.value(), |
| 183 flimflam::kStateProperty, | 184 flimflam::kStateProperty, |
| 184 associating_value); | 185 associating_value); |
| 185 | 186 |
| 186 // Set Online after a delay. | 187 // Set Online after a delay. |
| 187 base::TimeDelta delay; | 188 base::TimeDelta delay; |
| 188 if (CommandLine::ForCurrentProcess()->HasSwitch( | 189 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 189 chromeos::switches::kEnableStubInteractive)) { | 190 chromeos::switches::kEnableStubInteractive)) { |
| 190 const int kConnectDelaySeconds = 5; | 191 const int kConnectDelaySeconds = 5; |
| 191 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); | 192 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); |
| 192 } | 193 } |
| 193 base::StringValue online_value(flimflam::kStateOnline); | 194 base::StringValue online_value(flimflam::kStateOnline); |
| 195 std::string passphrase; |
| 196 service_properties->GetStringWithoutPathExpansion( |
| 197 flimflam::kPassphraseProperty, &passphrase); |
| 198 if (passphrase == "failure") |
| 199 online_value = base::StringValue(flimflam::kStateFailure); |
| 194 base::MessageLoop::current()->PostDelayedTask( | 200 base::MessageLoop::current()->PostDelayedTask( |
| 195 FROM_HERE, | 201 FROM_HERE, |
| 196 base::Bind(&ShillServiceClientStub::SetProperty, | 202 base::Bind(&ShillServiceClientStub::SetProperty, |
| 197 weak_ptr_factory_.GetWeakPtr(), | 203 weak_ptr_factory_.GetWeakPtr(), |
| 198 service_path, | 204 service_path, |
| 199 flimflam::kStateProperty, | 205 flimflam::kStateProperty, |
| 200 online_value, | 206 online_value, |
| 201 base::Bind(&base::DoNothing), | 207 base::Bind(&base::DoNothing), |
| 202 error_callback), | 208 error_callback), |
| 203 delay); | 209 delay); |
| 204 callback.Run(); | 210 callback.Run(); |
| 211 // On failure, also set the Error property. |
| 212 if (passphrase == "failure") { |
| 213 base::MessageLoop::current()->PostDelayedTask( |
| 214 FROM_HERE, |
| 215 base::Bind(&ShillServiceClientStub::SetProperty, |
| 216 weak_ptr_factory_.GetWeakPtr(), |
| 217 service_path, |
| 218 flimflam::kErrorProperty, |
| 219 base::StringValue(flimflam::kErrorBadPassphrase), |
| 220 base::Bind(&base::DoNothing), |
| 221 error_callback), |
| 222 delay); |
| 223 } |
| 205 } | 224 } |
| 206 | 225 |
| 207 void ShillServiceClientStub::Disconnect(const dbus::ObjectPath& service_path, | 226 void ShillServiceClientStub::Disconnect(const dbus::ObjectPath& service_path, |
| 208 const base::Closure& callback, | 227 const base::Closure& callback, |
| 209 const ErrorCallback& error_callback) { | 228 const ErrorCallback& error_callback) { |
| 210 base::Value* service; | 229 base::Value* service; |
| 211 if (!stub_services_.Get(service_path.value(), &service)) { | 230 if (!stub_services_.Get(service_path.value(), &service)) { |
| 212 error_callback.Run("Error.InvalidService", "Invalid Service"); | 231 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 213 return; | 232 return; |
| 214 } | 233 } |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 properties->GetString(flimflam::kTypeProperty, &type); | 581 properties->GetString(flimflam::kTypeProperty, &type); |
| 563 if (type != service_type) | 582 if (type != service_type) |
| 564 continue; | 583 continue; |
| 565 properties->SetWithoutPathExpansion( | 584 properties->SetWithoutPathExpansion( |
| 566 flimflam::kStateProperty, | 585 flimflam::kStateProperty, |
| 567 base::Value::CreateStringValue(flimflam::kStateIdle)); | 586 base::Value::CreateStringValue(flimflam::kStateIdle)); |
| 568 } | 587 } |
| 569 } | 588 } |
| 570 | 589 |
| 571 } // namespace chromeos | 590 } // namespace chromeos |
| OLD | NEW |