| 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_device_client.h" | 5 #include "chromeos/dbus/fake_shill_device_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chromeos/dbus/dbus_thread_manager.h" | 11 #include "chromeos/dbus/dbus_thread_manager.h" |
| 12 #include "chromeos/dbus/shill_manager_client.h" | 12 #include "chromeos/dbus/shill_manager_client.h" |
| 13 #include "chromeos/dbus/shill_property_changed_observer.h" | 13 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 14 #include "dbus/bus.h" | 14 #include "dbus/bus.h" |
| 15 #include "dbus/message.h" | 15 #include "dbus/message.h" |
| 16 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
| 17 #include "dbus/object_proxy.h" | 17 #include "dbus/object_proxy.h" |
| 18 #include "dbus/values_util.h" | 18 #include "dbus/values_util.h" |
| 19 #include "net/base/ip_endpoint.h" |
| 19 #include "third_party/cros_system_api/dbus/service_constants.h" | 20 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 20 | 21 |
| 21 namespace chromeos { | 22 namespace chromeos { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 std::string kSimPin = "1111"; | 26 std::string kSimPin = "1111"; |
| 26 | 27 |
| 27 void ErrorFunction(const std::string& device_path, | 28 void ErrorFunction(const std::string& device_path, |
| 28 const std::string& error_name, | 29 const std::string& error_name, |
| 29 const std::string& error_message) { | 30 const std::string& error_message) { |
| 30 LOG(ERROR) << "Shill Error for: " << device_path | 31 LOG(ERROR) << "Shill Error for: " << device_path |
| 31 << ": " << error_name << " : " << error_message; | 32 << ": " << error_name << " : " << error_message; |
| 32 } | 33 } |
| 33 | 34 |
| 34 void PostDeviceNotFoundError( | 35 void PostNotFoundError( |
| 35 const ShillDeviceClient::ErrorCallback& error_callback) { | 36 const ShillDeviceClient::ErrorCallback& error_callback) { |
| 36 std::string error_message("Failed"); | 37 std::string error_message("Failed"); |
| 37 base::MessageLoop::current()->PostTask( | 38 base::MessageLoop::current()->PostTask( |
| 38 FROM_HERE, | 39 FROM_HERE, |
| 39 base::Bind(error_callback, shill::kErrorResultNotFound, error_message)); | 40 base::Bind(error_callback, shill::kErrorResultNotFound, error_message)); |
| 40 } | 41 } |
| 41 | 42 |
| 42 } // namespace | 43 } // namespace |
| 43 | 44 |
| 44 FakeShillDeviceClient::FakeShillDeviceClient() | 45 FakeShillDeviceClient::FakeShillDeviceClient() |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 85 } |
| 85 | 86 |
| 86 void FakeShillDeviceClient::SetProperty(const dbus::ObjectPath& device_path, | 87 void FakeShillDeviceClient::SetProperty(const dbus::ObjectPath& device_path, |
| 87 const std::string& name, | 88 const std::string& name, |
| 88 const base::Value& value, | 89 const base::Value& value, |
| 89 const base::Closure& callback, | 90 const base::Closure& callback, |
| 90 const ErrorCallback& error_callback) { | 91 const ErrorCallback& error_callback) { |
| 91 base::DictionaryValue* device_properties = NULL; | 92 base::DictionaryValue* device_properties = NULL; |
| 92 if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path.value(), | 93 if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path.value(), |
| 93 &device_properties)) { | 94 &device_properties)) { |
| 94 PostDeviceNotFoundError(error_callback); | 95 PostNotFoundError(error_callback); |
| 95 return; | 96 return; |
| 96 } | 97 } |
| 97 device_properties->SetWithoutPathExpansion(name, value.DeepCopy()); | 98 device_properties->SetWithoutPathExpansion(name, value.DeepCopy()); |
| 98 base::MessageLoop::current()->PostTask( | 99 base::MessageLoop::current()->PostTask( |
| 99 FROM_HERE, | 100 FROM_HERE, |
| 100 base::Bind(&FakeShillDeviceClient::NotifyObserversPropertyChanged, | 101 base::Bind(&FakeShillDeviceClient::NotifyObserversPropertyChanged, |
| 101 weak_ptr_factory_.GetWeakPtr(), device_path, name)); | 102 weak_ptr_factory_.GetWeakPtr(), device_path, name)); |
| 102 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 103 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 103 } | 104 } |
| 104 | 105 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 134 VLOG(1) << "RequirePin: " << device_path.value(); | 135 VLOG(1) << "RequirePin: " << device_path.value(); |
| 135 if (pin != kSimPin) { | 136 if (pin != kSimPin) { |
| 136 base::MessageLoop::current()->PostTask( | 137 base::MessageLoop::current()->PostTask( |
| 137 FROM_HERE, | 138 FROM_HERE, |
| 138 base::Bind(error_callback, shill::kErrorResultIncorrectPin, "")); | 139 base::Bind(error_callback, shill::kErrorResultIncorrectPin, "")); |
| 139 return; | 140 return; |
| 140 } | 141 } |
| 141 base::DictionaryValue* device_properties = NULL; | 142 base::DictionaryValue* device_properties = NULL; |
| 142 if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path.value(), | 143 if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path.value(), |
| 143 &device_properties)) { | 144 &device_properties)) { |
| 144 PostDeviceNotFoundError(error_callback); | 145 PostNotFoundError(error_callback); |
| 145 return; | 146 return; |
| 146 } | 147 } |
| 147 base::DictionaryValue* simlock_dict = NULL; | 148 base::DictionaryValue* simlock_dict = NULL; |
| 148 if (!device_properties->GetDictionaryWithoutPathExpansion( | 149 if (!device_properties->GetDictionaryWithoutPathExpansion( |
| 149 shill::kSIMLockStatusProperty, &simlock_dict)) { | 150 shill::kSIMLockStatusProperty, &simlock_dict)) { |
| 150 simlock_dict = new base::DictionaryValue; | 151 simlock_dict = new base::DictionaryValue; |
| 151 device_properties->SetWithoutPathExpansion( | 152 device_properties->SetWithoutPathExpansion( |
| 152 shill::kSIMLockStatusProperty, simlock_dict); | 153 shill::kSIMLockStatusProperty, simlock_dict); |
| 153 } | 154 } |
| 154 simlock_dict->Clear(); | 155 simlock_dict->Clear(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 167 const base::Closure& callback, | 168 const base::Closure& callback, |
| 168 const ErrorCallback& error_callback) { | 169 const ErrorCallback& error_callback) { |
| 169 VLOG(1) << "EnterPin: " << device_path.value(); | 170 VLOG(1) << "EnterPin: " << device_path.value(); |
| 170 if (pin != kSimPin) { | 171 if (pin != kSimPin) { |
| 171 base::MessageLoop::current()->PostTask( | 172 base::MessageLoop::current()->PostTask( |
| 172 FROM_HERE, | 173 FROM_HERE, |
| 173 base::Bind(error_callback, shill::kErrorResultIncorrectPin, "")); | 174 base::Bind(error_callback, shill::kErrorResultIncorrectPin, "")); |
| 174 return; | 175 return; |
| 175 } | 176 } |
| 176 if (!stub_devices_.HasKey(device_path.value())) { | 177 if (!stub_devices_.HasKey(device_path.value())) { |
| 177 PostDeviceNotFoundError(error_callback); | 178 PostNotFoundError(error_callback); |
| 178 return; | 179 return; |
| 179 } | 180 } |
| 180 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 181 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 181 } | 182 } |
| 182 | 183 |
| 183 void FakeShillDeviceClient::UnblockPin(const dbus::ObjectPath& device_path, | 184 void FakeShillDeviceClient::UnblockPin(const dbus::ObjectPath& device_path, |
| 184 const std::string& puk, | 185 const std::string& puk, |
| 185 const std::string& pin, | 186 const std::string& pin, |
| 186 const base::Closure& callback, | 187 const base::Closure& callback, |
| 187 const ErrorCallback& error_callback) { | 188 const ErrorCallback& error_callback) { |
| 188 VLOG(1) << "UnblockPin: " << device_path.value(); | 189 VLOG(1) << "UnblockPin: " << device_path.value(); |
| 189 if (!stub_devices_.HasKey(device_path.value())) { | 190 if (!stub_devices_.HasKey(device_path.value())) { |
| 190 PostDeviceNotFoundError(error_callback); | 191 PostNotFoundError(error_callback); |
| 191 return; | 192 return; |
| 192 } | 193 } |
| 193 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 194 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 194 } | 195 } |
| 195 | 196 |
| 196 void FakeShillDeviceClient::ChangePin(const dbus::ObjectPath& device_path, | 197 void FakeShillDeviceClient::ChangePin(const dbus::ObjectPath& device_path, |
| 197 const std::string& old_pin, | 198 const std::string& old_pin, |
| 198 const std::string& new_pin, | 199 const std::string& new_pin, |
| 199 const base::Closure& callback, | 200 const base::Closure& callback, |
| 200 const ErrorCallback& error_callback) { | 201 const ErrorCallback& error_callback) { |
| 201 VLOG(1) << "ChangePin: " << device_path.value(); | 202 VLOG(1) << "ChangePin: " << device_path.value(); |
| 202 if (!stub_devices_.HasKey(device_path.value())) { | 203 if (!stub_devices_.HasKey(device_path.value())) { |
| 203 PostDeviceNotFoundError(error_callback); | 204 PostNotFoundError(error_callback); |
| 204 return; | 205 return; |
| 205 } | 206 } |
| 206 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 207 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 207 } | 208 } |
| 208 | 209 |
| 209 void FakeShillDeviceClient::Register(const dbus::ObjectPath& device_path, | 210 void FakeShillDeviceClient::Register(const dbus::ObjectPath& device_path, |
| 210 const std::string& network_id, | 211 const std::string& network_id, |
| 211 const base::Closure& callback, | 212 const base::Closure& callback, |
| 212 const ErrorCallback& error_callback) { | 213 const ErrorCallback& error_callback) { |
| 213 if (!stub_devices_.HasKey(device_path.value())) { | 214 if (!stub_devices_.HasKey(device_path.value())) { |
| 214 PostDeviceNotFoundError(error_callback); | 215 PostNotFoundError(error_callback); |
| 215 return; | 216 return; |
| 216 } | 217 } |
| 217 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 218 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 218 } | 219 } |
| 219 | 220 |
| 220 void FakeShillDeviceClient::SetCarrier(const dbus::ObjectPath& device_path, | 221 void FakeShillDeviceClient::SetCarrier(const dbus::ObjectPath& device_path, |
| 221 const std::string& carrier, | 222 const std::string& carrier, |
| 222 const base::Closure& callback, | 223 const base::Closure& callback, |
| 223 const ErrorCallback& error_callback) { | 224 const ErrorCallback& error_callback) { |
| 224 if (!stub_devices_.HasKey(device_path.value())) { | 225 if (!stub_devices_.HasKey(device_path.value())) { |
| 225 PostDeviceNotFoundError(error_callback); | 226 PostNotFoundError(error_callback); |
| 226 return; | 227 return; |
| 227 } | 228 } |
| 228 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 229 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 229 } | 230 } |
| 230 | 231 |
| 231 void FakeShillDeviceClient::Reset(const dbus::ObjectPath& device_path, | 232 void FakeShillDeviceClient::Reset(const dbus::ObjectPath& device_path, |
| 232 const base::Closure& callback, | 233 const base::Closure& callback, |
| 233 const ErrorCallback& error_callback) { | 234 const ErrorCallback& error_callback) { |
| 234 if (!stub_devices_.HasKey(device_path.value())) { | 235 if (!stub_devices_.HasKey(device_path.value())) { |
| 235 PostDeviceNotFoundError(error_callback); | 236 PostNotFoundError(error_callback); |
| 236 return; | 237 return; |
| 237 } | 238 } |
| 238 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 239 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 239 } | 240 } |
| 240 | 241 |
| 241 void FakeShillDeviceClient::PerformTDLSOperation( | 242 void FakeShillDeviceClient::PerformTDLSOperation( |
| 242 const dbus::ObjectPath& device_path, | 243 const dbus::ObjectPath& device_path, |
| 243 const std::string& operation, | 244 const std::string& operation, |
| 244 const std::string& peer, | 245 const std::string& peer, |
| 245 const StringCallback& callback, | 246 const StringCallback& callback, |
| 246 const ErrorCallback& error_callback) { | 247 const ErrorCallback& error_callback) { |
| 247 if (!stub_devices_.HasKey(device_path.value())) { | 248 if (!stub_devices_.HasKey(device_path.value())) { |
| 248 PostDeviceNotFoundError(error_callback); | 249 PostNotFoundError(error_callback); |
| 249 return; | 250 return; |
| 250 } | 251 } |
| 251 if (tdls_busy_count_) { | 252 if (tdls_busy_count_) { |
| 252 --tdls_busy_count_; | 253 --tdls_busy_count_; |
| 253 std::string error_message("In-Progress"); | 254 std::string error_message("In-Progress"); |
| 254 base::MessageLoop::current()->PostTask( | 255 base::MessageLoop::current()->PostTask( |
| 255 FROM_HERE, | 256 FROM_HERE, |
| 256 base::Bind(error_callback, | 257 base::Bind(error_callback, |
| 257 shill::kErrorResultInProgress, error_message)); | 258 shill::kErrorResultInProgress, error_message)); |
| 258 return; | 259 return; |
| 259 } | 260 } |
| 260 std::string result; | 261 std::string result; |
| 261 if (operation == shill::kTDLSStatusOperation) | 262 if (operation == shill::kTDLSStatusOperation) |
| 262 result = shill::kTDLSConnectedState; | 263 result = shill::kTDLSConnectedState; |
| 263 base::MessageLoop::current()->PostTask(FROM_HERE, | 264 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 264 base::Bind(callback, result)); | 265 base::Bind(callback, result)); |
| 265 } | 266 } |
| 266 | 267 |
| 268 void FakeShillDeviceClient::AddWakeOnPacketConnection( |
| 269 const dbus::ObjectPath& device_path, |
| 270 const net::IPEndPoint& ip_endpoint, |
| 271 const base::Closure& callback, |
| 272 const ErrorCallback& error_callback) { |
| 273 if (!stub_devices_.HasKey(device_path.value())) { |
| 274 PostNotFoundError(error_callback); |
| 275 return; |
| 276 } |
| 277 |
| 278 wake_on_packet_connections_[device_path].insert(ip_endpoint); |
| 279 |
| 280 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 281 } |
| 282 |
| 283 void FakeShillDeviceClient::RemoveWakeOnPacketConnection( |
| 284 const dbus::ObjectPath& device_path, |
| 285 const net::IPEndPoint& ip_endpoint, |
| 286 const base::Closure& callback, |
| 287 const ErrorCallback& error_callback) { |
| 288 const auto device_iter = wake_on_packet_connections_.find(device_path); |
| 289 if (!stub_devices_.HasKey(device_path.value()) || |
| 290 device_iter == wake_on_packet_connections_.end()) { |
| 291 PostNotFoundError(error_callback); |
| 292 return; |
| 293 } |
| 294 |
| 295 const auto endpoint_iter = device_iter->second.find(ip_endpoint); |
| 296 if (endpoint_iter == device_iter->second.end()) { |
| 297 PostNotFoundError(error_callback); |
| 298 return; |
| 299 } |
| 300 |
| 301 device_iter->second.erase(endpoint_iter); |
| 302 |
| 303 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 304 } |
| 305 |
| 306 void FakeShillDeviceClient::RemoveAllWakeOnPacketConnections( |
| 307 const dbus::ObjectPath& device_path, |
| 308 const base::Closure& callback, |
| 309 const ErrorCallback& error_callback) { |
| 310 const auto iter = wake_on_packet_connections_.find(device_path); |
| 311 if (!stub_devices_.HasKey(device_path.value()) || |
| 312 iter == wake_on_packet_connections_.end()) { |
| 313 PostNotFoundError(error_callback); |
| 314 return; |
| 315 } |
| 316 |
| 317 wake_on_packet_connections_.erase(iter); |
| 318 |
| 319 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 320 } |
| 321 |
| 267 ShillDeviceClient::TestInterface* FakeShillDeviceClient::GetTestInterface() { | 322 ShillDeviceClient::TestInterface* FakeShillDeviceClient::GetTestInterface() { |
| 268 return this; | 323 return this; |
| 269 } | 324 } |
| 270 | 325 |
| 271 // ShillDeviceClient::TestInterface overrides. | 326 // ShillDeviceClient::TestInterface overrides. |
| 272 | 327 |
| 273 void FakeShillDeviceClient::AddDevice(const std::string& device_path, | 328 void FakeShillDeviceClient::AddDevice(const std::string& device_path, |
| 274 const std::string& type, | 329 const std::string& type, |
| 275 const std::string& name) { | 330 const std::string& name) { |
| 276 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 331 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = | 442 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = |
| 388 observer_list_.find(device_path); | 443 observer_list_.find(device_path); |
| 389 if (iter != observer_list_.end()) | 444 if (iter != observer_list_.end()) |
| 390 return *(iter->second); | 445 return *(iter->second); |
| 391 PropertyObserverList* observer_list = new PropertyObserverList(); | 446 PropertyObserverList* observer_list = new PropertyObserverList(); |
| 392 observer_list_[device_path] = observer_list; | 447 observer_list_[device_path] = observer_list; |
| 393 return *observer_list; | 448 return *observer_list; |
| 394 } | 449 } |
| 395 | 450 |
| 396 } // namespace chromeos | 451 } // namespace chromeos |
| OLD | NEW |