| 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 20 matching lines...) Expand all Loading... |
| 31 class RulesRegistryStorageDelegate; | 31 class RulesRegistryStorageDelegate; |
| 32 } | 32 } |
| 33 | 33 |
| 34 namespace extensions { | 34 namespace extensions { |
| 35 | 35 |
| 36 // This class owns all RulesRegistries implementations of an ExtensionService. | 36 // This class owns all RulesRegistries implementations of an ExtensionService. |
| 37 // This class lives on the UI thread. | 37 // This class lives on the UI thread. |
| 38 class RulesRegistryService : public ProfileKeyedAPI, | 38 class RulesRegistryService : public ProfileKeyedAPI, |
| 39 public content::NotificationObserver { | 39 public content::NotificationObserver { |
| 40 public: | 40 public: |
| 41 typedef RulesRegistry::WebViewKey WebViewKey; |
| 42 struct RulesRegistryKey { |
| 43 std::string event_name; |
| 44 WebViewKey webview_key; |
| 45 RulesRegistryKey(const std::string event_name, |
| 46 const WebViewKey& webview_key) |
| 47 : event_name(event_name), |
| 48 webview_key(webview_key) {} |
| 49 bool operator<(const RulesRegistryKey& other) const { |
| 50 return (event_name < other.event_name) || |
| 51 ((event_name == other.event_name) && |
| 52 (webview_key < other.webview_key)); |
| 53 } |
| 54 }; |
| 55 |
| 41 explicit RulesRegistryService(Profile* profile); | 56 explicit RulesRegistryService(Profile* profile); |
| 42 virtual ~RulesRegistryService(); | 57 virtual ~RulesRegistryService(); |
| 43 | 58 |
| 44 // Unregisters refptrs to concrete RulesRegistries at other objects that were | 59 // Unregisters refptrs to concrete RulesRegistries at other objects that were |
| 45 // created by us so that the RulesRegistries can be released. | 60 // created by us so that the RulesRegistries can be released. |
| 46 virtual void Shutdown() OVERRIDE; | 61 virtual void Shutdown() OVERRIDE; |
| 47 | 62 |
| 48 // ProfileKeyedAPI implementation. | 63 // ProfileKeyedAPI implementation. |
| 49 static ProfileKeyedAPIFactory<RulesRegistryService>* GetFactoryInstance(); | 64 static ProfileKeyedAPIFactory<RulesRegistryService>* GetFactoryInstance(); |
| 50 | 65 |
| 51 // Convenience method to get the RulesRegistryService for a profile. | 66 // Convenience method to get the RulesRegistryService for a profile. |
| 52 static RulesRegistryService* Get(Profile* profile); | 67 static RulesRegistryService* Get(Profile* profile); |
| 53 | 68 |
| 54 // Registers the default RulesRegistries used in Chromium. | 69 // Registers the default RulesRegistries used in Chromium. |
| 55 void RegisterDefaultRulesRegistries(); | 70 void EnsureDefaultRulesRegistriesRegistered( |
| 71 const WebViewKey& webview_key); |
| 56 | 72 |
| 57 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry. | 73 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry. |
| 58 void RegisterRulesRegistry(scoped_refptr<RulesRegistry> rule_registry); | 74 void RegisterRulesRegistry(scoped_refptr<RulesRegistry> rule_registry); |
| 59 | 75 |
| 60 // Returns the RulesRegistry for |event_name| or NULL if no such registry | 76 // Returns the RulesRegistry for |event_name| and |webview_key| or NULL if no |
| 61 // has been registered. | 77 // such registry has been registered. Default rules registries (such as the |
| 78 // WebRequest rules registry) will be created on first access. |
| 62 scoped_refptr<RulesRegistry> GetRulesRegistry( | 79 scoped_refptr<RulesRegistry> GetRulesRegistry( |
| 63 const std::string& event_name) const; | 80 const WebViewKey& webview_key, |
| 81 const std::string& event_name); |
| 64 | 82 |
| 65 // Accessors for each type of rules registry. | 83 // Accessors for each type of rules registry. |
| 66 ContentRulesRegistry* content_rules_registry() const { | 84 ContentRulesRegistry* content_rules_registry() const { |
| 85 CHECK(content_rules_registry_); |
| 67 return content_rules_registry_; | 86 return content_rules_registry_; |
| 68 } | 87 } |
| 69 | 88 |
| 89 // Removes all rules registries of a given webview embedder process ID. |
| 90 void RemoveWebViewRulesRegistries(int process_id); |
| 91 |
| 70 // For testing. | 92 // For testing. |
| 71 void SimulateExtensionUnloaded(const std::string& extension_id); | 93 void SimulateExtensionUnloaded(const std::string& extension_id); |
| 72 private: | 94 private: |
| 73 friend class ProfileKeyedAPIFactory<RulesRegistryService>; | 95 friend class ProfileKeyedAPIFactory<RulesRegistryService>; |
| 74 | 96 |
| 75 // Maps event names to RuleRegistries that handle these events. | 97 // Maps <event name, webview key> to RuleRegistries that handle these |
| 76 typedef std::map<std::string, scoped_refptr<RulesRegistry> > | 98 // events. |
| 99 typedef std::map<RulesRegistryKey, scoped_refptr<RulesRegistry> > |
| 77 RulesRegistryMap; | 100 RulesRegistryMap; |
| 78 | 101 |
| 79 // Notifies all RulesRegistries that |extension_id| was unloaded. | 102 // Notifies all RulesRegistries that |extension_id| was unloaded. |
| 80 // It is not guaranteed that this notification is processed synchronously. | 103 // It is not guaranteed that this notification is processed synchronously. |
| 81 // If extensions live on another thread, the notification is posted. | 104 // If extensions live on another thread, the notification is posted. |
| 82 void OnExtensionUnloaded(const std::string& extension_id); | 105 void OnExtensionUnloaded(const std::string& extension_id); |
| 83 | 106 |
| 84 // Implementation of content::NotificationObserver. | 107 // Implementation of content::NotificationObserver. |
| 85 virtual void Observe(int type, | 108 virtual void Observe(int type, |
| 86 const content::NotificationSource& source, | 109 const content::NotificationSource& source, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 105 content::NotificationRegistrar registrar_; | 128 content::NotificationRegistrar registrar_; |
| 106 | 129 |
| 107 Profile* profile_; | 130 Profile* profile_; |
| 108 | 131 |
| 109 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); | 132 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); |
| 110 }; | 133 }; |
| 111 | 134 |
| 112 } // namespace extensions | 135 } // namespace extensions |
| 113 | 136 |
| 114 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ | 137 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |
| OLD | NEW |