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, FactoryFunction facto
ry); |
39 | 39 |
40 // Associates |factory| with |profile| and immediately returns the created | 40 // Associates |factory| with |profile| and immediately returns the created |
41 // ProfileKeyedService. Since the factory will be used immediately, it may | 41 // ProfileKeyedService. Since the factory will be used immediately, it may |
42 // not be NULL. | 42 // not be NULL. |
43 scoped_refptr<RefcountedProfileKeyedService> SetTestingFactoryAndUse( | 43 scoped_refptr<RefcountedProfileKeyedService> SetTestingFactoryAndUse( |
44 Profile* profile, | 44 content::BrowserContext* profile, |
45 FactoryFunction factory); | 45 FactoryFunction factory); |
46 | 46 |
47 protected: | 47 protected: |
48 RefcountedProfileKeyedServiceFactory(const char* name, | 48 RefcountedProfileKeyedServiceFactory(const char* name, |
49 ProfileDependencyManager* manager); | 49 ProfileDependencyManager* manager); |
50 virtual ~RefcountedProfileKeyedServiceFactory(); | 50 virtual ~RefcountedProfileKeyedServiceFactory(); |
51 | 51 |
52 scoped_refptr<RefcountedProfileKeyedService> GetServiceForProfile( | 52 scoped_refptr<RefcountedProfileKeyedService> GetServiceForProfile( |
53 Profile* profile, | 53 content::BrowserContext* profile, |
54 bool create); | 54 bool create); |
55 | 55 |
56 // Maps |profile| to |service| with debug checks to prevent duplication. | 56 // Maps |profile| to |service| with debug checks to prevent duplication. |
57 void Associate(Profile* profile, | 57 void Associate(content::BrowserContext* profile, |
58 const scoped_refptr<RefcountedProfileKeyedService>& service); | 58 const scoped_refptr<RefcountedProfileKeyedService>& service); |
59 | 59 |
60 // All subclasses of RefcountedProfileKeyedServiceFactory must return a | 60 // All subclasses of RefcountedProfileKeyedServiceFactory must return a |
61 // RefcountedProfileKeyedService instead of just a ProfileKeyedBase. | 61 // RefcountedProfileKeyedService instead of just a ProfileKeyedBase. |
62 virtual scoped_refptr<RefcountedProfileKeyedService> BuildServiceInstanceFor( | 62 virtual scoped_refptr<RefcountedProfileKeyedService> BuildServiceInstanceFor( |
63 Profile* profile) const = 0; | 63 content::BrowserContext* profile) const = 0; |
64 | 64 |
65 virtual void ProfileShutdown(Profile* profile) OVERRIDE; | 65 virtual void ProfileShutdown(content::BrowserContext* profile) OVERRIDE; |
66 virtual void ProfileDestroyed(Profile* profile) OVERRIDE; | 66 virtual void ProfileDestroyed(content::BrowserContext* profile) OVERRIDE; |
67 virtual void SetEmptyTestingFactory(Profile* profile) OVERRIDE; | 67 virtual void SetEmptyTestingFactory(content::BrowserContext* profile) OVERRIDE
; |
68 virtual void CreateServiceNow(Profile* profile) OVERRIDE; | 68 virtual void CreateServiceNow(content::BrowserContext* profile) OVERRIDE; |
69 | 69 |
70 private: | 70 private: |
71 typedef std::map<Profile*, scoped_refptr<RefcountedProfileKeyedService> > | 71 typedef std::map<content::BrowserContext*, |
| 72 scoped_refptr<RefcountedProfileKeyedService> > |
72 RefCountedStorage; | 73 RefCountedStorage; |
73 typedef std::map<Profile*, FactoryFunction> ProfileOverriddenFunctions; | 74 typedef std::map<content::BrowserContext*, |
| 75 FactoryFunction> ProfileOverriddenFunctions; |
74 | 76 |
75 // The mapping between a Profile and its refcounted service. | 77 // The mapping between a Profile and its refcounted service. |
76 RefCountedStorage mapping_; | 78 RefCountedStorage mapping_; |
77 | 79 |
78 // The mapping between a Profile and its overridden FactoryFunction. | 80 // The mapping between a Profile and its overridden FactoryFunction. |
79 ProfileOverriddenFunctions factories_; | 81 ProfileOverriddenFunctions factories_; |
80 | 82 |
81 DISALLOW_COPY_AND_ASSIGN(RefcountedProfileKeyedServiceFactory); | 83 DISALLOW_COPY_AND_ASSIGN(RefcountedProfileKeyedServiceFactory); |
82 }; | 84 }; |
83 | 85 |
84 #endif // CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_FACTORY_H_ | 86 #endif // CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_FACTORY_H_ |
OLD | NEW |