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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 supplies the instance of a ProfileKeyedService for a given
29 // Profile. This is used primarily for testing, where we want to feed a
30 // specific mock into the PKSF system.
31 typedef scoped_refptr<RefcountedProfileKeyedService>
32 (*FactoryFunction)(Profile* profile);
33
34 // Associates |factory| with |profile| so that |factory| is used to create
35 // the ProfileKeyedService when requested. |factory| can be NULL to signal
36 // that ProfileKeyedService should be NULL. Multiple calls to
37 // SetTestingFactory() are allowed; previous services will be shut down.
38 void SetTestingFactory(Profile* profile, FactoryFunction factory);
39
40 // Associates |factory| with |profile| and immediately returns the created
41 // ProfileKeyedService. Since the factory will be used immediately, it may
42 // not be NULL.
43 scoped_refptr<RefcountedProfileKeyedService> SetTestingFactoryAndUse(
44 Profile* profile,
45 FactoryFunction factory);
46
27 protected: 47 protected:
28 RefcountedProfileKeyedServiceFactory(const char* name, 48 RefcountedProfileKeyedServiceFactory(const char* name,
29 ProfileDependencyManager* manager); 49 ProfileDependencyManager* manager);
30 virtual ~RefcountedProfileKeyedServiceFactory(); 50 virtual ~RefcountedProfileKeyedServiceFactory();
31 51
52 scoped_refptr<RefcountedProfileKeyedService> GetServiceForProfile(
53 Profile* profile,
54 bool create);
55
56 // Maps |profile| to |service| with debug checks to prevent duplication.
57 void Associate(Profile* profile,
58 const scoped_refptr<RefcountedProfileKeyedService>& service);
59
32 // All subclasses of RefcountedProfileKeyedServiceFactory must return a 60 // All subclasses of RefcountedProfileKeyedServiceFactory must return a
33 // RefcountedProfileKeyedService instead of just a ProfileKeyedBase. 61 // RefcountedProfileKeyedService instead of just a ProfileKeyedBase.
34 virtual RefcountedProfileKeyedService* BuildServiceInstanceFor( 62 virtual scoped_refptr<RefcountedProfileKeyedService> BuildServiceInstanceFor(
35 Profile* profile) const = 0; 63 Profile* profile) const = 0;
36 64
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; 65 virtual void ProfileShutdown(Profile* profile) OVERRIDE;
42 virtual void ProfileDestroyed(Profile* profile) OVERRIDE; 66 virtual void ProfileDestroyed(Profile* profile) OVERRIDE;
67 virtual void SetEmptyTestingFactory(Profile* profile) OVERRIDE;
68 virtual void CreateServiceNow(Profile* profile) OVERRIDE;
43 69
44 private: 70 private:
45 typedef std::map<Profile*, scoped_refptr<RefcountedProfileKeyedService> > 71 typedef std::map<Profile*, scoped_refptr<RefcountedProfileKeyedService> >
46 RefCountedStorage; 72 RefCountedStorage;
47 73
48 // The mapping between a Profile and its refcounted service. 74 // The mapping between a Profile and its refcounted service.
49 RefCountedStorage mapping_; 75 RefCountedStorage mapping_;
50 76
77 // The mapping between a Profile and its overridden FactoryFunction.
78 std::map<Profile*, FactoryFunction> factories_;
79
51 DISALLOW_COPY_AND_ASSIGN(RefcountedProfileKeyedServiceFactory); 80 DISALLOW_COPY_AND_ASSIGN(RefcountedProfileKeyedServiceFactory);
52 }; 81 };
53 82
54 #endif // CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_FACTORY_H_ 83 #endif // CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698