Fix build break
[chromium-blink-merge.git] / chrome / browser / profiles / profile_dependency_manager.h
blob50a76d56d7655a8d1f5fded8195a77b6edab0ba5
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_
6 #define CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_
8 #include "base/memory/singleton.h"
9 #include "chrome/browser/profiles/dependency_graph.h"
11 #ifndef NDEBUG
12 #include <set>
13 #endif
15 class Profile;
16 class ProfileKeyedBaseFactory;
18 // A singleton that listens for profile destruction notifications and
19 // rebroadcasts them to each ProfileKeyedBaseFactory in a safe order based
20 // on the stated dependencies by each service.
21 class ProfileDependencyManager {
22 public:
23 // Adds/Removes a component from our list of live components. Removing will
24 // also remove live dependency links.
25 void AddComponent(ProfileKeyedBaseFactory* component);
26 void RemoveComponent(ProfileKeyedBaseFactory* component);
28 // Adds a dependency between two factories.
29 void AddEdge(ProfileKeyedBaseFactory* depended,
30 ProfileKeyedBaseFactory* dependee);
32 // 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
34 // done at this time. (If you want your ProfileKeyedService to be started
35 // with the Profile, override ProfileKeyedBaseFactory::
36 // ServiceIsCreatedWithProfile() to return true.)
37 void CreateProfileServices(Profile* profile, bool is_testing_profile);
39 // Called by each Profile to alert us that we should destroy services
40 // associated with it.
42 // Why not use the existing PROFILE_DESTROYED notification?
44 // - Because we need to do everything here after the application has handled
45 // being notified about PROFILE_DESTROYED.
46 // - Because this class is a singleton and Singletons can't rely on
47 // NotificationService in unit tests because NotificationService is
48 // replaced in many tests.
49 void DestroyProfileServices(Profile* profile);
51 #ifndef NDEBUG
52 // Debugging assertion called as part of GetServiceForProfile in debug
53 // mode. This will NOTREACHED() whenever the user is trying to access a stale
54 // Profile*.
55 void AssertProfileWasntDestroyed(Profile* profile);
56 #endif
58 static ProfileDependencyManager* GetInstance();
60 private:
61 friend class ProfileDependencyManagerUnittests;
62 friend struct DefaultSingletonTraits<ProfileDependencyManager>;
64 ProfileDependencyManager();
65 virtual ~ProfileDependencyManager();
67 // Ensures that all the factories have been created before building the
68 // dependency graph.
69 void AssertFactoriesBuilt();
71 #ifndef NDEBUG
72 void DumpProfileDependencies(Profile* profile);
73 #endif
75 // Whether AssertFactoriesBuilt has been done.
76 bool built_factories_;
78 DependencyGraph dependency_graph_;
80 #ifndef NDEBUG
81 // 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
83 // locations in memory so we can nicely assert if we're asked to do anything
84 // with them.
85 std::set<Profile*> dead_profile_pointers_;
86 #endif
89 #endif // CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_