Chromium Code Reviews| 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 typedef std::pair<std::string, WebViewKey> RulesRegistryKey; | |
| 43 | |
| 41 explicit RulesRegistryService(Profile* profile); | 44 explicit RulesRegistryService(Profile* profile); |
| 42 virtual ~RulesRegistryService(); | 45 virtual ~RulesRegistryService(); |
| 43 | 46 |
| 44 // Unregisters refptrs to concrete RulesRegistries at other objects that were | 47 // Unregisters refptrs to concrete RulesRegistries at other objects that were |
| 45 // created by us so that the RulesRegistries can be released. | 48 // created by us so that the RulesRegistries can be released. |
| 46 virtual void Shutdown() OVERRIDE; | 49 virtual void Shutdown() OVERRIDE; |
| 47 | 50 |
| 48 // ProfileKeyedAPI implementation. | 51 // ProfileKeyedAPI implementation. |
| 49 static ProfileKeyedAPIFactory<RulesRegistryService>* GetFactoryInstance(); | 52 static ProfileKeyedAPIFactory<RulesRegistryService>* GetFactoryInstance(); |
| 50 | 53 |
| 51 // Convenience method to get the RulesRegistryService for a profile. | 54 // Convenience method to get the RulesRegistryService for a profile. |
| 52 static RulesRegistryService* Get(Profile* profile); | 55 static RulesRegistryService* Get(Profile* profile); |
| 53 | 56 |
| 54 // Registers the default RulesRegistries used in Chromium. | 57 // Registers the default RulesRegistries used in Chromium. |
| 55 void RegisterDefaultRulesRegistries(); | 58 void RegisterDefaultRulesRegistriesIfNotAvailable( |
| 59 const WebViewKey& webview_key); | |
| 56 | 60 |
| 57 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry. | 61 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry. |
| 58 void RegisterRulesRegistry(scoped_refptr<RulesRegistry> rule_registry); | 62 void RegisterRulesRegistry(scoped_refptr<RulesRegistry> rule_registry); |
| 59 | 63 |
| 60 // Returns the RulesRegistry for |event_name| or NULL if no such registry | 64 // Returns the RulesRegistry for |event_name| and |webview_key| orr NULL if no |
| 61 // has been registered. | 65 // such registry has been registered. |
|
vabr (Chromium)
2013/11/04 11:12:13
This comment is more precise now, but it still doe
Fady Samuel
2013/11/04 20:13:53
Done.
| |
| 62 scoped_refptr<RulesRegistry> GetRulesRegistry( | 66 scoped_refptr<RulesRegistry> GetRulesRegistry( |
| 63 const std::string& event_name) const; | 67 const WebViewKey& webview_key, |
| 68 const std::string& event_name); | |
| 64 | 69 |
| 65 // Accessors for each type of rules registry. | 70 // Accessors for each type of rules registry. This method will install default |
| 66 ContentRulesRegistry* content_rules_registry() const { | 71 // rules registries if they haven't been installed yet. |
| 67 return content_rules_registry_; | 72 ContentRulesRegistry* GetContentRulesRegistry(); |
| 68 } | 73 |
| 74 // Removes all rules registries of a given webview embedder process ID. | |
| 75 void RemoveWebViewRulesRegistries(int process_id); | |
| 69 | 76 |
| 70 // For testing. | 77 // For testing. |
| 71 void SimulateExtensionUnloaded(const std::string& extension_id); | 78 void SimulateExtensionUnloaded(const std::string& extension_id); |
| 72 private: | 79 private: |
| 73 friend class ProfileKeyedAPIFactory<RulesRegistryService>; | 80 friend class ProfileKeyedAPIFactory<RulesRegistryService>; |
| 74 | 81 |
| 75 // Maps event names to RuleRegistries that handle these events. | 82 // Maps <event name, webview key> to RuleRegistries that handle these |
| 76 typedef std::map<std::string, scoped_refptr<RulesRegistry> > | 83 // events. |
| 84 typedef std::map<RulesRegistryKey, scoped_refptr<RulesRegistry> > | |
| 77 RulesRegistryMap; | 85 RulesRegistryMap; |
| 78 | 86 |
| 87 typedef std::set<WebViewKey> WebViewKeySet; | |
| 88 typedef std::set<RulesRegistryKey> RulesRegistryKeySet; | |
| 89 | |
| 79 // Notifies all RulesRegistries that |extension_id| was unloaded. | 90 // Notifies all RulesRegistries that |extension_id| was unloaded. |
| 80 // It is not guaranteed that this notification is processed synchronously. | 91 // It is not guaranteed that this notification is processed synchronously. |
| 81 // If extensions live on another thread, the notification is posted. | 92 // If extensions live on another thread, the notification is posted. |
| 82 void OnExtensionUnloaded(const std::string& extension_id); | 93 void OnExtensionUnloaded(const std::string& extension_id); |
| 83 | 94 |
| 95 // Removes a rules registry associated with a given |key|. | |
| 96 void RemoveRulesRegistry(const RulesRegistryKey& key); | |
| 97 | |
| 84 // Implementation of content::NotificationObserver. | 98 // Implementation of content::NotificationObserver. |
| 85 virtual void Observe(int type, | 99 virtual void Observe(int type, |
| 86 const content::NotificationSource& source, | 100 const content::NotificationSource& source, |
| 87 const content::NotificationDetails& details) OVERRIDE; | 101 const content::NotificationDetails& details) OVERRIDE; |
| 88 | 102 |
| 89 // ProfileKeyedAPI implementation. | 103 // ProfileKeyedAPI implementation. |
| 90 static const char* service_name() { | 104 static const char* service_name() { |
| 91 return "RulesRegistryService"; | 105 return "RulesRegistryService"; |
| 92 } | 106 } |
| 93 static const bool kServiceHasOwnInstanceInIncognito = true; | 107 static const bool kServiceHasOwnInstanceInIncognito = true; |
| 94 static const bool kServiceIsNULLWhileTesting = true; | 108 static const bool kServiceIsNULLWhileTesting = true; |
| 95 | 109 |
| 96 RulesRegistryMap rule_registries_; | 110 RulesRegistryMap rule_registries_; |
| 97 | 111 |
| 112 // Indicates the set of <webview>s that have default rule registries | |
| 113 // installed. | |
| 114 WebViewKeySet installed_rules_registries_; | |
| 115 | |
| 98 // We own the parts of the registries which need to run on the UI thread. | 116 // We own the parts of the registries which need to run on the UI thread. |
| 99 ScopedVector<RulesCacheDelegate> cache_delegates_; | 117 ScopedVector<RulesCacheDelegate> cache_delegates_; |
| 100 | 118 |
| 101 // Weak pointer into rule_registries_ to make it easier to handle content rule | 119 // Weak pointer into rule_registries_ to make it easier to handle content rule |
| 102 // conditions. | 120 // conditions. |
| 103 ContentRulesRegistry* content_rules_registry_; | 121 ContentRulesRegistry* content_rules_registry_; |
| 104 | 122 |
| 105 content::NotificationRegistrar registrar_; | 123 content::NotificationRegistrar registrar_; |
| 106 | 124 |
| 107 Profile* profile_; | 125 Profile* profile_; |
| 108 | 126 |
| 109 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); | 127 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); |
| 110 }; | 128 }; |
| 111 | 129 |
| 112 } // namespace extensions | 130 } // namespace extensions |
| 113 | 131 |
| 114 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ | 132 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |
| OLD | NEW |