| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.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/values.h" | 12 #include "base/values.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 #include "chromeos/dbus/shill_manager_client.h" | 14 #include "chromeos/dbus/shill_manager_client.h" |
| 15 #include "chromeos/dbus/shill_property_changed_observer.h" | 15 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 16 #include "dbus/bus.h" | 16 #include "dbus/bus.h" |
| 17 #include "dbus/message.h" | 17 #include "dbus/message.h" |
| 18 #include "dbus/object_path.h" | 18 #include "dbus/object_path.h" |
| 19 #include "dbus/object_proxy.h" | 19 #include "dbus/object_proxy.h" |
| 20 #include "dbus/values_util.h" | 20 #include "dbus/values_util.h" |
| 21 #include "net/base/ip_endpoint.h" | 21 #include "net/base/ip_endpoint.h" |
| 22 #include "third_party/cros_system_api/dbus/service_constants.h" | 22 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 23 | 23 |
| 24 namespace chromeos { | 24 namespace chromeos { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 std::string kSimPin = "1111"; | 28 std::string kSimPin = "1111"; |
| 29 std::string kFailedMessage = "Failed"; |
| 29 | 30 |
| 30 void ErrorFunction(const std::string& device_path, | 31 void ErrorFunction(const std::string& device_path, |
| 31 const std::string& error_name, | 32 const std::string& error_name, |
| 32 const std::string& error_message) { | 33 const std::string& error_message) { |
| 33 LOG(ERROR) << "Shill Error for: " << device_path | 34 LOG(ERROR) << "Shill Error for: " << device_path |
| 34 << ": " << error_name << " : " << error_message; | 35 << ": " << error_name << " : " << error_message; |
| 35 } | 36 } |
| 36 | 37 |
| 37 void PostNotFoundError( | 38 void PostError(const std::string& error, |
| 38 const ShillDeviceClient::ErrorCallback& error_callback) { | 39 const ShillDeviceClient::ErrorCallback& error_callback) { |
| 39 std::string error_message("Failed"); | |
| 40 base::MessageLoop::current()->PostTask( | 40 base::MessageLoop::current()->PostTask( |
| 41 FROM_HERE, | 41 FROM_HERE, base::Bind(error_callback, error, kFailedMessage)); |
| 42 base::Bind(error_callback, shill::kErrorResultNotFound, error_message)); | 42 } |
| 43 |
| 44 void PostNotFoundError(const ShillDeviceClient::ErrorCallback& error_callback) { |
| 45 PostError(shill::kErrorResultNotFound, error_callback); |
| 46 } |
| 47 |
| 48 bool IsReadOnlyProperty(const std::string& name) { |
| 49 if (name == shill::kCarrierProperty) |
| 50 return true; |
| 51 return false; |
| 43 } | 52 } |
| 44 | 53 |
| 45 } // namespace | 54 } // namespace |
| 46 | 55 |
| 47 FakeShillDeviceClient::FakeShillDeviceClient() | 56 FakeShillDeviceClient::FakeShillDeviceClient() |
| 48 : initial_tdls_busy_count_(0), | 57 : initial_tdls_busy_count_(0), |
| 49 tdls_busy_count_(0), | 58 tdls_busy_count_(0), |
| 50 weak_ptr_factory_(this) { | 59 weak_ptr_factory_(this) { |
| 51 } | 60 } |
| 52 | 61 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 const dbus::ObjectPath& device_path, | 94 const dbus::ObjectPath& device_path, |
| 86 const VoidDBusMethodCallback& callback) { | 95 const VoidDBusMethodCallback& callback) { |
| 87 PostVoidCallback(callback, DBUS_METHOD_CALL_SUCCESS); | 96 PostVoidCallback(callback, DBUS_METHOD_CALL_SUCCESS); |
| 88 } | 97 } |
| 89 | 98 |
| 90 void FakeShillDeviceClient::SetProperty(const dbus::ObjectPath& device_path, | 99 void FakeShillDeviceClient::SetProperty(const dbus::ObjectPath& device_path, |
| 91 const std::string& name, | 100 const std::string& name, |
| 92 const base::Value& value, | 101 const base::Value& value, |
| 93 const base::Closure& callback, | 102 const base::Closure& callback, |
| 94 const ErrorCallback& error_callback) { | 103 const ErrorCallback& error_callback) { |
| 104 if (IsReadOnlyProperty(name)) |
| 105 PostError(shill::kErrorResultInvalidArguments, error_callback); |
| 106 SetPropertyInternal(device_path, name, value, callback, error_callback); |
| 107 } |
| 108 |
| 109 void FakeShillDeviceClient::SetPropertyInternal( |
| 110 const dbus::ObjectPath& device_path, |
| 111 const std::string& name, |
| 112 const base::Value& value, |
| 113 const base::Closure& callback, |
| 114 const ErrorCallback& error_callback) { |
| 95 base::DictionaryValue* device_properties = NULL; | 115 base::DictionaryValue* device_properties = NULL; |
| 96 if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path.value(), | 116 if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path.value(), |
| 97 &device_properties)) { | 117 &device_properties)) { |
| 98 PostNotFoundError(error_callback); | 118 PostNotFoundError(error_callback); |
| 99 return; | 119 return; |
| 100 } | 120 } |
| 101 device_properties->SetWithoutPathExpansion(name, value.DeepCopy()); | 121 device_properties->SetWithoutPathExpansion(name, value.DeepCopy()); |
| 102 base::MessageLoop::current()->PostTask( | 122 base::MessageLoop::current()->PostTask( |
| 103 FROM_HERE, | 123 FROM_HERE, |
| 104 base::Bind(&FakeShillDeviceClient::NotifyObserversPropertyChanged, | 124 base::Bind(&FakeShillDeviceClient::NotifyObserversPropertyChanged, |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 PostNotFoundError(error_callback); | 238 PostNotFoundError(error_callback); |
| 219 return; | 239 return; |
| 220 } | 240 } |
| 221 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 241 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 222 } | 242 } |
| 223 | 243 |
| 224 void FakeShillDeviceClient::SetCarrier(const dbus::ObjectPath& device_path, | 244 void FakeShillDeviceClient::SetCarrier(const dbus::ObjectPath& device_path, |
| 225 const std::string& carrier, | 245 const std::string& carrier, |
| 226 const base::Closure& callback, | 246 const base::Closure& callback, |
| 227 const ErrorCallback& error_callback) { | 247 const ErrorCallback& error_callback) { |
| 228 if (!stub_devices_.HasKey(device_path.value())) { | 248 SetPropertyInternal(device_path, shill::kCarrierProperty, |
| 229 PostNotFoundError(error_callback); | 249 base::StringValue(carrier), callback, error_callback); |
| 230 return; | |
| 231 } | |
| 232 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | |
| 233 } | 250 } |
| 234 | 251 |
| 235 void FakeShillDeviceClient::Reset(const dbus::ObjectPath& device_path, | 252 void FakeShillDeviceClient::Reset(const dbus::ObjectPath& device_path, |
| 236 const base::Closure& callback, | 253 const base::Closure& callback, |
| 237 const ErrorCallback& error_callback) { | 254 const ErrorCallback& error_callback) { |
| 238 if (!stub_devices_.HasKey(device_path.value())) { | 255 if (!stub_devices_.HasKey(device_path.value())) { |
| 239 PostNotFoundError(error_callback); | 256 PostNotFoundError(error_callback); |
| 240 return; | 257 return; |
| 241 } | 258 } |
| 242 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 259 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = | 489 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = |
| 473 observer_list_.find(device_path); | 490 observer_list_.find(device_path); |
| 474 if (iter != observer_list_.end()) | 491 if (iter != observer_list_.end()) |
| 475 return *(iter->second); | 492 return *(iter->second); |
| 476 PropertyObserverList* observer_list = new PropertyObserverList(); | 493 PropertyObserverList* observer_list = new PropertyObserverList(); |
| 477 observer_list_[device_path] = observer_list; | 494 observer_list_[device_path] = observer_list; |
| 478 return *observer_list; | 495 return *observer_list; |
| 479 } | 496 } |
| 480 | 497 |
| 481 } // namespace chromeos | 498 } // namespace chromeos |
| OLD | NEW |