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> |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // Accessors for each type of rules registry. | 82 // Accessors for each type of rules registry. |
83 ContentRulesRegistry* content_rules_registry() const { | 83 ContentRulesRegistry* content_rules_registry() const { |
84 CHECK(content_rules_registry_); | 84 CHECK(content_rules_registry_); |
85 return content_rules_registry_; | 85 return content_rules_registry_; |
86 } | 86 } |
87 | 87 |
88 // Removes all rules registries of a given webview embedder process ID. | 88 // Removes all rules registries of a given webview embedder process ID. |
89 void RemoveWebViewRulesRegistries(int process_id); | 89 void RemoveWebViewRulesRegistries(int process_id); |
90 | 90 |
91 // For testing. | 91 // For testing. |
92 void SimulateExtensionUnloaded(const std::string& extension_id); | 92 void SimulateExtensionUninstalled(const std::string& extension_id); |
| 93 |
93 private: | 94 private: |
94 friend class ProfileKeyedAPIFactory<RulesRegistryService>; | 95 friend class ProfileKeyedAPIFactory<RulesRegistryService>; |
95 | 96 |
96 // Maps <event name, webview key> to RuleRegistries that handle these | 97 // Maps <event name, webview key> to RuleRegistries that handle these |
97 // events. | 98 // events. |
98 typedef std::map<RulesRegistryKey, scoped_refptr<RulesRegistry> > | 99 typedef std::map<RulesRegistryKey, scoped_refptr<RulesRegistry> > |
99 RulesRegistryMap; | 100 RulesRegistryMap; |
100 | 101 |
101 // Notifies all RulesRegistries that |extension_id| was unloaded. | 102 // Notifes all RulesRegistry instances that the availability of |extension_id| |
102 // It is not guaranteed that this notification is processed synchronously. | 103 // has changed. It is not guaranteed that this notification is processed |
103 // If extensions live on another thread, the notification is posted. | 104 // synchronously. If extensions live on another thread, then the notification |
| 105 // is posted. |
| 106 void OnExtensionUninstalled(const std::string& extension_id); |
104 void OnExtensionUnloaded(const std::string& extension_id); | 107 void OnExtensionUnloaded(const std::string& extension_id); |
| 108 void OnExtensionLoaded(const std::string& extension_id); |
105 | 109 |
106 // Implementation of content::NotificationObserver. | 110 // Implementation of content::NotificationObserver. |
107 virtual void Observe(int type, | 111 virtual void Observe(int type, |
108 const content::NotificationSource& source, | 112 const content::NotificationSource& source, |
109 const content::NotificationDetails& details) OVERRIDE; | 113 const content::NotificationDetails& details) OVERRIDE; |
110 | 114 |
| 115 // Iterates over all registries, and calls |notification_callback| on them |
| 116 // with |extension_id| as the argument. If a registry lives on a different |
| 117 // thread, the call is posted to that thread. |
| 118 void NotifyRegistriesHelper( |
| 119 void (RulesRegistry::*notification_callback)(const std::string&), |
| 120 const std::string& extension_id); |
| 121 |
111 // ProfileKeyedAPI implementation. | 122 // ProfileKeyedAPI implementation. |
112 static const char* service_name() { | 123 static const char* service_name() { |
113 return "RulesRegistryService"; | 124 return "RulesRegistryService"; |
114 } | 125 } |
115 static const bool kServiceHasOwnInstanceInIncognito = true; | 126 static const bool kServiceHasOwnInstanceInIncognito = true; |
116 static const bool kServiceIsNULLWhileTesting = true; | 127 static const bool kServiceIsNULLWhileTesting = true; |
117 | 128 |
118 RulesRegistryMap rule_registries_; | 129 RulesRegistryMap rule_registries_; |
119 | 130 |
120 // We own the parts of the registries which need to run on the UI thread. | 131 // We own the parts of the registries which need to run on the UI thread. |
121 ScopedVector<RulesCacheDelegate> cache_delegates_; | 132 ScopedVector<RulesCacheDelegate> cache_delegates_; |
122 | 133 |
123 // Weak pointer into rule_registries_ to make it easier to handle content rule | 134 // Weak pointer into rule_registries_ to make it easier to handle content rule |
124 // conditions. | 135 // conditions. |
125 ContentRulesRegistry* content_rules_registry_; | 136 ContentRulesRegistry* content_rules_registry_; |
126 | 137 |
127 content::NotificationRegistrar registrar_; | 138 content::NotificationRegistrar registrar_; |
128 | 139 |
129 Profile* profile_; | 140 Profile* profile_; |
130 | 141 |
131 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); | 142 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); |
132 }; | 143 }; |
133 | 144 |
134 } // namespace extensions | 145 } // namespace extensions |
135 | 146 |
136 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ | 147 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |
OLD | NEW |