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; | |
|
Jeffrey Yasskin
2013/11/09 02:47:22
Similarly, this should at the very least have a co
Fady Samuel
2013/11/10 03:39:56
Made it a struct. I agree, this is far more readab
| |
| 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( |
|
Jeffrey Yasskin
2013/11/09 02:47:22
If what aren't available? If this is a "do it the
Fady Samuel
2013/11/10 03:39:56
Done.
| |
| 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| or NULL if no |
| 61 // has been registered. | 65 // such registry has been registered. Default rules registries (such as the |
|
Jeffrey Yasskin
2013/11/09 02:47:22
Can this return NULL anymore, since it auto-regist
Fady Samuel
2013/11/10 03:39:56
Yes, it's possible for this to return NULL if ther
| |
| 66 // WebRequest rules registry) will be created on first access. | |
| 62 scoped_refptr<RulesRegistry> GetRulesRegistry( | 67 scoped_refptr<RulesRegistry> GetRulesRegistry( |
| 63 const std::string& event_name) const; | 68 const WebViewKey& webview_key, |
| 69 const std::string& event_name); | |
| 64 | 70 |
| 65 // Accessors for each type of rules registry. | 71 // Accessors for each type of rules registry. This method will install default |
| 72 // rules registries if they haven't been installed yet. | |
|
Jeffrey Yasskin
2013/11/09 02:47:22
No it won't. :)
Fady Samuel
2013/11/10 03:39:56
Doh. Stale comment. Removed!
| |
| 66 ContentRulesRegistry* content_rules_registry() const { | 73 ContentRulesRegistry* content_rules_registry() const { |
| 74 CHECK(content_rules_registry_); | |
| 67 return content_rules_registry_; | 75 return content_rules_registry_; |
| 68 } | 76 } |
| 69 | 77 |
| 78 // Removes all rules registries of a given webview embedder process ID. | |
| 79 void RemoveWebViewRulesRegistries(int process_id); | |
| 80 | |
| 70 // For testing. | 81 // For testing. |
| 71 void SimulateExtensionUnloaded(const std::string& extension_id); | 82 void SimulateExtensionUnloaded(const std::string& extension_id); |
| 72 private: | 83 private: |
| 73 friend class ProfileKeyedAPIFactory<RulesRegistryService>; | 84 friend class ProfileKeyedAPIFactory<RulesRegistryService>; |
| 74 | 85 |
| 75 // Maps event names to RuleRegistries that handle these events. | 86 // Maps <event name, webview key> to RuleRegistries that handle these |
| 76 typedef std::map<std::string, scoped_refptr<RulesRegistry> > | 87 // events. |
| 88 typedef std::map<RulesRegistryKey, scoped_refptr<RulesRegistry> > | |
| 77 RulesRegistryMap; | 89 RulesRegistryMap; |
| 78 | 90 |
| 91 typedef std::set<WebViewKey> WebViewKeySet; | |
|
Jeffrey Yasskin
2013/11/09 02:47:22
FWIW, I'm not a fan of typedefs that save 7 charac
Fady Samuel
2013/11/10 03:39:56
Removed.
| |
| 92 typedef std::set<RulesRegistryKey> RulesRegistryKeySet; | |
|
Jeffrey Yasskin
2013/11/09 02:47:22
This doesn't look used.
Fady Samuel
2013/11/10 03:39:56
Removed.
| |
| 93 | |
| 79 // Notifies all RulesRegistries that |extension_id| was unloaded. | 94 // Notifies all RulesRegistries that |extension_id| was unloaded. |
| 80 // It is not guaranteed that this notification is processed synchronously. | 95 // It is not guaranteed that this notification is processed synchronously. |
| 81 // If extensions live on another thread, the notification is posted. | 96 // If extensions live on another thread, the notification is posted. |
| 82 void OnExtensionUnloaded(const std::string& extension_id); | 97 void OnExtensionUnloaded(const std::string& extension_id); |
| 83 | 98 |
| 99 // Removes a rules registry associated with a given |key|. | |
| 100 void RemoveRulesRegistry(const RulesRegistryKey& key); | |
| 101 | |
| 84 // Implementation of content::NotificationObserver. | 102 // Implementation of content::NotificationObserver. |
| 85 virtual void Observe(int type, | 103 virtual void Observe(int type, |
| 86 const content::NotificationSource& source, | 104 const content::NotificationSource& source, |
| 87 const content::NotificationDetails& details) OVERRIDE; | 105 const content::NotificationDetails& details) OVERRIDE; |
| 88 | 106 |
| 89 // ProfileKeyedAPI implementation. | 107 // ProfileKeyedAPI implementation. |
| 90 static const char* service_name() { | 108 static const char* service_name() { |
| 91 return "RulesRegistryService"; | 109 return "RulesRegistryService"; |
| 92 } | 110 } |
| 93 static const bool kServiceHasOwnInstanceInIncognito = true; | 111 static const bool kServiceHasOwnInstanceInIncognito = true; |
| 94 static const bool kServiceIsNULLWhileTesting = true; | 112 static const bool kServiceIsNULLWhileTesting = true; |
| 95 | 113 |
| 96 RulesRegistryMap rule_registries_; | 114 RulesRegistryMap rule_registries_; |
| 97 | 115 |
| 116 // Indicates the set of <webview>s that have default rule registries | |
| 117 // installed. | |
| 118 WebViewKeySet installed_rules_registries_; | |
| 119 | |
| 98 // We own the parts of the registries which need to run on the UI thread. | 120 // We own the parts of the registries which need to run on the UI thread. |
| 99 ScopedVector<RulesCacheDelegate> cache_delegates_; | 121 ScopedVector<RulesCacheDelegate> cache_delegates_; |
| 100 | 122 |
| 101 // Weak pointer into rule_registries_ to make it easier to handle content rule | 123 // Weak pointer into rule_registries_ to make it easier to handle content rule |
| 102 // conditions. | 124 // conditions. |
| 103 ContentRulesRegistry* content_rules_registry_; | 125 ContentRulesRegistry* content_rules_registry_; |
| 104 | 126 |
| 105 content::NotificationRegistrar registrar_; | 127 content::NotificationRegistrar registrar_; |
| 106 | 128 |
| 107 Profile* profile_; | 129 Profile* profile_; |
| 108 | 130 |
| 109 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); | 131 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); |
| 110 }; | 132 }; |
| 111 | 133 |
| 112 } // namespace extensions | 134 } // namespace extensions |
| 113 | 135 |
| 114 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ | 136 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |
| OLD | NEW |