| 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 // It is not guaranteed that this notification is processed synchronously. | |
| 103 // If extensions live on another thread, the notification is posted. | |
| 104 void OnExtensionUnloaded(const std::string& extension_id); | |
| 105 | |
| 106 // Implementation of content::NotificationObserver. | 102 // Implementation of content::NotificationObserver. |
| 107 virtual void Observe(int type, | 103 virtual void Observe(int type, |
| 108 const content::NotificationSource& source, | 104 const content::NotificationSource& source, |
| 109 const content::NotificationDetails& details) OVERRIDE; | 105 const content::NotificationDetails& details) OVERRIDE; |
| 110 | 106 |
| 107 // Iterates over all registries, and calls |notification_callback| on them |
| 108 // with |extension_id| as the argument. If a registry lives on a different |
| 109 // thread, the call is posted to that thread, so no guarantee of synchronous |
| 110 // processing. |
| 111 void NotifyRegistriesHelper( |
| 112 void (RulesRegistry::*notification_callback)(const std::string&), |
| 113 const std::string& extension_id); |
| 114 |
| 111 // ProfileKeyedAPI implementation. | 115 // ProfileKeyedAPI implementation. |
| 112 static const char* service_name() { | 116 static const char* service_name() { |
| 113 return "RulesRegistryService"; | 117 return "RulesRegistryService"; |
| 114 } | 118 } |
| 115 static const bool kServiceHasOwnInstanceInIncognito = true; | 119 static const bool kServiceHasOwnInstanceInIncognito = true; |
| 116 static const bool kServiceIsNULLWhileTesting = true; | 120 static const bool kServiceIsNULLWhileTesting = true; |
| 117 | 121 |
| 118 RulesRegistryMap rule_registries_; | 122 RulesRegistryMap rule_registries_; |
| 119 | 123 |
| 120 // We own the parts of the registries which need to run on the UI thread. | 124 // We own the parts of the registries which need to run on the UI thread. |
| 121 ScopedVector<RulesCacheDelegate> cache_delegates_; | 125 ScopedVector<RulesCacheDelegate> cache_delegates_; |
| 122 | 126 |
| 123 // Weak pointer into rule_registries_ to make it easier to handle content rule | 127 // Weak pointer into rule_registries_ to make it easier to handle content rule |
| 124 // conditions. | 128 // conditions. |
| 125 ContentRulesRegistry* content_rules_registry_; | 129 ContentRulesRegistry* content_rules_registry_; |
| 126 | 130 |
| 127 content::NotificationRegistrar registrar_; | 131 content::NotificationRegistrar registrar_; |
| 128 | 132 |
| 129 Profile* profile_; | 133 Profile* profile_; |
| 130 | 134 |
| 131 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); | 135 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); |
| 132 }; | 136 }; |
| 133 | 137 |
| 134 } // namespace extensions | 138 } // namespace extensions |
| 135 | 139 |
| 136 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ | 140 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |
| OLD | NEW |