| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_ipconfig_client.h" | 5 #include "chromeos/dbus/shill_ipconfig_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/containers/scoped_ptr_map.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 9 #include "base/stl_util.h" | |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "chromeos/dbus/shill_property_changed_observer.h" | 12 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 12 #include "dbus/bus.h" | 13 #include "dbus/bus.h" |
| 13 #include "dbus/message.h" | 14 #include "dbus/message.h" |
| 14 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
| 15 #include "dbus/object_proxy.h" | 16 #include "dbus/object_proxy.h" |
| 16 #include "dbus/values_util.h" | 17 #include "dbus/values_util.h" |
| 17 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 18 | 19 |
| 19 namespace chromeos { | 20 namespace chromeos { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 50 const std::string& name, | 51 const std::string& name, |
| 51 const VoidDBusMethodCallback& callback) override; | 52 const VoidDBusMethodCallback& callback) override; |
| 52 void Remove(const dbus::ObjectPath& ipconfig_path, | 53 void Remove(const dbus::ObjectPath& ipconfig_path, |
| 53 const VoidDBusMethodCallback& callback) override; | 54 const VoidDBusMethodCallback& callback) override; |
| 54 ShillIPConfigClient::TestInterface* GetTestInterface() override; | 55 ShillIPConfigClient::TestInterface* GetTestInterface() override; |
| 55 | 56 |
| 56 protected: | 57 protected: |
| 57 void Init(dbus::Bus* bus) override { bus_ = bus; } | 58 void Init(dbus::Bus* bus) override { bus_ = bus; } |
| 58 | 59 |
| 59 private: | 60 private: |
| 60 typedef std::map<std::string, ShillClientHelper*> HelperMap; | 61 typedef ScopedPtrMap<std::string, scoped_ptr<ShillClientHelper>> HelperMap; |
| 61 | 62 |
| 62 // Returns the corresponding ShillClientHelper for the profile. | 63 // Returns the corresponding ShillClientHelper for the profile. |
| 63 ShillClientHelper* GetHelper(const dbus::ObjectPath& ipconfig_path) { | 64 ShillClientHelper* GetHelper(const dbus::ObjectPath& ipconfig_path) { |
| 64 HelperMap::iterator it = helpers_.find(ipconfig_path.value()); | 65 HelperMap::const_iterator it = helpers_.find(ipconfig_path.value()); |
| 65 if (it != helpers_.end()) | 66 if (it != helpers_.end()) |
| 66 return it->second; | 67 return it->second; |
| 67 | 68 |
| 68 // There is no helper for the profile, create it. | 69 // There is no helper for the profile, create it. |
| 69 dbus::ObjectProxy* object_proxy = | 70 dbus::ObjectProxy* object_proxy = |
| 70 bus_->GetObjectProxy(shill::kFlimflamServiceName, ipconfig_path); | 71 bus_->GetObjectProxy(shill::kFlimflamServiceName, ipconfig_path); |
| 71 ShillClientHelper* helper = new ShillClientHelper(object_proxy); | 72 scoped_ptr<ShillClientHelper> helper(new ShillClientHelper(object_proxy)); |
| 72 helper->MonitorPropertyChanged(shill::kFlimflamIPConfigInterface); | 73 helper->MonitorPropertyChanged(shill::kFlimflamIPConfigInterface); |
| 73 helpers_.insert(HelperMap::value_type(ipconfig_path.value(), helper)); | 74 ShillClientHelper* helper_ptr = helper.get(); |
| 74 return helper; | 75 helpers_.insert(ipconfig_path.value(), helper.Pass()); |
| 76 return helper_ptr; |
| 75 } | 77 } |
| 76 | 78 |
| 77 dbus::Bus* bus_; | 79 dbus::Bus* bus_; |
| 78 HelperMap helpers_; | 80 HelperMap helpers_; |
| 79 STLValueDeleter<HelperMap> helpers_deleter_; | |
| 80 | 81 |
| 81 DISALLOW_COPY_AND_ASSIGN(ShillIPConfigClientImpl); | 82 DISALLOW_COPY_AND_ASSIGN(ShillIPConfigClientImpl); |
| 82 }; | 83 }; |
| 83 | 84 |
| 84 ShillIPConfigClientImpl::ShillIPConfigClientImpl() | 85 ShillIPConfigClientImpl::ShillIPConfigClientImpl() : bus_(NULL) { |
| 85 : bus_(NULL), | |
| 86 helpers_deleter_(&helpers_) { | |
| 87 } | 86 } |
| 88 | 87 |
| 89 void ShillIPConfigClientImpl::GetProperties( | 88 void ShillIPConfigClientImpl::GetProperties( |
| 90 const dbus::ObjectPath& ipconfig_path, | 89 const dbus::ObjectPath& ipconfig_path, |
| 91 const DictionaryValueCallback& callback) { | 90 const DictionaryValueCallback& callback) { |
| 92 dbus::MethodCall method_call(shill::kFlimflamIPConfigInterface, | 91 dbus::MethodCall method_call(shill::kFlimflamIPConfigInterface, |
| 93 shill::kGetPropertiesFunction); | 92 shill::kGetPropertiesFunction); |
| 94 GetHelper(ipconfig_path)->CallDictionaryValueMethod(&method_call, callback); | 93 GetHelper(ipconfig_path)->CallDictionaryValueMethod(&method_call, callback); |
| 95 } | 94 } |
| 96 | 95 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 ShillIPConfigClient::ShillIPConfigClient() {} | 172 ShillIPConfigClient::ShillIPConfigClient() {} |
| 174 | 173 |
| 175 ShillIPConfigClient::~ShillIPConfigClient() {} | 174 ShillIPConfigClient::~ShillIPConfigClient() {} |
| 176 | 175 |
| 177 // static | 176 // static |
| 178 ShillIPConfigClient* ShillIPConfigClient::Create() { | 177 ShillIPConfigClient* ShillIPConfigClient::Create() { |
| 179 return new ShillIPConfigClientImpl(); | 178 return new ShillIPConfigClientImpl(); |
| 180 } | 179 } |
| 181 | 180 |
| 182 } // namespace chromeos | 181 } // namespace chromeos |
| OLD | NEW |