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_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
14 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
15 | 15 |
16 class Profile; | 16 class Profile; |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 class NotificationSource; | 19 class NotificationSource; |
20 class NotificationSource; | 20 class NotificationSource; |
21 } | 21 } |
22 | 22 |
23 namespace extensions { | 23 namespace extensions { |
| 24 class ContentRulesRegistry; |
24 class RulesRegistry; | 25 class RulesRegistry; |
25 class RulesRegistryStorageDelegate; | 26 class RulesRegistryStorageDelegate; |
26 } | 27 } |
27 | 28 |
28 namespace extensions { | 29 namespace extensions { |
29 | 30 |
30 // This class owns all RulesRegistries implementations of an ExtensionService. | 31 // This class owns all RulesRegistries implementations of an ExtensionService. |
31 // This class lives on the UI thread. | 32 // This class lives on the UI thread. |
32 class RulesRegistryService : public content::NotificationObserver { | 33 class RulesRegistryService : public content::NotificationObserver { |
33 public: | 34 public: |
34 explicit RulesRegistryService(Profile* profile); | 35 explicit RulesRegistryService(Profile* profile); |
35 virtual ~RulesRegistryService(); | 36 virtual ~RulesRegistryService(); |
36 | 37 |
37 // Unregisters refptrs to concrete RulesRegistries at other objects that were | 38 // Unregisters refptrs to concrete RulesRegistries at other objects that were |
38 // created by us so that the RulesRegistries can be released. | 39 // created by us so that the RulesRegistries can be released. |
39 void Shutdown(); | 40 void Shutdown(); |
40 | 41 |
41 // Registers the default RulesRegistries used in Chromium. | 42 // Registers the default RulesRegistries used in Chromium. |
42 void RegisterDefaultRulesRegistries(); | 43 void RegisterDefaultRulesRegistries(); |
43 | 44 |
44 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry. | 45 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry. |
45 void RegisterRulesRegistry(const std::string& event_name, | 46 void RegisterRulesRegistry(const std::string& event_name, |
46 scoped_refptr<RulesRegistry> rule_registry); | 47 scoped_refptr<RulesRegistry> rule_registry); |
47 | 48 |
48 // Returns the RulesRegistry for |event_name| or NULL if no such registry | 49 // Returns the RulesRegistry for |event_name| or NULL if no such registry |
49 // has been registered. | 50 // has been registered. |
50 scoped_refptr<RulesRegistry> GetRulesRegistry( | 51 scoped_refptr<RulesRegistry> GetRulesRegistry( |
51 const std::string& event_name) const; | 52 const std::string& event_name) const; |
52 | 53 |
| 54 // Accessors for each type of rules registry. |
| 55 ContentRulesRegistry* content_rules_registry() const { |
| 56 return content_rules_registry_; |
| 57 } |
| 58 |
53 // For testing. | 59 // For testing. |
54 void SimulateExtensionUnloaded(const std::string& extension_id); | 60 void SimulateExtensionUnloaded(const std::string& extension_id); |
55 private: | 61 private: |
56 // Maps event names to RuleRegistries that handle these events. | 62 // Maps event names to RuleRegistries that handle these events. |
57 typedef std::map<std::string, scoped_refptr<RulesRegistry> > RulesRegistryMap; | 63 typedef std::map<std::string, scoped_refptr<RulesRegistry> > RulesRegistryMap; |
58 | 64 |
59 // Notifies all RulesRegistries that |extension_id| was unloaded. | 65 // Notifies all RulesRegistries that |extension_id| was unloaded. |
60 // It is not guaranteed that this notification is processed synchronously. | 66 // It is not guaranteed that this notification is processed synchronously. |
61 // If extensions live on another thread, the notification is posted. | 67 // If extensions live on another thread, the notification is posted. |
62 void OnExtensionUnloaded(const std::string& extension_id); | 68 void OnExtensionUnloaded(const std::string& extension_id); |
63 | 69 |
64 // Implementation of content::NotificationObserver. | 70 // Implementation of content::NotificationObserver. |
65 virtual void Observe(int type, | 71 virtual void Observe(int type, |
66 const content::NotificationSource& source, | 72 const content::NotificationSource& source, |
67 const content::NotificationDetails& details) OVERRIDE; | 73 const content::NotificationDetails& details) OVERRIDE; |
68 | 74 |
69 RulesRegistryMap rule_registries_; | 75 RulesRegistryMap rule_registries_; |
70 | 76 |
71 // These are weak pointers to the delegates owned by the RulesRegistry's. We | 77 // These are weak pointers to the delegates owned by the RulesRegistry's. We |
72 // keep track of them so we can tell them to do cleanup on shutdown. | 78 // keep track of them so we can tell them to do cleanup on shutdown. |
73 std::vector<RulesRegistryStorageDelegate*> delegates_; | 79 std::vector<RulesRegistryStorageDelegate*> delegates_; |
74 | 80 |
| 81 // Weak pointer into rule_registries_ to make it easier to handle content rule |
| 82 // conditions. |
| 83 ContentRulesRegistry* content_rules_registry_; |
| 84 |
75 content::NotificationRegistrar registrar_; | 85 content::NotificationRegistrar registrar_; |
76 | 86 |
77 Profile* profile_; | 87 Profile* profile_; |
78 | 88 |
79 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); | 89 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); |
80 }; | 90 }; |
81 | 91 |
82 } // namespace extensions | 92 } // namespace extensions |
83 | 93 |
84 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ | 94 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |
OLD | NEW |