| 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_ipconfig_client.h" | 5 #include "chromeos/dbus/fake_shill_ipconfig_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ptr_util.h" |
| 9 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "chromeos/dbus/shill_property_changed_observer.h" | 14 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 14 #include "dbus/bus.h" | 15 #include "dbus/bus.h" |
| 15 #include "dbus/message.h" | 16 #include "dbus/message.h" |
| 16 #include "dbus/object_path.h" | 17 #include "dbus/object_path.h" |
| 17 #include "dbus/object_proxy.h" | 18 #include "dbus/object_proxy.h" |
| 18 #include "dbus/values_util.h" | 19 #include "dbus/values_util.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 FROM_HERE, base::Bind(&FakeShillIPConfigClient::PassProperties, | 55 FROM_HERE, base::Bind(&FakeShillIPConfigClient::PassProperties, |
| 55 weak_ptr_factory_.GetWeakPtr(), dict, callback)); | 56 weak_ptr_factory_.GetWeakPtr(), dict, callback)); |
| 56 } | 57 } |
| 57 | 58 |
| 58 void FakeShillIPConfigClient::SetProperty( | 59 void FakeShillIPConfigClient::SetProperty( |
| 59 const dbus::ObjectPath& ipconfig_path, | 60 const dbus::ObjectPath& ipconfig_path, |
| 60 const std::string& name, | 61 const std::string& name, |
| 61 const base::Value& value, | 62 const base::Value& value, |
| 62 const VoidDBusMethodCallback& callback) { | 63 const VoidDBusMethodCallback& callback) { |
| 63 base::DictionaryValue* dict = NULL; | 64 base::DictionaryValue* dict = NULL; |
| 64 if (ipconfigs_.GetDictionaryWithoutPathExpansion(ipconfig_path.value(), | 65 if (!ipconfigs_.GetDictionaryWithoutPathExpansion(ipconfig_path.value(), |
| 65 &dict)) { | 66 &dict)) { |
| 66 // Update existing ip config stub object's properties. | 67 dict = ipconfigs_.SetDictionaryWithoutPathExpansion( |
| 67 dict->SetWithoutPathExpansion(name, value.DeepCopy()); | 68 ipconfig_path.value(), base::MakeUnique<base::DictionaryValue>()); |
| 68 } else { | |
| 69 // Create a new stub ipconfig object, and update its properties. | |
| 70 base::DictionaryValue* dvalue = new base::DictionaryValue; | |
| 71 dvalue->SetWithoutPathExpansion(name, value.DeepCopy()); | |
| 72 ipconfigs_.SetWithoutPathExpansion(ipconfig_path.value(), | |
| 73 dvalue); | |
| 74 } | 69 } |
| 70 // Update existing ip config stub object's properties. |
| 71 dict->SetWithoutPathExpansion(name, base::MakeUnique<base::Value>(value)); |
| 75 base::ThreadTaskRunnerHandle::Get()->PostTask( | 72 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 76 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS)); | 73 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS)); |
| 77 } | 74 } |
| 78 | 75 |
| 79 void FakeShillIPConfigClient::ClearProperty( | 76 void FakeShillIPConfigClient::ClearProperty( |
| 80 const dbus::ObjectPath& ipconfig_path, | 77 const dbus::ObjectPath& ipconfig_path, |
| 81 const std::string& name, | 78 const std::string& name, |
| 82 const VoidDBusMethodCallback& callback) { | 79 const VoidDBusMethodCallback& callback) { |
| 83 base::ThreadTaskRunnerHandle::Get()->PostTask( | 80 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 84 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS)); | 81 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS)); |
| 85 } | 82 } |
| 86 | 83 |
| 87 void FakeShillIPConfigClient::Remove(const dbus::ObjectPath& ipconfig_path, | 84 void FakeShillIPConfigClient::Remove(const dbus::ObjectPath& ipconfig_path, |
| 88 const VoidDBusMethodCallback& callback) { | 85 const VoidDBusMethodCallback& callback) { |
| 89 base::ThreadTaskRunnerHandle::Get()->PostTask( | 86 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 90 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS)); | 87 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS)); |
| 91 } | 88 } |
| 92 | 89 |
| 93 ShillIPConfigClient::TestInterface* | 90 ShillIPConfigClient::TestInterface* |
| 94 FakeShillIPConfigClient::GetTestInterface() { | 91 FakeShillIPConfigClient::GetTestInterface() { |
| 95 return this; | 92 return this; |
| 96 } | 93 } |
| 97 | 94 |
| 98 // ShillIPConfigClient::TestInterface overrides | 95 // ShillIPConfigClient::TestInterface overrides |
| 99 | 96 |
| 100 void FakeShillIPConfigClient::AddIPConfig( | 97 void FakeShillIPConfigClient::AddIPConfig( |
| 101 const std::string& ip_config_path, | 98 const std::string& ip_config_path, |
| 102 const base::DictionaryValue& properties) { | 99 const base::DictionaryValue& properties) { |
| 103 ipconfigs_.SetWithoutPathExpansion(ip_config_path, properties.DeepCopy()); | 100 ipconfigs_.SetWithoutPathExpansion(ip_config_path, |
| 101 base::MakeUnique<base::Value>(properties)); |
| 104 } | 102 } |
| 105 | 103 |
| 106 // Private methods | 104 // Private methods |
| 107 | 105 |
| 108 void FakeShillIPConfigClient::PassProperties( | 106 void FakeShillIPConfigClient::PassProperties( |
| 109 const base::DictionaryValue* values, | 107 const base::DictionaryValue* values, |
| 110 const DictionaryValueCallback& callback) const { | 108 const DictionaryValueCallback& callback) const { |
| 111 callback.Run(DBUS_METHOD_CALL_SUCCESS, *values); | 109 callback.Run(DBUS_METHOD_CALL_SUCCESS, *values); |
| 112 } | 110 } |
| 113 | 111 |
| 114 } // namespace chromeos | 112 } // namespace chromeos |
| OLD | NEW |