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

Unified Diff: chrome/browser/profiles/refcounted_profile_keyed_service_factory.h

Issue 9703038: Profiles: Really fix refcounted services. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile Created 8 years, 9 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
Index: chrome/browser/profiles/refcounted_profile_keyed_service_factory.h
diff --git a/chrome/browser/profiles/refcounted_profile_keyed_service_factory.h b/chrome/browser/profiles/refcounted_profile_keyed_service_factory.h
index 4e9c1b5c6d59d0bce86e1dac9f8b20b0c72d1ede..bac542691055a967855c629471b61c2b96fb5359 100644
--- a/chrome/browser/profiles/refcounted_profile_keyed_service_factory.h
+++ b/chrome/browser/profiles/refcounted_profile_keyed_service_factory.h
@@ -24,22 +24,46 @@ class RefcountedProfileKeyedService;
// that ShutdownOnUIThread() is called on the UI thread, but actual object
// destruction can happen anywhere.
class RefcountedProfileKeyedServiceFactory : public ProfileKeyedBaseFactory {
+ public:
+ // A function that replaces the (possibly internal) object used by this
+ // factory. For the majority of cases, this is the object returned to users.
Miranda Callahan 2012/03/15 16:55:35 As before: "Shouldn't FactoryFunction be described
+ typedef scoped_refptr<RefcountedProfileKeyedService>
+ (*FactoryFunction)(Profile* profile);
+
+ // Associates |factory| with |profile| so that |factory| is used to create
+ // the ProfileKeyedService when requested.
+ //
Miranda Callahan 2012/03/15 16:55:35 nit: remove blank line.
+ // |factory| can be NULL to signal that ProfileKeyedService should be NULL. A
+ // second call to SetTestingFactory() is allowed. If the FactoryFunction is
Miranda Callahan 2012/03/15 16:55:35 nit as before: instead of "a second call", maybe "
+ // changed AND an instance of the PKSF already exists for |profile|, that
+ // service is destroyed.
+ void SetTestingFactory(Profile* profile, FactoryFunction factory);
+
+ // Associates |factory| with |profile| and immediately returns the created
+ // ProfileKeyedService. Since the factory will be used immediately, it may
+ // not be NULL;
Miranda Callahan 2012/03/15 16:55:35 nit: s/;/./
+ scoped_refptr<RefcountedProfileKeyedService> SetTestingFactoryAndUse(
+ Profile* profile,
+ FactoryFunction factory);
+
protected:
RefcountedProfileKeyedServiceFactory(const char* name,
ProfileDependencyManager* manager);
virtual ~RefcountedProfileKeyedServiceFactory();
+ scoped_refptr<RefcountedProfileKeyedService> GetServiceForProfile(
+ Profile* profile,
+ bool create);
+
// All subclasses of RefcountedProfileKeyedServiceFactory must return a
// RefcountedProfileKeyedService instead of just a ProfileKeyedBase.
- virtual RefcountedProfileKeyedService* BuildServiceInstanceFor(
+ virtual scoped_refptr<RefcountedProfileKeyedService> BuildServiceInstanceFor(
Profile* profile) const = 0;
- virtual void Associate(Profile* profile,
- ProfileKeyedBase* base) OVERRIDE;
- virtual bool GetAssociation(Profile* profile,
- ProfileKeyedBase** out) const OVERRIDE;
virtual void ProfileShutdown(Profile* profile) OVERRIDE;
virtual void ProfileDestroyed(Profile* profile) OVERRIDE;
+ virtual void SetEmptyTestingFactory(Profile* profile) OVERRIDE;
+ virtual void CreateServiceNow(Profile* profile) OVERRIDE;
private:
typedef std::map<Profile*, scoped_refptr<RefcountedProfileKeyedService> >
@@ -48,6 +72,9 @@ class RefcountedProfileKeyedServiceFactory : public ProfileKeyedBaseFactory {
// The mapping between a Profile and its refcounted service.
RefCountedStorage mapping_;
+ // The mapping between a Profile and its overridden FactoryFunction.
+ std::map<Profile*, FactoryFunction> factories_;
+
DISALLOW_COPY_AND_ASSIGN(RefcountedProfileKeyedServiceFactory);
};

Powered by Google App Engine
This is Rietveld 408576698