| 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_service_client.h" | 5 #include "chromeos/dbus/shill_service_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/shill_property_changed_observer.h" | 11 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 12 #include "chromeos/dbus/shill_service_client_stub.h" | 12 #include "chromeos/dbus/shill_service_client_stub.h" |
| 13 #include "chromeos/network/network_event_log.h" |
| 13 #include "dbus/bus.h" | 14 #include "dbus/bus.h" |
| 14 #include "dbus/message.h" | 15 #include "dbus/message.h" |
| 15 #include "dbus/object_proxy.h" | 16 #include "dbus/object_proxy.h" |
| 16 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 17 | 18 |
| 18 namespace chromeos { | 19 namespace chromeos { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 #ifndef DBUS_ERROR_UNKNOWN_OBJECT | 23 #ifndef DBUS_ERROR_UNKNOWN_OBJECT |
| (...skipping 20 matching lines...) Expand all Loading... |
| 43 error_name == DBUS_ERROR_UNKNOWN_OBJECT) | 44 error_name == DBUS_ERROR_UNKNOWN_OBJECT) |
| 44 VLOG(1) << log_string; | 45 VLOG(1) << log_string; |
| 45 else | 46 else |
| 46 LOG(ERROR) << log_string; | 47 LOG(ERROR) << log_string; |
| 47 | 48 |
| 48 base::DictionaryValue empty_dictionary; | 49 base::DictionaryValue empty_dictionary; |
| 49 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary); | 50 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary); |
| 50 } | 51 } |
| 51 | 52 |
| 52 // The ShillServiceClient implementation. | 53 // The ShillServiceClient implementation. |
| 53 class ShillServiceClientImpl : public ShillServiceClient { | 54 class ShillServiceClientImpl : public ShillServiceClient, |
| 55 public ShillClientHelper::Owner { |
| 54 public: | 56 public: |
| 55 explicit ShillServiceClientImpl() | 57 explicit ShillServiceClientImpl() |
| 56 : bus_(NULL), | 58 : bus_(NULL), |
| 57 helpers_deleter_(&helpers_) { | 59 helpers_deleter_(&helpers_) { |
| 58 } | 60 } |
| 59 | 61 |
| 60 virtual void AddPropertyChangedObserver( | 62 virtual void AddPropertyChangedObserver( |
| 61 const dbus::ObjectPath& service_path, | 63 const dbus::ObjectPath& service_path, |
| 62 ShillPropertyChangedObserver* observer) OVERRIDE { | 64 ShillPropertyChangedObserver* observer) OVERRIDE { |
| 63 GetHelper(service_path)->AddPropertyChangedObserver(observer); | 65 GetHelper(service_path)->AddPropertyChangedObserver(observer); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 private: | 217 private: |
| 216 typedef std::map<std::string, ShillClientHelper*> HelperMap; | 218 typedef std::map<std::string, ShillClientHelper*> HelperMap; |
| 217 | 219 |
| 218 // Returns the corresponding ShillClientHelper for the profile. | 220 // Returns the corresponding ShillClientHelper for the profile. |
| 219 ShillClientHelper* GetHelper(const dbus::ObjectPath& service_path) { | 221 ShillClientHelper* GetHelper(const dbus::ObjectPath& service_path) { |
| 220 HelperMap::iterator it = helpers_.find(service_path.value()); | 222 HelperMap::iterator it = helpers_.find(service_path.value()); |
| 221 if (it != helpers_.end()) | 223 if (it != helpers_.end()) |
| 222 return it->second; | 224 return it->second; |
| 223 | 225 |
| 224 // There is no helper for the profile, create it. | 226 // There is no helper for the profile, create it. |
| 227 NET_LOG_DEBUG("AddShillClientHelper", service_path.value()); |
| 225 dbus::ObjectProxy* object_proxy = | 228 dbus::ObjectProxy* object_proxy = |
| 226 bus_->GetObjectProxy(flimflam::kFlimflamServiceName, service_path); | 229 bus_->GetObjectProxy(flimflam::kFlimflamServiceName, service_path); |
| 227 ShillClientHelper* helper = new ShillClientHelper(bus_, object_proxy); | 230 ShillClientHelper* helper = new ShillClientHelper(object_proxy); |
| 231 helper->SetOwner(this); |
| 228 helper->MonitorPropertyChanged(flimflam::kFlimflamServiceInterface); | 232 helper->MonitorPropertyChanged(flimflam::kFlimflamServiceInterface); |
| 229 helpers_.insert(HelperMap::value_type(service_path.value(), helper)); | 233 helpers_.insert(HelperMap::value_type(service_path.value(), helper)); |
| 230 return helper; | 234 return helper; |
| 231 } | 235 } |
| 232 | 236 |
| 237 // ShillClientHelper::Owner |
| 238 virtual void NotifyReleased(ShillClientHelper* helper) OVERRIDE { |
| 239 // New Shill Service DBus objects are created relatively frequently, so |
| 240 // remove them when they become inactive (no observers and no active method |
| 241 // calls). |
| 242 const dbus::ObjectPath& object_path = helper->object_proxy()->object_path(); |
| 243 NET_LOG_DEBUG("RemoveShillClientHelper", object_path.value()); |
| 244 bus_->RemoveObjectProxy(flimflam::kFlimflamServiceName, |
| 245 object_path, base::Bind(&base::DoNothing)); |
| 246 helpers_.erase(object_path.value()); |
| 247 delete helper; |
| 248 } |
| 249 |
| 233 dbus::Bus* bus_; | 250 dbus::Bus* bus_; |
| 234 HelperMap helpers_; | 251 HelperMap helpers_; |
| 235 STLValueDeleter<HelperMap> helpers_deleter_; | 252 STLValueDeleter<HelperMap> helpers_deleter_; |
| 236 | 253 |
| 237 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientImpl); | 254 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientImpl); |
| 238 }; | 255 }; |
| 239 | 256 |
| 240 } // namespace | 257 } // namespace |
| 241 | 258 |
| 242 ShillServiceClient::ShillServiceClient() {} | 259 ShillServiceClient::ShillServiceClient() {} |
| 243 | 260 |
| 244 ShillServiceClient::~ShillServiceClient() {} | 261 ShillServiceClient::~ShillServiceClient() {} |
| 245 | 262 |
| 246 // static | 263 // static |
| 247 ShillServiceClient* ShillServiceClient::Create( | 264 ShillServiceClient* ShillServiceClient::Create( |
| 248 DBusClientImplementationType type) { | 265 DBusClientImplementationType type) { |
| 249 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 266 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 250 return new ShillServiceClientImpl(); | 267 return new ShillServiceClientImpl(); |
| 251 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 268 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 252 return new ShillServiceClientStub(); | 269 return new ShillServiceClientStub(); |
| 253 } | 270 } |
| 254 | 271 |
| 255 } // namespace chromeos | 272 } // namespace chromeos |
| OLD | NEW |