Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Unified Diff: chromeos/dbus/shill_client_helper.h

Issue 24558004: Track active references in ShillClientHelper (Take 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chromeos/dbus/shill_client_helper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_;
« no previous file with comments | « no previous file | chromeos/dbus/shill_client_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698