| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_ |
| 6 #define CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/memory/singleton.h" |
| 12 #include "content/common/notification_observer.h" |
| 13 #include "content/common/notification_registrar.h" |
| 14 |
| 15 class ProfileKeyedServiceFactory; |
| 16 |
| 17 // A singleton that listens for profile destruction notifications and |
| 18 // rebroadcasts them to each ProfileKeyedServiceFactory in a safe order based |
| 19 // on the stated dependencies by each service. |
| 20 class ProfileDependencyManager : public NotificationObserver { |
| 21 public: |
| 22 void AddComponent(ProfileKeyedServiceFactory* component); |
| 23 void RemoveComponent(ProfileKeyedServiceFactory* component); |
| 24 |
| 25 void AddEdge(ProfileKeyedServiceFactory* depended, |
| 26 ProfileKeyedServiceFactory* dependee); |
| 27 |
| 28 static ProfileDependencyManager* GetInstance(); |
| 29 |
| 30 private: |
| 31 friend class ProfileDependencyManagerUnittests; |
| 32 friend struct DefaultSingletonTraits<ProfileDependencyManager>; |
| 33 |
| 34 typedef std::multimap<ProfileKeyedServiceFactory*, |
| 35 ProfileKeyedServiceFactory*> EdgeMap; |
| 36 |
| 37 ProfileDependencyManager(); |
| 38 virtual ~ProfileDependencyManager(); |
| 39 |
| 40 // Using the dependency graph defined in |edges_|, fills |destruction_order_| |
| 41 // so that Observe() can notify each ProfileKeyedServiceFactory in order. |
| 42 void BuildDestructionOrder(); |
| 43 |
| 44 // NotificationObserver: |
| 45 virtual void Observe(NotificationType type, |
| 46 const NotificationSource& source, |
| 47 const NotificationDetails& details); |
| 48 |
| 49 std::vector<ProfileKeyedServiceFactory*> all_components_; |
| 50 |
| 51 EdgeMap edges_; |
| 52 |
| 53 std::vector<ProfileKeyedServiceFactory*> destruction_order_; |
| 54 |
| 55 NotificationRegistrar registrar_; |
| 56 }; |
| 57 |
| 58 #endif // CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_ |
| OLD | NEW |