New issue
Advanced search Search tips

Issue 782761 link

Starred by 0 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 2
Type: Bug



Sign in to add a comment

Return scoped_refptr in GetImageLoaderClient

Project Member Reported by xiaochu@chromium.org, Nov 8 2017

Issue description

modify DBusThreadManager::GetImageLoaderClient and related to return a  scoped_refptr instead of raw ptr. In this case, the memory space does not outlive the process that owns it.
 
Cc: hidehiko@chromium.org satorux@chromium.org steve...@chromium.org derat@chromium.org adlr@chromium.org
is there a reason why we use unique_ptr for all clients in chromeos/dbus/dbus_clients_browser.h?

it looks like a client is 'get' as a raw pointer all the time which isn't ideal. 

do you think it would be a practical idea to switch to scoped_refptr from unique_ptr which seems more applicable here?
DBusClientsBrowser is owned by DBusThreadManager which provides explicit initialization and shutdown of DBus services.

The clients in DBusClientsBrowser should not be able to outlive DBusThreadManager and therefore should continue to use unique_ptr, not refptr.

Consumers of the DBus clients should be aware of the lifetime of DBusThreadManager and should call DBusThreadManager::IsInitialized() if there is any uncertainty (e.g. during shutdown / destruction).


Comment 3 by derat@chromium.org, Nov 28 2017

It's a bit tangential, but I've recently recommended in some reviews that people make their c'tors take pointers to Client objects instead of calling DBusThreadManager::Get() directly. This can make unit tests a bit simpler in some cases, since a test can initialize and pass its own Fake*Client object instead of needing to do an ugly dance to get a raw pointer to the DBusThreadManager-owned client, which also often requires a downcast. Any opinions about this?
Re comment #3: That is a fine pattern, as long as the handler has clear ownership and is clearly destroyed before DBusThreadManager (which is a better pattern in general, but may be challenging for classes that are global singletons or owned by global singletons).

Status: Assigned (was: Untriaged)
Labels: Pri-2

Sign in to add a comment