| 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/flimflam_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/message_loop.h" | 8 #include "base/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 "dbus/bus.h" | 11 #include "dbus/bus.h" |
| 12 #include "dbus/message.h" | 12 #include "dbus/message.h" |
| 13 #include "dbus/object_path.h" | 13 #include "dbus/object_path.h" |
| 14 #include "dbus/object_proxy.h" | 14 #include "dbus/object_proxy.h" |
| 15 #include "dbus/values_util.h" | 15 #include "dbus/values_util.h" |
| 16 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 17 | 17 |
| 18 namespace chromeos { | 18 namespace chromeos { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // The FlimflamIPConfigClient implementation. | 22 // The ShillIPConfigClient implementation. |
| 23 class FlimflamIPConfigClientImpl : public FlimflamIPConfigClient { | 23 class ShillIPConfigClientImpl : public ShillIPConfigClient { |
| 24 public: | 24 public: |
| 25 explicit FlimflamIPConfigClientImpl(dbus::Bus* bus); | 25 explicit ShillIPConfigClientImpl(dbus::Bus* bus); |
| 26 | 26 |
| 27 // FlimflamIPConfigClient overrides: | 27 // ShillIPConfigClient overrides: |
| 28 virtual void SetPropertyChangedHandler( | 28 virtual void SetPropertyChangedHandler( |
| 29 const dbus::ObjectPath& ipconfig_path, | 29 const dbus::ObjectPath& ipconfig_path, |
| 30 const PropertyChangedHandler& handler) OVERRIDE; | 30 const PropertyChangedHandler& handler) OVERRIDE; |
| 31 virtual void ResetPropertyChangedHandler( | 31 virtual void ResetPropertyChangedHandler( |
| 32 const dbus::ObjectPath& ipconfig_path) OVERRIDE; | 32 const dbus::ObjectPath& ipconfig_path) OVERRIDE; |
| 33 virtual void Refresh(const dbus::ObjectPath& ipconfig_path, | 33 virtual void Refresh(const dbus::ObjectPath& ipconfig_path, |
| 34 const VoidDBusMethodCallback& callback) OVERRIDE; | 34 const VoidDBusMethodCallback& callback) OVERRIDE; |
| 35 virtual void GetProperties(const dbus::ObjectPath& ipconfig_path, | 35 virtual void GetProperties(const dbus::ObjectPath& ipconfig_path, |
| 36 const DictionaryValueCallback& callback) OVERRIDE; | 36 const DictionaryValueCallback& callback) OVERRIDE; |
| 37 virtual base::DictionaryValue* CallGetPropertiesAndBlock( | 37 virtual base::DictionaryValue* CallGetPropertiesAndBlock( |
| 38 const dbus::ObjectPath& ipconfig_path) OVERRIDE; | 38 const dbus::ObjectPath& ipconfig_path) OVERRIDE; |
| 39 virtual void SetProperty(const dbus::ObjectPath& ipconfig_path, | 39 virtual void SetProperty(const dbus::ObjectPath& ipconfig_path, |
| 40 const std::string& name, | 40 const std::string& name, |
| 41 const base::Value& value, | 41 const base::Value& value, |
| 42 const VoidDBusMethodCallback& callback) OVERRIDE; | 42 const VoidDBusMethodCallback& callback) OVERRIDE; |
| 43 virtual void ClearProperty(const dbus::ObjectPath& ipconfig_path, | 43 virtual void ClearProperty(const dbus::ObjectPath& ipconfig_path, |
| 44 const std::string& name, | 44 const std::string& name, |
| 45 const VoidDBusMethodCallback& callback) OVERRIDE; | 45 const VoidDBusMethodCallback& callback) OVERRIDE; |
| 46 virtual void Remove(const dbus::ObjectPath& ipconfig_path, | 46 virtual void Remove(const dbus::ObjectPath& ipconfig_path, |
| 47 const VoidDBusMethodCallback& callback) OVERRIDE; | 47 const VoidDBusMethodCallback& callback) OVERRIDE; |
| 48 virtual bool CallRemoveAndBlock( | 48 virtual bool CallRemoveAndBlock( |
| 49 const dbus::ObjectPath& ipconfig_path) OVERRIDE; | 49 const dbus::ObjectPath& ipconfig_path) OVERRIDE; |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 typedef std::map<std::string, FlimflamClientHelper*> HelperMap; | 52 typedef std::map<std::string, ShillClientHelper*> HelperMap; |
| 53 | 53 |
| 54 // Returns the corresponding FlimflamClientHelper for the profile. | 54 // Returns the corresponding ShillClientHelper for the profile. |
| 55 FlimflamClientHelper* GetHelper(const dbus::ObjectPath& ipconfig_path) { | 55 ShillClientHelper* GetHelper(const dbus::ObjectPath& ipconfig_path) { |
| 56 HelperMap::iterator it = helpers_.find(ipconfig_path.value()); | 56 HelperMap::iterator it = helpers_.find(ipconfig_path.value()); |
| 57 if (it != helpers_.end()) | 57 if (it != helpers_.end()) |
| 58 return it->second; | 58 return it->second; |
| 59 | 59 |
| 60 // There is no helper for the profile, create it. | 60 // There is no helper for the profile, create it. |
| 61 dbus::ObjectProxy* object_proxy = | 61 dbus::ObjectProxy* object_proxy = |
| 62 bus_->GetObjectProxy(flimflam::kFlimflamServiceName, ipconfig_path); | 62 bus_->GetObjectProxy(flimflam::kFlimflamServiceName, ipconfig_path); |
| 63 FlimflamClientHelper* helper = new FlimflamClientHelper(bus_, object_proxy); | 63 ShillClientHelper* helper = new ShillClientHelper(bus_, object_proxy); |
| 64 helper->MonitorPropertyChanged(flimflam::kFlimflamIPConfigInterface); | 64 helper->MonitorPropertyChanged(flimflam::kFlimflamIPConfigInterface); |
| 65 helpers_.insert(HelperMap::value_type(ipconfig_path.value(), helper)); | 65 helpers_.insert(HelperMap::value_type(ipconfig_path.value(), helper)); |
| 66 return helper; | 66 return helper; |
| 67 } | 67 } |
| 68 | 68 |
| 69 dbus::Bus* bus_; | 69 dbus::Bus* bus_; |
| 70 HelperMap helpers_; | 70 HelperMap helpers_; |
| 71 STLValueDeleter<HelperMap> helpers_deleter_; | 71 STLValueDeleter<HelperMap> helpers_deleter_; |
| 72 | 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(FlimflamIPConfigClientImpl); | 73 DISALLOW_COPY_AND_ASSIGN(ShillIPConfigClientImpl); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 FlimflamIPConfigClientImpl::FlimflamIPConfigClientImpl(dbus::Bus* bus) | 76 ShillIPConfigClientImpl::ShillIPConfigClientImpl(dbus::Bus* bus) |
| 77 : bus_(bus), | 77 : bus_(bus), |
| 78 helpers_deleter_(&helpers_) { | 78 helpers_deleter_(&helpers_) { |
| 79 } | 79 } |
| 80 | 80 |
| 81 void FlimflamIPConfigClientImpl::SetPropertyChangedHandler( | 81 void ShillIPConfigClientImpl::SetPropertyChangedHandler( |
| 82 const dbus::ObjectPath& ipconfig_path, | 82 const dbus::ObjectPath& ipconfig_path, |
| 83 const PropertyChangedHandler& handler) { | 83 const PropertyChangedHandler& handler) { |
| 84 GetHelper(ipconfig_path)->SetPropertyChangedHandler(handler); | 84 GetHelper(ipconfig_path)->SetPropertyChangedHandler(handler); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void FlimflamIPConfigClientImpl::ResetPropertyChangedHandler( | 87 void ShillIPConfigClientImpl::ResetPropertyChangedHandler( |
| 88 const dbus::ObjectPath& ipconfig_path) { | 88 const dbus::ObjectPath& ipconfig_path) { |
| 89 GetHelper(ipconfig_path)->ResetPropertyChangedHandler(); | 89 GetHelper(ipconfig_path)->ResetPropertyChangedHandler(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void FlimflamIPConfigClientImpl::GetProperties( | 92 void ShillIPConfigClientImpl::GetProperties( |
| 93 const dbus::ObjectPath& ipconfig_path, | 93 const dbus::ObjectPath& ipconfig_path, |
| 94 const DictionaryValueCallback& callback) { | 94 const DictionaryValueCallback& callback) { |
| 95 dbus::MethodCall method_call(flimflam::kFlimflamIPConfigInterface, | 95 dbus::MethodCall method_call(flimflam::kFlimflamIPConfigInterface, |
| 96 flimflam::kGetPropertiesFunction); | 96 flimflam::kGetPropertiesFunction); |
| 97 GetHelper(ipconfig_path)->CallDictionaryValueMethod(&method_call, callback); | 97 GetHelper(ipconfig_path)->CallDictionaryValueMethod(&method_call, callback); |
| 98 } | 98 } |
| 99 | 99 |
| 100 base::DictionaryValue* FlimflamIPConfigClientImpl::CallGetPropertiesAndBlock( | 100 base::DictionaryValue* ShillIPConfigClientImpl::CallGetPropertiesAndBlock( |
| 101 const dbus::ObjectPath& ipconfig_path) { | 101 const dbus::ObjectPath& ipconfig_path) { |
| 102 dbus::MethodCall method_call(flimflam::kFlimflamIPConfigInterface, | 102 dbus::MethodCall method_call(flimflam::kFlimflamIPConfigInterface, |
| 103 flimflam::kGetPropertiesFunction); | 103 flimflam::kGetPropertiesFunction); |
| 104 return GetHelper(ipconfig_path)->CallDictionaryValueMethodAndBlock( | 104 return GetHelper(ipconfig_path)->CallDictionaryValueMethodAndBlock( |
| 105 &method_call); | 105 &method_call); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void FlimflamIPConfigClientImpl::Refresh( | 108 void ShillIPConfigClientImpl::Refresh( |
| 109 const dbus::ObjectPath& ipconfig_path, | 109 const dbus::ObjectPath& ipconfig_path, |
| 110 const VoidDBusMethodCallback& callback) { | 110 const VoidDBusMethodCallback& callback) { |
| 111 dbus::MethodCall method_call(flimflam::kFlimflamIPConfigInterface, | 111 dbus::MethodCall method_call(flimflam::kFlimflamIPConfigInterface, |
| 112 shill::kRefreshFunction); | 112 shill::kRefreshFunction); |
| 113 GetHelper(ipconfig_path)->CallVoidMethod(&method_call, callback); | 113 GetHelper(ipconfig_path)->CallVoidMethod(&method_call, callback); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void FlimflamIPConfigClientImpl::SetProperty( | 116 void ShillIPConfigClientImpl::SetProperty( |
| 117 const dbus::ObjectPath& ipconfig_path, | 117 const dbus::ObjectPath& ipconfig_path, |
| 118 const std::string& name, | 118 const std::string& name, |
| 119 const base::Value& value, | 119 const base::Value& value, |
| 120 const VoidDBusMethodCallback& callback) { | 120 const VoidDBusMethodCallback& callback) { |
| 121 dbus::MethodCall method_call(flimflam::kFlimflamIPConfigInterface, | 121 dbus::MethodCall method_call(flimflam::kFlimflamIPConfigInterface, |
| 122 flimflam::kSetPropertyFunction); | 122 flimflam::kSetPropertyFunction); |
| 123 dbus::MessageWriter writer(&method_call); | 123 dbus::MessageWriter writer(&method_call); |
| 124 writer.AppendString(name); | 124 writer.AppendString(name); |
| 125 // IPConfig supports writing basic type and string array properties. | 125 // IPConfig supports writing basic type and string array properties. |
| 126 switch (value.GetType()) { | 126 switch (value.GetType()) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 148 case base::Value::TYPE_DOUBLE: | 148 case base::Value::TYPE_DOUBLE: |
| 149 case base::Value::TYPE_STRING: | 149 case base::Value::TYPE_STRING: |
| 150 dbus::AppendBasicTypeValueDataAsVariant(&writer, value); | 150 dbus::AppendBasicTypeValueDataAsVariant(&writer, value); |
| 151 break; | 151 break; |
| 152 default: | 152 default: |
| 153 DLOG(ERROR) << "Unexpected type " << value.GetType(); | 153 DLOG(ERROR) << "Unexpected type " << value.GetType(); |
| 154 } | 154 } |
| 155 GetHelper(ipconfig_path)->CallVoidMethod(&method_call, callback); | 155 GetHelper(ipconfig_path)->CallVoidMethod(&method_call, callback); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void FlimflamIPConfigClientImpl::ClearProperty( | 158 void ShillIPConfigClientImpl::ClearProperty( |
| 159 const dbus::ObjectPath& ipconfig_path, | 159 const dbus::ObjectPath& ipconfig_path, |
| 160 const std::string& name, | 160 const std::string& name, |
| 161 const VoidDBusMethodCallback& callback) { | 161 const VoidDBusMethodCallback& callback) { |
| 162 dbus::MethodCall method_call(flimflam::kFlimflamIPConfigInterface, | 162 dbus::MethodCall method_call(flimflam::kFlimflamIPConfigInterface, |
| 163 flimflam::kClearPropertyFunction); | 163 flimflam::kClearPropertyFunction); |
| 164 dbus::MessageWriter writer(&method_call); | 164 dbus::MessageWriter writer(&method_call); |
| 165 writer.AppendString(name); | 165 writer.AppendString(name); |
| 166 GetHelper(ipconfig_path)->CallVoidMethod(&method_call, callback); | 166 GetHelper(ipconfig_path)->CallVoidMethod(&method_call, callback); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void FlimflamIPConfigClientImpl::Remove( | 169 void ShillIPConfigClientImpl::Remove( |
| 170 const dbus::ObjectPath& ipconfig_path, | 170 const dbus::ObjectPath& ipconfig_path, |
| 171 const VoidDBusMethodCallback& callback) { | 171 const VoidDBusMethodCallback& callback) { |
| 172 dbus::MethodCall method_call(flimflam::kFlimflamIPConfigInterface, | 172 dbus::MethodCall method_call(flimflam::kFlimflamIPConfigInterface, |
| 173 flimflam::kRemoveConfigFunction); | 173 flimflam::kRemoveConfigFunction); |
| 174 GetHelper(ipconfig_path)->CallVoidMethod(&method_call, callback); | 174 GetHelper(ipconfig_path)->CallVoidMethod(&method_call, callback); |
| 175 } | 175 } |
| 176 | 176 |
| 177 bool FlimflamIPConfigClientImpl::CallRemoveAndBlock( | 177 bool ShillIPConfigClientImpl::CallRemoveAndBlock( |
| 178 const dbus::ObjectPath& ipconfig_path) { | 178 const dbus::ObjectPath& ipconfig_path) { |
| 179 dbus::MethodCall method_call(flimflam::kFlimflamIPConfigInterface, | 179 dbus::MethodCall method_call(flimflam::kFlimflamIPConfigInterface, |
| 180 flimflam::kRemoveConfigFunction); | 180 flimflam::kRemoveConfigFunction); |
| 181 return GetHelper(ipconfig_path)->CallVoidMethodAndBlock(&method_call); | 181 return GetHelper(ipconfig_path)->CallVoidMethodAndBlock(&method_call); |
| 182 } | 182 } |
| 183 | 183 |
| 184 // A stub implementation of FlimflamIPConfigClient. | 184 // A stub implementation of ShillIPConfigClient. |
| 185 class FlimflamIPConfigClientStubImpl : public FlimflamIPConfigClient { | 185 class ShillIPConfigClientStubImpl : public ShillIPConfigClient { |
| 186 public: | 186 public: |
| 187 FlimflamIPConfigClientStubImpl() : weak_ptr_factory_(this) {} | 187 ShillIPConfigClientStubImpl() : weak_ptr_factory_(this) {} |
| 188 | 188 |
| 189 virtual ~FlimflamIPConfigClientStubImpl() {} | 189 virtual ~ShillIPConfigClientStubImpl() {} |
| 190 | 190 |
| 191 /////////////////////////////////////////////// | 191 /////////////////////////////////////////////// |
| 192 // FlimflamIPConfigClient overrides: | 192 // ShillIPConfigClient overrides: |
| 193 virtual void SetPropertyChangedHandler( | 193 virtual void SetPropertyChangedHandler( |
| 194 const dbus::ObjectPath& ipconfig_path, | 194 const dbus::ObjectPath& ipconfig_path, |
| 195 const PropertyChangedHandler& handler) OVERRIDE {} | 195 const PropertyChangedHandler& handler) OVERRIDE {} |
| 196 | 196 |
| 197 virtual void ResetPropertyChangedHandler( | 197 virtual void ResetPropertyChangedHandler( |
| 198 const dbus::ObjectPath& ipconfig_path) OVERRIDE {} | 198 const dbus::ObjectPath& ipconfig_path) OVERRIDE {} |
| 199 | 199 |
| 200 virtual void Refresh(const dbus::ObjectPath& ipconfig_path, | 200 virtual void Refresh(const dbus::ObjectPath& ipconfig_path, |
| 201 const VoidDBusMethodCallback& callback) OVERRIDE {} | 201 const VoidDBusMethodCallback& callback) OVERRIDE {} |
| 202 | 202 |
| 203 virtual void GetProperties(const dbus::ObjectPath& ipconfig_path, | 203 virtual void GetProperties(const dbus::ObjectPath& ipconfig_path, |
| 204 const DictionaryValueCallback& callback) OVERRIDE { | 204 const DictionaryValueCallback& callback) OVERRIDE { |
| 205 MessageLoop::current()->PostTask( | 205 MessageLoop::current()->PostTask( |
| 206 FROM_HERE, base::Bind(&FlimflamIPConfigClientStubImpl::PassProperties, | 206 FROM_HERE, base::Bind(&ShillIPConfigClientStubImpl::PassProperties, |
| 207 weak_ptr_factory_.GetWeakPtr(), | 207 weak_ptr_factory_.GetWeakPtr(), |
| 208 callback)); | 208 callback)); |
| 209 } | 209 } |
| 210 | 210 |
| 211 virtual base::DictionaryValue* CallGetPropertiesAndBlock( | 211 virtual base::DictionaryValue* CallGetPropertiesAndBlock( |
| 212 const dbus::ObjectPath& ipconfig_path) OVERRIDE { | 212 const dbus::ObjectPath& ipconfig_path) OVERRIDE { |
| 213 return new base::DictionaryValue; | 213 return new base::DictionaryValue; |
| 214 } | 214 } |
| 215 | 215 |
| 216 virtual void SetProperty(const dbus::ObjectPath& ipconfig_path, | 216 virtual void SetProperty(const dbus::ObjectPath& ipconfig_path, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 242 private: | 242 private: |
| 243 // Runs callback with |properties_|. | 243 // Runs callback with |properties_|. |
| 244 void PassProperties(const DictionaryValueCallback& callback) const { | 244 void PassProperties(const DictionaryValueCallback& callback) const { |
| 245 callback.Run(DBUS_METHOD_CALL_SUCCESS, properties_); | 245 callback.Run(DBUS_METHOD_CALL_SUCCESS, properties_); |
| 246 } | 246 } |
| 247 | 247 |
| 248 base::DictionaryValue properties_; | 248 base::DictionaryValue properties_; |
| 249 | 249 |
| 250 // Note: This should remain the last member so it'll be destroyed and | 250 // Note: This should remain the last member so it'll be destroyed and |
| 251 // invalidate its weak pointers before any other members are destroyed. | 251 // invalidate its weak pointers before any other members are destroyed. |
| 252 base::WeakPtrFactory<FlimflamIPConfigClientStubImpl> weak_ptr_factory_; | 252 base::WeakPtrFactory<ShillIPConfigClientStubImpl> weak_ptr_factory_; |
| 253 | 253 |
| 254 DISALLOW_COPY_AND_ASSIGN(FlimflamIPConfigClientStubImpl); | 254 DISALLOW_COPY_AND_ASSIGN(ShillIPConfigClientStubImpl); |
| 255 }; | 255 }; |
| 256 | 256 |
| 257 } // namespace | 257 } // namespace |
| 258 | 258 |
| 259 FlimflamIPConfigClient::FlimflamIPConfigClient() {} | 259 ShillIPConfigClient::ShillIPConfigClient() {} |
| 260 | 260 |
| 261 FlimflamIPConfigClient::~FlimflamIPConfigClient() {} | 261 ShillIPConfigClient::~ShillIPConfigClient() {} |
| 262 | 262 |
| 263 // static | 263 // static |
| 264 FlimflamIPConfigClient* FlimflamIPConfigClient::Create( | 264 ShillIPConfigClient* ShillIPConfigClient::Create( |
| 265 DBusClientImplementationType type, | 265 DBusClientImplementationType type, |
| 266 dbus::Bus* bus) { | 266 dbus::Bus* bus) { |
| 267 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 267 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 268 return new FlimflamIPConfigClientImpl(bus); | 268 return new ShillIPConfigClientImpl(bus); |
| 269 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 269 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 270 return new FlimflamIPConfigClientStubImpl(); | 270 return new ShillIPConfigClientStubImpl(); |
| 271 } | 271 } |
| 272 | 272 |
| 273 } // namespace chromeos | 273 } // namespace chromeos |
| OLD | NEW |