Chromium Code Reviews| 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" |
| 11 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 11 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
| 12 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" | 12 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" |
| 13 | 13 |
| 14 class Profile; | 14 class Profile; |
| 15 class RefcountedProfileKeyedService; | 15 class RefcountedProfileKeyedService; |
| 16 | 16 |
| 17 // A specialized ProfileKeyedServiceFactory that manages a | 17 // A specialized ProfileKeyedServiceFactory that manages a |
| 18 // RefcountedThreadSafe<>. | 18 // RefcountedThreadSafe<>. |
| 19 // | 19 // |
| 20 // While the factory returns RefcountedThreadSafe<>s, the factory itself is a | 20 // While the factory returns RefcountedThreadSafe<>s, the factory itself is a |
| 21 // base::NotThreadSafe. Only call methods on this object on the UI thread. | 21 // base::NotThreadSafe. Only call methods on this object on the UI thread. |
| 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: | |
| 28 // A function that replaces the (possibly internal) object used by this | |
| 29 // 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
| |
| 30 typedef scoped_refptr<RefcountedProfileKeyedService> | |
| 31 (*FactoryFunction)(Profile* profile); | |
| 32 | |
| 33 // Associates |factory| with |profile| so that |factory| is used to create | |
| 34 // the ProfileKeyedService when requested. | |
| 35 // | |
|
Miranda Callahan
2012/03/15 16:55:35
nit: remove blank line.
| |
| 36 // |factory| can be NULL to signal that ProfileKeyedService should be NULL. A | |
| 37 // 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 "
| |
| 38 // changed AND an instance of the PKSF already exists for |profile|, that | |
| 39 // service is destroyed. | |
| 40 void SetTestingFactory(Profile* profile, FactoryFunction factory); | |
| 41 | |
| 42 // Associates |factory| with |profile| and immediately returns the created | |
| 43 // ProfileKeyedService. Since the factory will be used immediately, it may | |
| 44 // not be NULL; | |
|
Miranda Callahan
2012/03/15 16:55:35
nit: s/;/./
| |
| 45 scoped_refptr<RefcountedProfileKeyedService> SetTestingFactoryAndUse( | |
| 46 Profile* profile, | |
| 47 FactoryFunction factory); | |
| 48 | |
| 27 protected: | 49 protected: |
| 28 RefcountedProfileKeyedServiceFactory(const char* name, | 50 RefcountedProfileKeyedServiceFactory(const char* name, |
| 29 ProfileDependencyManager* manager); | 51 ProfileDependencyManager* manager); |
| 30 virtual ~RefcountedProfileKeyedServiceFactory(); | 52 virtual ~RefcountedProfileKeyedServiceFactory(); |
| 31 | 53 |
| 54 scoped_refptr<RefcountedProfileKeyedService> GetServiceForProfile( | |
| 55 Profile* profile, | |
| 56 bool create); | |
| 57 | |
| 32 // All subclasses of RefcountedProfileKeyedServiceFactory must return a | 58 // All subclasses of RefcountedProfileKeyedServiceFactory must return a |
| 33 // RefcountedProfileKeyedService instead of just a ProfileKeyedBase. | 59 // RefcountedProfileKeyedService instead of just a ProfileKeyedBase. |
| 34 virtual RefcountedProfileKeyedService* BuildServiceInstanceFor( | 60 virtual scoped_refptr<RefcountedProfileKeyedService> BuildServiceInstanceFor( |
| 35 Profile* profile) const = 0; | 61 Profile* profile) const = 0; |
| 36 | 62 |
| 37 virtual void Associate(Profile* profile, | |
| 38 ProfileKeyedBase* base) OVERRIDE; | |
| 39 virtual bool GetAssociation(Profile* profile, | |
| 40 ProfileKeyedBase** out) const OVERRIDE; | |
| 41 virtual void ProfileShutdown(Profile* profile) OVERRIDE; | 63 virtual void ProfileShutdown(Profile* profile) OVERRIDE; |
| 42 virtual void ProfileDestroyed(Profile* profile) OVERRIDE; | 64 virtual void ProfileDestroyed(Profile* profile) OVERRIDE; |
| 65 virtual void SetEmptyTestingFactory(Profile* profile) OVERRIDE; | |
| 66 virtual void CreateServiceNow(Profile* profile) OVERRIDE; | |
| 43 | 67 |
| 44 private: | 68 private: |
| 45 typedef std::map<Profile*, scoped_refptr<RefcountedProfileKeyedService> > | 69 typedef std::map<Profile*, scoped_refptr<RefcountedProfileKeyedService> > |
| 46 RefCountedStorage; | 70 RefCountedStorage; |
| 47 | 71 |
| 48 // The mapping between a Profile and its refcounted service. | 72 // The mapping between a Profile and its refcounted service. |
| 49 RefCountedStorage mapping_; | 73 RefCountedStorage mapping_; |
| 50 | 74 |
| 75 // The mapping between a Profile and its overridden FactoryFunction. | |
| 76 std::map<Profile*, FactoryFunction> factories_; | |
| 77 | |
| 51 DISALLOW_COPY_AND_ASSIGN(RefcountedProfileKeyedServiceFactory); | 78 DISALLOW_COPY_AND_ASSIGN(RefcountedProfileKeyedServiceFactory); |
| 52 }; | 79 }; |
| 53 | 80 |
| 54 #endif // CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_FACTORY_H_ | 81 #endif // CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_FACTORY_H_ |
| OLD | NEW |