Index: chromeos/dbus/shill_client_helper.h |
diff --git a/chromeos/dbus/shill_client_helper.h b/chromeos/dbus/shill_client_helper.h |
index 12cd9948cf2f04b2bc86ae3e8293d53bd59a1ef6..a52fc222eae758b43c86d32bd1b97554f9f044db 100644 |
--- a/chromeos/dbus/shill_client_helper.h |
+++ b/chromeos/dbus/shill_client_helper.h |
@@ -41,6 +41,8 @@ namespace chromeos { |
// A class to help implement Shill clients. |
class ShillClientHelper { |
public: |
+ class RefHolder; |
+ |
// A callback to handle PropertyChanged signals. |
typedef base::Callback<void(const std::string& name, |
const base::Value& value)> PropertyChangedHandler; |
@@ -68,11 +70,17 @@ class ShillClientHelper { |
// A callback that handles responses for methods with boolean results. |
typedef base::Callback<void(bool result)> BooleanCallback; |
+ // Callback used to notify owner when this can be safely released. |
+ typedef base::Callback<void(ShillClientHelper* helper)> ReleasedCallback; |
- ShillClientHelper(dbus::Bus* bus, dbus::ObjectProxy* proxy); |
+ explicit ShillClientHelper(dbus::ObjectProxy* proxy); |
virtual ~ShillClientHelper(); |
+ // Sets |released_callback_|. This is optional and should only be called at |
+ // most once. |
+ void SetReleasedCallback(ReleasedCallback callback); |
+ |
// Adds an |observer| of the PropertyChanged signal. |
void AddPropertyChangedObserver(ShillPropertyChangedObserver* observer); |
@@ -131,6 +139,8 @@ class ShillClientHelper { |
const ListValueCallback& callback, |
const ErrorCallback& error_callback); |
+ const dbus::ObjectProxy* object_proxy() const { return proxy_; } |
+ |
// Appends the value (basic types and string-to-string dictionary) to the |
// writer as a variant. |
static void AppendValueDataAsVariant(dbus::MessageWriter* writer, |
@@ -141,6 +151,13 @@ class ShillClientHelper { |
dbus::MessageWriter* writer, |
const base::DictionaryValue& dictionary); |
+ protected: |
+ // Reference / Ownership management. If the number of active refs (observers |
+ // + in-progress method calls) becomes 0, |released_callback_| (if set) will |
+ // be called. |
+ void AddRef(); |
+ void Release(); |
+ |
private: |
// Starts monitoring PropertyChanged signal. |
void MonitorPropertyChangedInternal(const std::string& interface_name); |
@@ -154,6 +171,8 @@ class ShillClientHelper { |
void OnPropertyChanged(dbus::Signal* signal); |
dbus::ObjectProxy* proxy_; |
+ ReleasedCallback released_callback_; |
+ int active_refs_; |
PropertyChangedHandler property_changed_handler_; |
ObserverList<ShillPropertyChangedObserver, true /* check_empty */> |
observer_list_; |