When using ProfileKeyedServiceFactory, I have had trouble trying to
make the Profile only hold a shared pointer to my service.
ProfileKeyedServiceFactory doesn't seem to like shared pointer as it
just deletes the service in
ProfileKeyedServiceFactory::ProfileDestroyed with delete.
To work around this, I've ended up creating a wrapper FooWrapper which
holds a shared pointer to my service Foo, and making FooWrapper a
ProfileKeyedService.
E.g.,
chrome/browser/content_settings/cookie_settings.h
contains such a wrapper (at the bottom).
This is clumsy. Am I doing it wrong? Or should
ProfileKeyedServiceFactory be adapted to allow this kind of usage,
too?
BR,
Marja
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
That's because generally this isn't safe :)
> To work around this, I've ended up creating a wrapper FooWrapper which
> holds a shared pointer to my service Foo, and making FooWrapper a
> ProfileKeyedService.
>
> E.g.,
> chrome/browser/content_settings/cookie_settings.h
> contains such a wrapper (at the bottom).
>
> This is clumsy. Am I doing it wrong? Or should
> ProfileKeyedServiceFactory be adapted to allow this kind of usage,
> too?
This looks unsafe to me (though I may be wrong) - your service has a
pointer to the profile's PrefService, no? This pointer will become
dangling once the profile is destroyed.
In other cases where profile services have been refcounted, we have
found that this behaviour was already unsafe (could theoretically
result in accessing a deleted Profile) and have reworked the services
not to be reference counted instead.
--
Torne (Richard Coles)
to...@google.com
Agreed. In general, trying to share ownership of something tied to the
Profile has historically been error prone. We've had numerous shutdown
crashes because an object has tried to access a deleted
Profile/PrefService/Other thing tied to Profile that's already been
shut down.
After an admittedly quick skim of cookie_settings.{cc,h}, I can't
convince myself that what's going on here is safe.
-- Elliot
CookieSettingsWrapper::Shutdown calls
CookieSettings::ShutdownOnUIThread, which drops all references to the
Profile. CookieSettings in general can be accessed from any thread, so
it doesn't even directly use the Profile, it just listens to pref
change notifications.
Bernhard.
> -- Elliot
I'd be more confident of this if PrefChangeRegistrar::RemoveAll (or
probably a new method for this task) also NULLed out the PrefService*
pointer. (I'm being pedantic now; I'm just a bit worried about the
possibility of re Add()ing new preferences.)
-- Elliot
-- Elliot
On Fri, Jan 13, 2012 at 10:44, Miranda Callahan <mira...@google.com> wrote:
> On Fri, Jan 13, 2012 at 01:18, Drew Wilson <atwi...@chromium.org> wrote:
>> Speaking of preferences, it looks like when using TestingProfile,
>> ProfileDependencyManager doesn't call RegisterUserPrefs() on the various
>> services, leaving us with a profile without all of our prefs registered.
I think that this decision was made mainly to allow the TestingProfile
to insert its own PrefService.
Maybe instead of just outright not registering user prefs for any
testing profile, we can pass an argument when creating the
TestingProfile to determine whether or not it's going to be using a
separate PrefService? Then we can just ask the TestingProfile whether
it wants to handle its own user prefs registration or not in the
ProfileDependencyManager.
(once more, with feeling)
On Fri, Jan 13, 2012 at 10:44, Miranda Callahan <mira...@google.com> wrote:
> On Fri, Jan 13, 2012 at 01:18, Drew Wilson <atwi...@chromium.org> wrote:
>> Speaking of preferences, it looks like when using TestingProfile,
>> ProfileDependencyManager doesn't call RegisterUserPrefs() on the various
>> services, leaving us with a profile without all of our prefs registered.
I think that this decision was made mainly to allow the TestingProfile
to insert its own PrefService.
Maybe instead of just outright not registering user prefs for any
testing profile, we can pass an argument when creating the
TestingProfile to determine whether or not it's going to be using a
separate PrefService? Then we can just ask the TestingProfile whether
it wants to handle its own user prefs registration or not in the
ProfileDependencyManager.
IIRC, I thought the opposite, though I guess it's likely that the set
of services that I was converting weren't representative of chrome as
a whole.
> I think it's not bad to just do the RegisterUserPrefs always - if we then
> throw out that PrefService because we're swapping in a new one, then the
> caller can just register them again with the new PrefService.
>
> After talking with Miranda about this, I'm going to move forward with a
> patch that registers prefs from TestingProfile also - I did this last night
> and it seems to be working (mostly :). I'll be sure to include both Miranda
> and Elliot on the review.
My memory is fuzzy, but I think I put all my knowledge about what I
used to know about this in the comment in
ProfileKeyedServiceFactory::RegisterUserPrefsOnProfile(). Good luck
doing this.
-- Elliot