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

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: Forgot to save a file. >_< 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..cac29d61a0f2050081a2f7fcb430516cf3fa1806 100644
--- a/chrome/browser/profiles/refcounted_profile_keyed_service_factory.h
+++ b/chrome/browser/profiles/refcounted_profile_keyed_service_factory.h
@@ -24,22 +24,48 @@ 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 supplies the instance of a ProfileKeyedService for a given
+ // Profile. This is used primarily for testing, where we want to feed a
+ // specific mock into the PKSF system.
+ typedef scoped_refptr<RefcountedProfileKeyedService>
+ (*FactoryFunction)(Profile* profile);
+
+ // Associates |factory| with |profile| so that |factory| is used to create
+ // the ProfileKeyedService when requested. |factory| can be NULL to signal
+ // that ProfileKeyedService should be NULL. Multiple calls to
+ // SetTestingFactory() are allowed; previous services will be shut down.
+ 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.
+ 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);
+
+ // Maps |profile| to |service| with debug checks to prevent duplication.
+ void Associate(Profile* profile,
+ const scoped_refptr<RefcountedProfileKeyedService>& service);
+
// 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 +74,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