Return scoped_refptr in GetImageLoaderClient |
|||
Issue descriptionmodify 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.
,
Nov 27 2017
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).
,
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?
,
Nov 28 2017
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).
,
Aug 1
,
Nov 14
|
|||
►
Sign in to add a comment |
|||
Comment 1 by xiaochu@chromium.org
, Nov 27 2017