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

Side by Side Diff: chrome/browser/profiles/profile_dependency_manager.h

Issue 14967003: Drop more dependencies of ProfileKeyedService infrastructure on chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: trybots Created 7 years, 7 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_PROFILE_DEPENDENCY_MANAGER_H_ 5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_
6 #define CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_ 6 #define CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_
7 7
8 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
9 #include "chrome/browser/profiles/dependency_graph.h" 9 #include "chrome/browser/profiles/dependency_graph.h"
10 10
11 #ifndef NDEBUG 11 #ifndef NDEBUG
12 #include <set> 12 #include <set>
13 #endif 13 #endif
14 14
15 class Profile;
16 class ProfileKeyedBaseFactory; 15 class ProfileKeyedBaseFactory;
17 16
17 namespace content {
18 class BrowserContext;
19 }
20
18 // A singleton that listens for profile destruction notifications and 21 // A singleton that listens for profile destruction notifications and
19 // rebroadcasts them to each ProfileKeyedBaseFactory in a safe order based 22 // rebroadcasts them to each ProfileKeyedBaseFactory in a safe order based
20 // on the stated dependencies by each service. 23 // on the stated dependencies by each service.
21 class ProfileDependencyManager { 24 class ProfileDependencyManager {
22 public: 25 public:
23 // Adds/Removes a component from our list of live components. Removing will 26 // Adds/Removes a component from our list of live components. Removing will
24 // also remove live dependency links. 27 // also remove live dependency links.
25 void AddComponent(ProfileKeyedBaseFactory* component); 28 void AddComponent(ProfileKeyedBaseFactory* component);
26 void RemoveComponent(ProfileKeyedBaseFactory* component); 29 void RemoveComponent(ProfileKeyedBaseFactory* component);
27 30
28 // Adds a dependency between two factories. 31 // Adds a dependency between two factories.
29 void AddEdge(ProfileKeyedBaseFactory* depended, 32 void AddEdge(ProfileKeyedBaseFactory* depended,
30 ProfileKeyedBaseFactory* dependee); 33 ProfileKeyedBaseFactory* dependee);
31 34
32 // Called by each Profile to alert us of its creation. Several services want 35 // Called by each Profile to alert us of its creation. Several services want
33 // to be started when a profile is created. Testing configuration is also 36 // to be started when a profile is created. Testing configuration is also
34 // done at this time. (If you want your ProfileKeyedService to be started 37 // done at this time. (If you want your ProfileKeyedService to be started
35 // with the Profile, override ProfileKeyedBaseFactory:: 38 // with the Profile, override ProfileKeyedBaseFactory::
36 // ServiceIsCreatedWithProfile() to return true.) 39 // ServiceIsCreatedWithProfile() to return true.)
37 void CreateProfileServices(Profile* profile, bool is_testing_profile); 40 void CreateProfileServices(content::BrowserContext* profile,
41 bool is_testing_profile);
38 42
39 // Called by each Profile to alert us that we should destroy services 43 // Called by each Profile to alert us that we should destroy services
40 // associated with it. 44 // associated with it.
41 // 45 //
42 // Why not use the existing PROFILE_DESTROYED notification? 46 // Why not use the existing PROFILE_DESTROYED notification?
43 // 47 //
44 // - Because we need to do everything here after the application has handled 48 // - Because we need to do everything here after the application has handled
45 // being notified about PROFILE_DESTROYED. 49 // being notified about PROFILE_DESTROYED.
46 // - Because this class is a singleton and Singletons can't rely on 50 // - Because this class is a singleton and Singletons can't rely on
47 // NotificationService in unit tests because NotificationService is 51 // NotificationService in unit tests because NotificationService is
48 // replaced in many tests. 52 // replaced in many tests.
49 void DestroyProfileServices(Profile* profile); 53 void DestroyProfileServices(content::BrowserContext* profile);
50 54
51 #ifndef NDEBUG 55 #ifndef NDEBUG
52 // Debugging assertion called as part of GetServiceForProfile in debug 56 // Debugging assertion called as part of GetServiceForProfile in debug
53 // mode. This will NOTREACHED() whenever the user is trying to access a stale 57 // mode. This will NOTREACHED() whenever the user is trying to access a stale
54 // Profile*. 58 // Profile*.
55 void AssertProfileWasntDestroyed(Profile* profile); 59 void AssertProfileWasntDestroyed(content::BrowserContext* profile);
56 #endif 60 #endif
57 61
58 static ProfileDependencyManager* GetInstance(); 62 static ProfileDependencyManager* GetInstance();
59 63
60 private: 64 private:
61 friend class ProfileDependencyManagerUnittests; 65 friend class ProfileDependencyManagerUnittests;
62 friend struct DefaultSingletonTraits<ProfileDependencyManager>; 66 friend struct DefaultSingletonTraits<ProfileDependencyManager>;
63 67
64 ProfileDependencyManager(); 68 ProfileDependencyManager();
65 virtual ~ProfileDependencyManager(); 69 virtual ~ProfileDependencyManager();
66 70
67 // Ensures that all the factories have been created before building the
68 // dependency graph.
69 void AssertFactoriesBuilt();
70
71 #ifndef NDEBUG 71 #ifndef NDEBUG
72 void DumpProfileDependencies(Profile* profile); 72 void DumpProfileDependencies(content::BrowserContext* profile);
73 #endif 73 #endif
74 74
75 // Whether AssertFactoriesBuilt has been done.
76 bool built_factories_;
77
78 DependencyGraph dependency_graph_; 75 DependencyGraph dependency_graph_;
79 76
80 #ifndef NDEBUG 77 #ifndef NDEBUG
81 // A list of profile objects that have gone through the Shutdown() 78 // A list of profile objects that have gone through the Shutdown()
82 // phase. These pointers are most likely invalid, but we keep track of their 79 // phase. These pointers are most likely invalid, but we keep track of their
83 // locations in memory so we can nicely assert if we're asked to do anything 80 // locations in memory so we can nicely assert if we're asked to do anything
84 // with them. 81 // with them.
85 std::set<Profile*> dead_profile_pointers_; 82 std::set<content::BrowserContext*> dead_profile_pointers_;
86 #endif 83 #endif
87 }; 84 };
88 85
89 #endif // CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_ 86 #endif // CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698