| OLD | NEW |
| 1 // Copyright (c) 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/shill_service_client_stub.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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chromeos/chromeos_switches.h" | 14 #include "chromeos/chromeos_switches.h" |
| 15 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 void PassStubServiceProperties( | 39 void PassStubServiceProperties( |
| 40 const ShillServiceClient::DictionaryValueCallback& callback, | 40 const ShillServiceClient::DictionaryValueCallback& callback, |
| 41 DBusMethodCallStatus call_status, | 41 DBusMethodCallStatus call_status, |
| 42 const base::DictionaryValue* properties) { | 42 const base::DictionaryValue* properties) { |
| 43 callback.Run(call_status, *properties); | 43 callback.Run(call_status, *properties); |
| 44 } | 44 } |
| 45 | 45 |
| 46 } // namespace | 46 } // namespace |
| 47 | 47 |
| 48 ShillServiceClientStub::ShillServiceClientStub() : weak_ptr_factory_(this) { | 48 FakeShillServiceClient::FakeShillServiceClient() : weak_ptr_factory_(this) { |
| 49 } | 49 } |
| 50 | 50 |
| 51 ShillServiceClientStub::~ShillServiceClientStub() { | 51 FakeShillServiceClient::~FakeShillServiceClient() { |
| 52 STLDeleteContainerPairSecondPointers( | 52 STLDeleteContainerPairSecondPointers( |
| 53 observer_list_.begin(), observer_list_.end()); | 53 observer_list_.begin(), observer_list_.end()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 | 56 |
| 57 // ShillServiceClient overrides. | 57 // ShillServiceClient overrides. |
| 58 | 58 |
| 59 void ShillServiceClientStub::Init(dbus::Bus* bus) { | 59 void FakeShillServiceClient::Init(dbus::Bus* bus) { |
| 60 } | 60 } |
| 61 | 61 |
| 62 void ShillServiceClientStub::AddPropertyChangedObserver( | 62 void FakeShillServiceClient::AddPropertyChangedObserver( |
| 63 const dbus::ObjectPath& service_path, | 63 const dbus::ObjectPath& service_path, |
| 64 ShillPropertyChangedObserver* observer) { | 64 ShillPropertyChangedObserver* observer) { |
| 65 GetObserverList(service_path).AddObserver(observer); | 65 GetObserverList(service_path).AddObserver(observer); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void ShillServiceClientStub::RemovePropertyChangedObserver( | 68 void FakeShillServiceClient::RemovePropertyChangedObserver( |
| 69 const dbus::ObjectPath& service_path, | 69 const dbus::ObjectPath& service_path, |
| 70 ShillPropertyChangedObserver* observer) { | 70 ShillPropertyChangedObserver* observer) { |
| 71 GetObserverList(service_path).RemoveObserver(observer); | 71 GetObserverList(service_path).RemoveObserver(observer); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void ShillServiceClientStub::GetProperties( | 74 void FakeShillServiceClient::GetProperties( |
| 75 const dbus::ObjectPath& service_path, | 75 const dbus::ObjectPath& service_path, |
| 76 const DictionaryValueCallback& callback) { | 76 const DictionaryValueCallback& callback) { |
| 77 base::DictionaryValue* nested_dict = NULL; | 77 base::DictionaryValue* nested_dict = NULL; |
| 78 scoped_ptr<base::DictionaryValue> result_properties; | 78 scoped_ptr<base::DictionaryValue> result_properties; |
| 79 DBusMethodCallStatus call_status; | 79 DBusMethodCallStatus call_status; |
| 80 stub_services_.GetDictionaryWithoutPathExpansion(service_path.value(), | 80 stub_services_.GetDictionaryWithoutPathExpansion(service_path.value(), |
| 81 &nested_dict); | 81 &nested_dict); |
| 82 if (nested_dict) { | 82 if (nested_dict) { |
| 83 result_properties.reset(nested_dict->DeepCopy()); | 83 result_properties.reset(nested_dict->DeepCopy()); |
| 84 // Remove credentials that Shill wouldn't send. | 84 // Remove credentials that Shill wouldn't send. |
| 85 result_properties->RemoveWithoutPathExpansion(shill::kPassphraseProperty, | 85 result_properties->RemoveWithoutPathExpansion(shill::kPassphraseProperty, |
| 86 NULL); | 86 NULL); |
| 87 call_status = DBUS_METHOD_CALL_SUCCESS; | 87 call_status = DBUS_METHOD_CALL_SUCCESS; |
| 88 } else { | 88 } else { |
| 89 LOG(ERROR) << "Properties not found for: " << service_path.value(); | 89 LOG(ERROR) << "Properties not found for: " << service_path.value(); |
| 90 result_properties.reset(new base::DictionaryValue); | 90 result_properties.reset(new base::DictionaryValue); |
| 91 call_status = DBUS_METHOD_CALL_FAILURE; | 91 call_status = DBUS_METHOD_CALL_FAILURE; |
| 92 } | 92 } |
| 93 | 93 |
| 94 base::MessageLoop::current()->PostTask( | 94 base::MessageLoop::current()->PostTask( |
| 95 FROM_HERE, | 95 FROM_HERE, |
| 96 base::Bind(&PassStubServiceProperties, | 96 base::Bind(&PassStubServiceProperties, |
| 97 callback, | 97 callback, |
| 98 call_status, | 98 call_status, |
| 99 base::Owned(result_properties.release()))); | 99 base::Owned(result_properties.release()))); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void ShillServiceClientStub::SetProperty(const dbus::ObjectPath& service_path, | 102 void FakeShillServiceClient::SetProperty(const dbus::ObjectPath& service_path, |
| 103 const std::string& name, | 103 const std::string& name, |
| 104 const base::Value& value, | 104 const base::Value& value, |
| 105 const base::Closure& callback, | 105 const base::Closure& callback, |
| 106 const ErrorCallback& error_callback) { | 106 const ErrorCallback& error_callback) { |
| 107 if (!SetServiceProperty(service_path.value(), name, value)) { | 107 if (!SetServiceProperty(service_path.value(), name, value)) { |
| 108 LOG(ERROR) << "Service not found: " << service_path.value(); | 108 LOG(ERROR) << "Service not found: " << service_path.value(); |
| 109 error_callback.Run("Error.InvalidService", "Invalid Service"); | 109 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 110 return; | 110 return; |
| 111 } | 111 } |
| 112 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 112 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void ShillServiceClientStub::SetProperties( | 115 void FakeShillServiceClient::SetProperties( |
| 116 const dbus::ObjectPath& service_path, | 116 const dbus::ObjectPath& service_path, |
| 117 const base::DictionaryValue& properties, | 117 const base::DictionaryValue& properties, |
| 118 const base::Closure& callback, | 118 const base::Closure& callback, |
| 119 const ErrorCallback& error_callback) { | 119 const ErrorCallback& error_callback) { |
| 120 for (base::DictionaryValue::Iterator iter(properties); | 120 for (base::DictionaryValue::Iterator iter(properties); |
| 121 !iter.IsAtEnd(); iter.Advance()) { | 121 !iter.IsAtEnd(); iter.Advance()) { |
| 122 if (!SetServiceProperty(service_path.value(), iter.key(), iter.value())) { | 122 if (!SetServiceProperty(service_path.value(), iter.key(), iter.value())) { |
| 123 LOG(ERROR) << "Service not found: " << service_path.value(); | 123 LOG(ERROR) << "Service not found: " << service_path.value(); |
| 124 error_callback.Run("Error.InvalidService", "Invalid Service"); | 124 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 125 return; | 125 return; |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 128 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void ShillServiceClientStub::ClearProperty( | 131 void FakeShillServiceClient::ClearProperty( |
| 132 const dbus::ObjectPath& service_path, | 132 const dbus::ObjectPath& service_path, |
| 133 const std::string& name, | 133 const std::string& name, |
| 134 const base::Closure& callback, | 134 const base::Closure& callback, |
| 135 const ErrorCallback& error_callback) { | 135 const ErrorCallback& error_callback) { |
| 136 base::DictionaryValue* dict = NULL; | 136 base::DictionaryValue* dict = NULL; |
| 137 if (!stub_services_.GetDictionaryWithoutPathExpansion( | 137 if (!stub_services_.GetDictionaryWithoutPathExpansion( |
| 138 service_path.value(), &dict)) { | 138 service_path.value(), &dict)) { |
| 139 error_callback.Run("Error.InvalidService", "Invalid Service"); | 139 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 140 return; | 140 return; |
| 141 } | 141 } |
| 142 dict->RemoveWithoutPathExpansion(name, NULL); | 142 dict->RemoveWithoutPathExpansion(name, NULL); |
| 143 // Note: Shill does not send notifications when properties are cleared. | 143 // Note: Shill does not send notifications when properties are cleared. |
| 144 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 144 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void ShillServiceClientStub::ClearProperties( | 147 void FakeShillServiceClient::ClearProperties( |
| 148 const dbus::ObjectPath& service_path, | 148 const dbus::ObjectPath& service_path, |
| 149 const std::vector<std::string>& names, | 149 const std::vector<std::string>& names, |
| 150 const ListValueCallback& callback, | 150 const ListValueCallback& callback, |
| 151 const ErrorCallback& error_callback) { | 151 const ErrorCallback& error_callback) { |
| 152 base::DictionaryValue* dict = NULL; | 152 base::DictionaryValue* dict = NULL; |
| 153 if (!stub_services_.GetDictionaryWithoutPathExpansion( | 153 if (!stub_services_.GetDictionaryWithoutPathExpansion( |
| 154 service_path.value(), &dict)) { | 154 service_path.value(), &dict)) { |
| 155 error_callback.Run("Error.InvalidService", "Invalid Service"); | 155 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 156 return; | 156 return; |
| 157 } | 157 } |
| 158 scoped_ptr<base::ListValue> results(new base::ListValue); | 158 scoped_ptr<base::ListValue> results(new base::ListValue); |
| 159 for (std::vector<std::string>::const_iterator iter = names.begin(); | 159 for (std::vector<std::string>::const_iterator iter = names.begin(); |
| 160 iter != names.end(); ++iter) { | 160 iter != names.end(); ++iter) { |
| 161 dict->RemoveWithoutPathExpansion(*iter, NULL); | 161 dict->RemoveWithoutPathExpansion(*iter, NULL); |
| 162 // Note: Shill does not send notifications when properties are cleared. | 162 // Note: Shill does not send notifications when properties are cleared. |
| 163 results->AppendBoolean(true); | 163 results->AppendBoolean(true); |
| 164 } | 164 } |
| 165 base::MessageLoop::current()->PostTask( | 165 base::MessageLoop::current()->PostTask( |
| 166 FROM_HERE, | 166 FROM_HERE, |
| 167 base::Bind(&PassStubListValue, | 167 base::Bind(&PassStubListValue, |
| 168 callback, base::Owned(results.release()))); | 168 callback, base::Owned(results.release()))); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void ShillServiceClientStub::Connect(const dbus::ObjectPath& service_path, | 171 void FakeShillServiceClient::Connect(const dbus::ObjectPath& service_path, |
| 172 const base::Closure& callback, | 172 const base::Closure& callback, |
| 173 const ErrorCallback& error_callback) { | 173 const ErrorCallback& error_callback) { |
| 174 VLOG(1) << "ShillServiceClientStub::Connect: " << service_path.value(); | 174 VLOG(1) << "FakeShillServiceClient::Connect: " << service_path.value(); |
| 175 base::DictionaryValue* service_properties = NULL; | 175 base::DictionaryValue* service_properties = NULL; |
| 176 if (!stub_services_.GetDictionary( | 176 if (!stub_services_.GetDictionary( |
| 177 service_path.value(), &service_properties)) { | 177 service_path.value(), &service_properties)) { |
| 178 LOG(ERROR) << "Service not found: " << service_path.value(); | 178 LOG(ERROR) << "Service not found: " << service_path.value(); |
| 179 error_callback.Run("Error.InvalidService", "Invalid Service"); | 179 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 180 return; | 180 return; |
| 181 } | 181 } |
| 182 | 182 |
| 183 // Set any other services of the same Type to 'offline' first, before setting | 183 // Set any other services of the same Type to 'offline' first, before setting |
| 184 // State to Association which will trigger sorting Manager.Services and | 184 // State to Association which will trigger sorting Manager.Services and |
| 185 // sending an update. | 185 // sending an update. |
| 186 SetOtherServicesOffline(service_path.value()); | 186 SetOtherServicesOffline(service_path.value()); |
| 187 | 187 |
| 188 // Set Associating. | 188 // Set Associating. |
| 189 base::StringValue associating_value(shill::kStateAssociation); | 189 base::StringValue associating_value(shill::kStateAssociation); |
| 190 SetServiceProperty(service_path.value(), | 190 SetServiceProperty(service_path.value(), |
| 191 shill::kStateProperty, | 191 shill::kStateProperty, |
| 192 associating_value); | 192 associating_value); |
| 193 | 193 |
| 194 // Stay Associating until the state is changed again after a delay. | 194 // Stay Associating until the state is changed again after a delay. |
| 195 base::TimeDelta delay; | 195 base::TimeDelta delay; |
| 196 if (CommandLine::ForCurrentProcess()->HasSwitch( | 196 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 197 chromeos::switches::kEnableStubInteractive)) { | 197 chromeos::switches::kEnableStubInteractive)) { |
| 198 const int kConnectDelaySeconds = 5; | 198 const int kConnectDelaySeconds = 5; |
| 199 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); | 199 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); |
| 200 } | 200 } |
| 201 base::MessageLoop::current()->PostDelayedTask( | 201 base::MessageLoop::current()->PostDelayedTask( |
| 202 FROM_HERE, | 202 FROM_HERE, |
| 203 base::Bind(&ShillServiceClientStub::ContinueConnect, | 203 base::Bind(&FakeShillServiceClient::ContinueConnect, |
| 204 weak_ptr_factory_.GetWeakPtr(), | 204 weak_ptr_factory_.GetWeakPtr(), |
| 205 service_path.value()), | 205 service_path.value()), |
| 206 delay); | 206 delay); |
| 207 | 207 |
| 208 callback.Run(); | 208 callback.Run(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void ShillServiceClientStub::Disconnect(const dbus::ObjectPath& service_path, | 211 void FakeShillServiceClient::Disconnect(const dbus::ObjectPath& service_path, |
| 212 const base::Closure& callback, | 212 const base::Closure& callback, |
| 213 const ErrorCallback& error_callback) { | 213 const ErrorCallback& error_callback) { |
| 214 base::Value* service; | 214 base::Value* service; |
| 215 if (!stub_services_.Get(service_path.value(), &service)) { | 215 if (!stub_services_.Get(service_path.value(), &service)) { |
| 216 error_callback.Run("Error.InvalidService", "Invalid Service"); | 216 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 217 return; | 217 return; |
| 218 } | 218 } |
| 219 base::TimeDelta delay; | 219 base::TimeDelta delay; |
| 220 if (CommandLine::ForCurrentProcess()->HasSwitch( | 220 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 221 chromeos::switches::kEnableStubInteractive)) { | 221 chromeos::switches::kEnableStubInteractive)) { |
| 222 const int kConnectDelaySeconds = 2; | 222 const int kConnectDelaySeconds = 2; |
| 223 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); | 223 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); |
| 224 } | 224 } |
| 225 // Set Idle after a delay | 225 // Set Idle after a delay |
| 226 base::StringValue idle_value(shill::kStateIdle); | 226 base::StringValue idle_value(shill::kStateIdle); |
| 227 base::MessageLoop::current()->PostDelayedTask( | 227 base::MessageLoop::current()->PostDelayedTask( |
| 228 FROM_HERE, | 228 FROM_HERE, |
| 229 base::Bind(&ShillServiceClientStub::SetProperty, | 229 base::Bind(&FakeShillServiceClient::SetProperty, |
| 230 weak_ptr_factory_.GetWeakPtr(), | 230 weak_ptr_factory_.GetWeakPtr(), |
| 231 service_path, | 231 service_path, |
| 232 shill::kStateProperty, | 232 shill::kStateProperty, |
| 233 idle_value, | 233 idle_value, |
| 234 base::Bind(&base::DoNothing), | 234 base::Bind(&base::DoNothing), |
| 235 error_callback), | 235 error_callback), |
| 236 delay); | 236 delay); |
| 237 callback.Run(); | 237 callback.Run(); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void ShillServiceClientStub::Remove(const dbus::ObjectPath& service_path, | 240 void FakeShillServiceClient::Remove(const dbus::ObjectPath& service_path, |
| 241 const base::Closure& callback, | 241 const base::Closure& callback, |
| 242 const ErrorCallback& error_callback) { | 242 const ErrorCallback& error_callback) { |
| 243 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 243 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 244 } | 244 } |
| 245 | 245 |
| 246 void ShillServiceClientStub::ActivateCellularModem( | 246 void FakeShillServiceClient::ActivateCellularModem( |
| 247 const dbus::ObjectPath& service_path, | 247 const dbus::ObjectPath& service_path, |
| 248 const std::string& carrier, | 248 const std::string& carrier, |
| 249 const base::Closure& callback, | 249 const base::Closure& callback, |
| 250 const ErrorCallback& error_callback) { | 250 const ErrorCallback& error_callback) { |
| 251 base::DictionaryValue* service_properties = | 251 base::DictionaryValue* service_properties = |
| 252 GetModifiableServiceProperties(service_path.value(), false); | 252 GetModifiableServiceProperties(service_path.value(), false); |
| 253 if (!service_properties) { | 253 if (!service_properties) { |
| 254 LOG(ERROR) << "Service not found: " << service_path.value(); | 254 LOG(ERROR) << "Service not found: " << service_path.value(); |
| 255 error_callback.Run("Error.InvalidService", "Invalid Service"); | 255 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 256 } | 256 } |
| 257 SetServiceProperty(service_path.value(), | 257 SetServiceProperty(service_path.value(), |
| 258 shill::kActivationStateProperty, | 258 shill::kActivationStateProperty, |
| 259 base::StringValue(shill::kActivationStateActivating)); | 259 base::StringValue(shill::kActivationStateActivating)); |
| 260 base::TimeDelta delay; | 260 base::TimeDelta delay; |
| 261 if (CommandLine::ForCurrentProcess()->HasSwitch( | 261 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 262 chromeos::switches::kEnableStubInteractive)) { | 262 chromeos::switches::kEnableStubInteractive)) { |
| 263 const int kConnectDelaySeconds = 2; | 263 const int kConnectDelaySeconds = 2; |
| 264 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); | 264 delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); |
| 265 } | 265 } |
| 266 // Set Activated after a delay | 266 // Set Activated after a delay |
| 267 base::MessageLoop::current()->PostDelayedTask( | 267 base::MessageLoop::current()->PostDelayedTask( |
| 268 FROM_HERE, | 268 FROM_HERE, |
| 269 base::Bind(&ShillServiceClientStub::SetCellularActivated, | 269 base::Bind(&FakeShillServiceClient::SetCellularActivated, |
| 270 weak_ptr_factory_.GetWeakPtr(), | 270 weak_ptr_factory_.GetWeakPtr(), |
| 271 service_path, | 271 service_path, |
| 272 error_callback), | 272 error_callback), |
| 273 delay); | 273 delay); |
| 274 | 274 |
| 275 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 275 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 276 } | 276 } |
| 277 | 277 |
| 278 void ShillServiceClientStub::CompleteCellularActivation( | 278 void FakeShillServiceClient::CompleteCellularActivation( |
| 279 const dbus::ObjectPath& service_path, | 279 const dbus::ObjectPath& service_path, |
| 280 const base::Closure& callback, | 280 const base::Closure& callback, |
| 281 const ErrorCallback& error_callback) { | 281 const ErrorCallback& error_callback) { |
| 282 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 282 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 283 } | 283 } |
| 284 | 284 |
| 285 void ShillServiceClientStub::GetLoadableProfileEntries( | 285 void FakeShillServiceClient::GetLoadableProfileEntries( |
| 286 const dbus::ObjectPath& service_path, | 286 const dbus::ObjectPath& service_path, |
| 287 const DictionaryValueCallback& callback) { | 287 const DictionaryValueCallback& callback) { |
| 288 // Provide a dictionary with a single { profile_path, service_path } entry | 288 // Provide a dictionary with a single { profile_path, service_path } entry |
| 289 // if the Profile property is set, or an empty dictionary. | 289 // if the Profile property is set, or an empty dictionary. |
| 290 scoped_ptr<base::DictionaryValue> result_properties( | 290 scoped_ptr<base::DictionaryValue> result_properties( |
| 291 new base::DictionaryValue); | 291 new base::DictionaryValue); |
| 292 base::DictionaryValue* service_properties = | 292 base::DictionaryValue* service_properties = |
| 293 GetModifiableServiceProperties(service_path.value(), false); | 293 GetModifiableServiceProperties(service_path.value(), false); |
| 294 if (service_properties) { | 294 if (service_properties) { |
| 295 std::string profile_path; | 295 std::string profile_path; |
| 296 if (service_properties->GetStringWithoutPathExpansion( | 296 if (service_properties->GetStringWithoutPathExpansion( |
| 297 shill::kProfileProperty, &profile_path)) { | 297 shill::kProfileProperty, &profile_path)) { |
| 298 result_properties->SetStringWithoutPathExpansion( | 298 result_properties->SetStringWithoutPathExpansion( |
| 299 profile_path, service_path.value()); | 299 profile_path, service_path.value()); |
| 300 } | 300 } |
| 301 } else { | 301 } else { |
| 302 LOG(WARNING) << "Service not in profile: " << service_path.value(); | 302 LOG(WARNING) << "Service not in profile: " << service_path.value(); |
| 303 } | 303 } |
| 304 | 304 |
| 305 DBusMethodCallStatus call_status = DBUS_METHOD_CALL_SUCCESS; | 305 DBusMethodCallStatus call_status = DBUS_METHOD_CALL_SUCCESS; |
| 306 base::MessageLoop::current()->PostTask( | 306 base::MessageLoop::current()->PostTask( |
| 307 FROM_HERE, | 307 FROM_HERE, |
| 308 base::Bind(&PassStubServiceProperties, | 308 base::Bind(&PassStubServiceProperties, |
| 309 callback, | 309 callback, |
| 310 call_status, | 310 call_status, |
| 311 base::Owned(result_properties.release()))); | 311 base::Owned(result_properties.release()))); |
| 312 } | 312 } |
| 313 | 313 |
| 314 ShillServiceClient::TestInterface* ShillServiceClientStub::GetTestInterface() { | 314 ShillServiceClient::TestInterface* FakeShillServiceClient::GetTestInterface() { |
| 315 return this; | 315 return this; |
| 316 } | 316 } |
| 317 | 317 |
| 318 // ShillServiceClient::TestInterface overrides. | 318 // ShillServiceClient::TestInterface overrides. |
| 319 | 319 |
| 320 void ShillServiceClientStub::AddService(const std::string& service_path, | 320 void FakeShillServiceClient::AddService(const std::string& service_path, |
| 321 const std::string& name, | 321 const std::string& name, |
| 322 const std::string& type, | 322 const std::string& type, |
| 323 const std::string& state, | 323 const std::string& state, |
| 324 bool add_to_visible_list, | 324 bool add_to_visible_list, |
| 325 bool add_to_watch_list) { | 325 bool add_to_watch_list) { |
| 326 std::string nstate = state; | 326 std::string nstate = state; |
| 327 if (CommandLine::ForCurrentProcess()->HasSwitch( | 327 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 328 chromeos::switches::kDefaultStubNetworkStateIdle)) { | 328 chromeos::switches::kDefaultStubNetworkStateIdle)) { |
| 329 nstate = shill::kStateIdle; | 329 nstate = shill::kStateIdle; |
| 330 } | 330 } |
| 331 AddServiceWithIPConfig(service_path, name, type, nstate, "", | 331 AddServiceWithIPConfig(service_path, name, type, nstate, "", |
| 332 add_to_visible_list, add_to_watch_list); | 332 add_to_visible_list, add_to_watch_list); |
| 333 } | 333 } |
| 334 | 334 |
| 335 void ShillServiceClientStub::AddServiceWithIPConfig( | 335 void FakeShillServiceClient::AddServiceWithIPConfig( |
| 336 const std::string& service_path, | 336 const std::string& service_path, |
| 337 const std::string& name, | 337 const std::string& name, |
| 338 const std::string& type, | 338 const std::string& type, |
| 339 const std::string& state, | 339 const std::string& state, |
| 340 const std::string& ipconfig_path, | 340 const std::string& ipconfig_path, |
| 341 bool add_to_visible_list, | 341 bool add_to_visible_list, |
| 342 bool add_to_watch_list) { | 342 bool add_to_watch_list) { |
| 343 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 343 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 344 AddManagerService(service_path, add_to_visible_list, add_to_watch_list); | 344 AddManagerService(service_path, add_to_visible_list, add_to_watch_list); |
| 345 | 345 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 359 base::Value::CreateStringValue(type)); | 359 base::Value::CreateStringValue(type)); |
| 360 properties->SetWithoutPathExpansion( | 360 properties->SetWithoutPathExpansion( |
| 361 shill::kStateProperty, | 361 shill::kStateProperty, |
| 362 base::Value::CreateStringValue(state)); | 362 base::Value::CreateStringValue(state)); |
| 363 if (!ipconfig_path.empty()) | 363 if (!ipconfig_path.empty()) |
| 364 properties->SetWithoutPathExpansion( | 364 properties->SetWithoutPathExpansion( |
| 365 shill::kIPConfigProperty, | 365 shill::kIPConfigProperty, |
| 366 base::Value::CreateStringValue(ipconfig_path)); | 366 base::Value::CreateStringValue(ipconfig_path)); |
| 367 } | 367 } |
| 368 | 368 |
| 369 void ShillServiceClientStub::RemoveService(const std::string& service_path) { | 369 void FakeShillServiceClient::RemoveService(const std::string& service_path) { |
| 370 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 370 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 371 RemoveManagerService(service_path); | 371 RemoveManagerService(service_path); |
| 372 | 372 |
| 373 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); | 373 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); |
| 374 connect_behavior_.erase(service_path); | 374 connect_behavior_.erase(service_path); |
| 375 } | 375 } |
| 376 | 376 |
| 377 bool ShillServiceClientStub::SetServiceProperty(const std::string& service_path, | 377 bool FakeShillServiceClient::SetServiceProperty(const std::string& service_path, |
| 378 const std::string& property, | 378 const std::string& property, |
| 379 const base::Value& value) { | 379 const base::Value& value) { |
| 380 base::DictionaryValue* dict = NULL; | 380 base::DictionaryValue* dict = NULL; |
| 381 if (!stub_services_.GetDictionaryWithoutPathExpansion(service_path, &dict)) | 381 if (!stub_services_.GetDictionaryWithoutPathExpansion(service_path, &dict)) |
| 382 return false; | 382 return false; |
| 383 | 383 |
| 384 VLOG(1) << "Service.SetProperty: " << property << " = " << value | 384 VLOG(1) << "Service.SetProperty: " << property << " = " << value |
| 385 << " For: " << service_path; | 385 << " For: " << service_path; |
| 386 | 386 |
| 387 base::DictionaryValue new_properties; | 387 base::DictionaryValue new_properties; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 404 dict->MergeDictionary(&new_properties); | 404 dict->MergeDictionary(&new_properties); |
| 405 | 405 |
| 406 if (property == shill::kStateProperty) { | 406 if (property == shill::kStateProperty) { |
| 407 // When State changes the sort order of Services may change. | 407 // When State changes the sort order of Services may change. |
| 408 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 408 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 409 SortManagerServices(); | 409 SortManagerServices(); |
| 410 } | 410 } |
| 411 | 411 |
| 412 base::MessageLoop::current()->PostTask( | 412 base::MessageLoop::current()->PostTask( |
| 413 FROM_HERE, | 413 FROM_HERE, |
| 414 base::Bind(&ShillServiceClientStub::NotifyObserversPropertyChanged, | 414 base::Bind(&FakeShillServiceClient::NotifyObserversPropertyChanged, |
| 415 weak_ptr_factory_.GetWeakPtr(), | 415 weak_ptr_factory_.GetWeakPtr(), |
| 416 dbus::ObjectPath(service_path), changed_property)); | 416 dbus::ObjectPath(service_path), changed_property)); |
| 417 return true; | 417 return true; |
| 418 } | 418 } |
| 419 | 419 |
| 420 const base::DictionaryValue* ShillServiceClientStub::GetServiceProperties( | 420 const base::DictionaryValue* FakeShillServiceClient::GetServiceProperties( |
| 421 const std::string& service_path) const { | 421 const std::string& service_path) const { |
| 422 const base::DictionaryValue* properties = NULL; | 422 const base::DictionaryValue* properties = NULL; |
| 423 stub_services_.GetDictionaryWithoutPathExpansion(service_path, &properties); | 423 stub_services_.GetDictionaryWithoutPathExpansion(service_path, &properties); |
| 424 return properties; | 424 return properties; |
| 425 } | 425 } |
| 426 | 426 |
| 427 void ShillServiceClientStub::ClearServices() { | 427 void FakeShillServiceClient::ClearServices() { |
| 428 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 428 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 429 ClearManagerServices(); | 429 ClearManagerServices(); |
| 430 | 430 |
| 431 stub_services_.Clear(); | 431 stub_services_.Clear(); |
| 432 connect_behavior_.clear(); | 432 connect_behavior_.clear(); |
| 433 } | 433 } |
| 434 | 434 |
| 435 void ShillServiceClientStub::SetConnectBehavior(const std::string& service_path, | 435 void FakeShillServiceClient::SetConnectBehavior(const std::string& service_path, |
| 436 const base::Closure& behavior) { | 436 const base::Closure& behavior) { |
| 437 connect_behavior_[service_path] = behavior; | 437 connect_behavior_[service_path] = behavior; |
| 438 } | 438 } |
| 439 | 439 |
| 440 void ShillServiceClientStub::NotifyObserversPropertyChanged( | 440 void FakeShillServiceClient::NotifyObserversPropertyChanged( |
| 441 const dbus::ObjectPath& service_path, | 441 const dbus::ObjectPath& service_path, |
| 442 const std::string& property) { | 442 const std::string& property) { |
| 443 base::DictionaryValue* dict = NULL; | 443 base::DictionaryValue* dict = NULL; |
| 444 std::string path = service_path.value(); | 444 std::string path = service_path.value(); |
| 445 if (!stub_services_.GetDictionaryWithoutPathExpansion(path, &dict)) { | 445 if (!stub_services_.GetDictionaryWithoutPathExpansion(path, &dict)) { |
| 446 LOG(ERROR) << "Notify for unknown service: " << path; | 446 LOG(ERROR) << "Notify for unknown service: " << path; |
| 447 return; | 447 return; |
| 448 } | 448 } |
| 449 base::Value* value = NULL; | 449 base::Value* value = NULL; |
| 450 if (!dict->GetWithoutPathExpansion(property, &value)) { | 450 if (!dict->GetWithoutPathExpansion(property, &value)) { |
| 451 LOG(ERROR) << "Notify for unknown property: " | 451 LOG(ERROR) << "Notify for unknown property: " |
| 452 << path << " : " << property; | 452 << path << " : " << property; |
| 453 return; | 453 return; |
| 454 } | 454 } |
| 455 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, | 455 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, |
| 456 GetObserverList(service_path), | 456 GetObserverList(service_path), |
| 457 OnPropertyChanged(property, *value)); | 457 OnPropertyChanged(property, *value)); |
| 458 } | 458 } |
| 459 | 459 |
| 460 base::DictionaryValue* ShillServiceClientStub::GetModifiableServiceProperties( | 460 base::DictionaryValue* FakeShillServiceClient::GetModifiableServiceProperties( |
| 461 const std::string& service_path, bool create_if_missing) { | 461 const std::string& service_path, bool create_if_missing) { |
| 462 base::DictionaryValue* properties = NULL; | 462 base::DictionaryValue* properties = NULL; |
| 463 if (!stub_services_.GetDictionaryWithoutPathExpansion(service_path, | 463 if (!stub_services_.GetDictionaryWithoutPathExpansion(service_path, |
| 464 &properties) && | 464 &properties) && |
| 465 create_if_missing) { | 465 create_if_missing) { |
| 466 properties = new base::DictionaryValue; | 466 properties = new base::DictionaryValue; |
| 467 stub_services_.Set(service_path, properties); | 467 stub_services_.Set(service_path, properties); |
| 468 } | 468 } |
| 469 return properties; | 469 return properties; |
| 470 } | 470 } |
| 471 | 471 |
| 472 ShillServiceClientStub::PropertyObserverList& | 472 FakeShillServiceClient::PropertyObserverList& |
| 473 ShillServiceClientStub::GetObserverList(const dbus::ObjectPath& device_path) { | 473 FakeShillServiceClient::GetObserverList(const dbus::ObjectPath& device_path) { |
| 474 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = | 474 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = |
| 475 observer_list_.find(device_path); | 475 observer_list_.find(device_path); |
| 476 if (iter != observer_list_.end()) | 476 if (iter != observer_list_.end()) |
| 477 return *(iter->second); | 477 return *(iter->second); |
| 478 PropertyObserverList* observer_list = new PropertyObserverList(); | 478 PropertyObserverList* observer_list = new PropertyObserverList(); |
| 479 observer_list_[device_path] = observer_list; | 479 observer_list_[device_path] = observer_list; |
| 480 return *observer_list; | 480 return *observer_list; |
| 481 } | 481 } |
| 482 | 482 |
| 483 void ShillServiceClientStub::SetOtherServicesOffline( | 483 void FakeShillServiceClient::SetOtherServicesOffline( |
| 484 const std::string& service_path) { | 484 const std::string& service_path) { |
| 485 const base::DictionaryValue* service_properties = GetServiceProperties( | 485 const base::DictionaryValue* service_properties = GetServiceProperties( |
| 486 service_path); | 486 service_path); |
| 487 if (!service_properties) { | 487 if (!service_properties) { |
| 488 LOG(ERROR) << "Missing service: " << service_path; | 488 LOG(ERROR) << "Missing service: " << service_path; |
| 489 return; | 489 return; |
| 490 } | 490 } |
| 491 std::string service_type; | 491 std::string service_type; |
| 492 service_properties->GetString(shill::kTypeProperty, &service_type); | 492 service_properties->GetString(shill::kTypeProperty, &service_type); |
| 493 // Set all other services of the same type to offline (Idle). | 493 // Set all other services of the same type to offline (Idle). |
| 494 for (base::DictionaryValue::Iterator iter(stub_services_); | 494 for (base::DictionaryValue::Iterator iter(stub_services_); |
| 495 !iter.IsAtEnd(); iter.Advance()) { | 495 !iter.IsAtEnd(); iter.Advance()) { |
| 496 std::string path = iter.key(); | 496 std::string path = iter.key(); |
| 497 if (path == service_path) | 497 if (path == service_path) |
| 498 continue; | 498 continue; |
| 499 base::DictionaryValue* properties; | 499 base::DictionaryValue* properties; |
| 500 if (!stub_services_.GetDictionaryWithoutPathExpansion(path, &properties)) | 500 if (!stub_services_.GetDictionaryWithoutPathExpansion(path, &properties)) |
| 501 NOTREACHED(); | 501 NOTREACHED(); |
| 502 | 502 |
| 503 std::string type; | 503 std::string type; |
| 504 properties->GetString(shill::kTypeProperty, &type); | 504 properties->GetString(shill::kTypeProperty, &type); |
| 505 if (type != service_type) | 505 if (type != service_type) |
| 506 continue; | 506 continue; |
| 507 properties->SetWithoutPathExpansion( | 507 properties->SetWithoutPathExpansion( |
| 508 shill::kStateProperty, | 508 shill::kStateProperty, |
| 509 base::Value::CreateStringValue(shill::kStateIdle)); | 509 base::Value::CreateStringValue(shill::kStateIdle)); |
| 510 } | 510 } |
| 511 } | 511 } |
| 512 | 512 |
| 513 void ShillServiceClientStub::SetCellularActivated( | 513 void FakeShillServiceClient::SetCellularActivated( |
| 514 const dbus::ObjectPath& service_path, | 514 const dbus::ObjectPath& service_path, |
| 515 const ErrorCallback& error_callback) { | 515 const ErrorCallback& error_callback) { |
| 516 SetProperty(service_path, | 516 SetProperty(service_path, |
| 517 shill::kActivationStateProperty, | 517 shill::kActivationStateProperty, |
| 518 base::StringValue(shill::kActivationStateActivated), | 518 base::StringValue(shill::kActivationStateActivated), |
| 519 base::Bind(&base::DoNothing), | 519 base::Bind(&base::DoNothing), |
| 520 error_callback); | 520 error_callback); |
| 521 SetProperty(service_path, | 521 SetProperty(service_path, |
| 522 shill::kConnectableProperty, | 522 shill::kConnectableProperty, |
| 523 base::FundamentalValue(true), | 523 base::FundamentalValue(true), |
| 524 base::Bind(&base::DoNothing), | 524 base::Bind(&base::DoNothing), |
| 525 error_callback); | 525 error_callback); |
| 526 } | 526 } |
| 527 | 527 |
| 528 void ShillServiceClientStub::ContinueConnect( | 528 void FakeShillServiceClient::ContinueConnect( |
| 529 const std::string& service_path) { | 529 const std::string& service_path) { |
| 530 VLOG(1) << "ShillServiceClientStub::ContinueConnect: " << service_path; | 530 VLOG(1) << "FakeShillServiceClient::ContinueConnect: " << service_path; |
| 531 base::DictionaryValue* service_properties = NULL; | 531 base::DictionaryValue* service_properties = NULL; |
| 532 if (!stub_services_.GetDictionary(service_path, &service_properties)) { | 532 if (!stub_services_.GetDictionary(service_path, &service_properties)) { |
| 533 LOG(ERROR) << "Service not found: " << service_path; | 533 LOG(ERROR) << "Service not found: " << service_path; |
| 534 return; | 534 return; |
| 535 } | 535 } |
| 536 | 536 |
| 537 if (ContainsKey(connect_behavior_, service_path)) { | 537 if (ContainsKey(connect_behavior_, service_path)) { |
| 538 const base::Closure& custom_connect_behavior = | 538 const base::Closure& custom_connect_behavior = |
| 539 connect_behavior_[service_path]; | 539 connect_behavior_[service_path]; |
| 540 custom_connect_behavior.Run(); | 540 custom_connect_behavior.Run(); |
| 541 return; | 541 return; |
| 542 } | 542 } |
| 543 | 543 |
| 544 // No custom connect behavior set, continue with the default connect behavior. | 544 // No custom connect behavior set, continue with the default connect behavior. |
| 545 std::string passphrase; | 545 std::string passphrase; |
| 546 service_properties->GetStringWithoutPathExpansion( | 546 service_properties->GetStringWithoutPathExpansion( |
| 547 shill::kPassphraseProperty, &passphrase); | 547 shill::kPassphraseProperty, &passphrase); |
| 548 if (passphrase == "failure") { | 548 if (passphrase == "failure") { |
| 549 // Simulate a password failure. | 549 // Simulate a password failure. |
| 550 SetServiceProperty(service_path, | 550 SetServiceProperty(service_path, |
| 551 shill::kStateProperty, | 551 shill::kStateProperty, |
| 552 base::StringValue(shill::kStateFailure)); | 552 base::StringValue(shill::kStateFailure)); |
| 553 base::MessageLoop::current()->PostTask( | 553 base::MessageLoop::current()->PostTask( |
| 554 FROM_HERE, | 554 FROM_HERE, |
| 555 base::Bind( | 555 base::Bind( |
| 556 base::IgnoreResult(&ShillServiceClientStub::SetServiceProperty), | 556 base::IgnoreResult(&FakeShillServiceClient::SetServiceProperty), |
| 557 weak_ptr_factory_.GetWeakPtr(), | 557 weak_ptr_factory_.GetWeakPtr(), |
| 558 service_path, | 558 service_path, |
| 559 shill::kErrorProperty, | 559 shill::kErrorProperty, |
| 560 base::StringValue(shill::kErrorBadPassphrase))); | 560 base::StringValue(shill::kErrorBadPassphrase))); |
| 561 } else { | 561 } else { |
| 562 // Set Online. | 562 // Set Online. |
| 563 SetServiceProperty(service_path, | 563 SetServiceProperty(service_path, |
| 564 shill::kStateProperty, | 564 shill::kStateProperty, |
| 565 base::StringValue(shill::kStateOnline)); | 565 base::StringValue(shill::kStateOnline)); |
| 566 } | 566 } |
| 567 } | 567 } |
| 568 | 568 |
| 569 } // namespace chromeos | 569 } // namespace chromeos |
| OLD | NEW |