| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_FACTORY_H_ | 5 #ifndef CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_FACTORY_H_ |
| 6 #define CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_FACTORY_H_ | 6 #define CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_FACTORY_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // | 22 // |
| 23 // Implementers of RefcountedProfileKeyedService should note that we guarantee | 23 // Implementers of RefcountedProfileKeyedService should note that we guarantee |
| 24 // that ShutdownOnUIThread() is called on the UI thread, but actual object | 24 // that ShutdownOnUIThread() is called on the UI thread, but actual object |
| 25 // destruction can happen anywhere. | 25 // destruction can happen anywhere. |
| 26 class RefcountedProfileKeyedServiceFactory : public ProfileKeyedBaseFactory { | 26 class RefcountedProfileKeyedServiceFactory : public ProfileKeyedBaseFactory { |
| 27 public: | 27 public: |
| 28 // A function that supplies the instance of a ProfileKeyedService for a given | 28 // A function that supplies the instance of a ProfileKeyedService for a given |
| 29 // Profile. This is used primarily for testing, where we want to feed a | 29 // Profile. This is used primarily for testing, where we want to feed a |
| 30 // specific mock into the PKSF system. | 30 // specific mock into the PKSF system. |
| 31 typedef scoped_refptr<RefcountedProfileKeyedService> | 31 typedef scoped_refptr<RefcountedProfileKeyedService> |
| 32 (*FactoryFunction)(Profile* profile); | 32 (*FactoryFunction)(content::BrowserContext* profile); |
| 33 | 33 |
| 34 // Associates |factory| with |profile| so that |factory| is used to create | 34 // Associates |factory| with |profile| so that |factory| is used to create |
| 35 // the ProfileKeyedService when requested. |factory| can be NULL to signal | 35 // the ProfileKeyedService when requested. |factory| can be NULL to signal |
| 36 // that ProfileKeyedService should be NULL. Multiple calls to | 36 // that ProfileKeyedService should be NULL. Multiple calls to |
| 37 // SetTestingFactory() are allowed; previous services will be shut down. | 37 // SetTestingFactory() are allowed; previous services will be shut down. |
| 38 void SetTestingFactory(Profile* profile, FactoryFunction factory); | 38 void SetTestingFactory(content::BrowserContext* profile, |
| 39 FactoryFunction factory); |
| 39 | 40 |
| 40 // Associates |factory| with |profile| and immediately returns the created | 41 // Associates |factory| with |profile| and immediately returns the created |
| 41 // ProfileKeyedService. Since the factory will be used immediately, it may | 42 // ProfileKeyedService. Since the factory will be used immediately, it may |
| 42 // not be NULL. | 43 // not be NULL. |
| 43 scoped_refptr<RefcountedProfileKeyedService> SetTestingFactoryAndUse( | 44 scoped_refptr<RefcountedProfileKeyedService> SetTestingFactoryAndUse( |
| 44 Profile* profile, | 45 content::BrowserContext* profile, |
| 45 FactoryFunction factory); | 46 FactoryFunction factory); |
| 46 | 47 |
| 47 protected: | 48 protected: |
| 48 RefcountedProfileKeyedServiceFactory(const char* name, | 49 RefcountedProfileKeyedServiceFactory(const char* name, |
| 49 ProfileDependencyManager* manager); | 50 ProfileDependencyManager* manager); |
| 50 virtual ~RefcountedProfileKeyedServiceFactory(); | 51 virtual ~RefcountedProfileKeyedServiceFactory(); |
| 51 | 52 |
| 52 scoped_refptr<RefcountedProfileKeyedService> GetServiceForProfile( | 53 scoped_refptr<RefcountedProfileKeyedService> GetServiceForProfile( |
| 53 Profile* profile, | 54 content::BrowserContext* profile, |
| 54 bool create); | 55 bool create); |
| 55 | 56 |
| 56 // Maps |profile| to |service| with debug checks to prevent duplication. | 57 // Maps |profile| to |service| with debug checks to prevent duplication. |
| 57 void Associate(Profile* profile, | 58 void Associate(content::BrowserContext* profile, |
| 58 const scoped_refptr<RefcountedProfileKeyedService>& service); | 59 const scoped_refptr<RefcountedProfileKeyedService>& service); |
| 59 | 60 |
| 60 // All subclasses of RefcountedProfileKeyedServiceFactory must return a | 61 // All subclasses of RefcountedProfileKeyedServiceFactory must return a |
| 61 // RefcountedProfileKeyedService instead of just a ProfileKeyedBase. | 62 // RefcountedProfileKeyedService instead of just a ProfileKeyedBase. |
| 62 virtual scoped_refptr<RefcountedProfileKeyedService> BuildServiceInstanceFor( | 63 virtual scoped_refptr<RefcountedProfileKeyedService> BuildServiceInstanceFor( |
| 63 Profile* profile) const = 0; | 64 content::BrowserContext* profile) const = 0; |
| 64 | 65 |
| 65 virtual void ProfileShutdown(Profile* profile) OVERRIDE; | 66 virtual void ProfileShutdown(content::BrowserContext* profile) OVERRIDE; |
| 66 virtual void ProfileDestroyed(Profile* profile) OVERRIDE; | 67 virtual void ProfileDestroyed(content::BrowserContext* profile) OVERRIDE; |
| 67 virtual void SetEmptyTestingFactory(Profile* profile) OVERRIDE; | 68 virtual void SetEmptyTestingFactory( |
| 68 virtual void CreateServiceNow(Profile* profile) OVERRIDE; | 69 content::BrowserContext* profile) OVERRIDE; |
| 70 virtual void CreateServiceNow(content::BrowserContext* profile) OVERRIDE; |
| 69 | 71 |
| 70 private: | 72 private: |
| 71 typedef std::map<Profile*, scoped_refptr<RefcountedProfileKeyedService> > | 73 typedef std::map<content::BrowserContext*, |
| 74 scoped_refptr<RefcountedProfileKeyedService> > |
| 72 RefCountedStorage; | 75 RefCountedStorage; |
| 73 typedef std::map<Profile*, FactoryFunction> ProfileOverriddenFunctions; | 76 typedef std::map<content::BrowserContext*, |
| 77 FactoryFunction> ProfileOverriddenFunctions; |
| 74 | 78 |
| 75 // The mapping between a Profile and its refcounted service. | 79 // The mapping between a Profile and its refcounted service. |
| 76 RefCountedStorage mapping_; | 80 RefCountedStorage mapping_; |
| 77 | 81 |
| 78 // The mapping between a Profile and its overridden FactoryFunction. | 82 // The mapping between a Profile and its overridden FactoryFunction. |
| 79 ProfileOverriddenFunctions factories_; | 83 ProfileOverriddenFunctions factories_; |
| 80 | 84 |
| 81 DISALLOW_COPY_AND_ASSIGN(RefcountedProfileKeyedServiceFactory); | 85 DISALLOW_COPY_AND_ASSIGN(RefcountedProfileKeyedServiceFactory); |
| 82 }; | 86 }; |
| 83 | 87 |
| 84 #endif // CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_FACTORY_H_ | 88 #endif // CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_FACTORY_H_ |
| OLD | NEW |