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 EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ | 5 #ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |
| 6 #define EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ | 6 #define EXTENSIONS_BROWSER_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 } | 31 } |
| 32 | 32 |
| 33 namespace extensions { | 33 namespace extensions { |
| 34 | 34 |
| 35 // This class owns all RulesRegistries implementations of an ExtensionService. | 35 // This class owns all RulesRegistries implementations of an ExtensionService. |
| 36 // This class lives on the UI thread. | 36 // This class lives on the UI thread. |
| 37 class RulesRegistryService : public BrowserContextKeyedAPI, | 37 class RulesRegistryService : public BrowserContextKeyedAPI, |
| 38 public content::NotificationObserver, | 38 public content::NotificationObserver, |
| 39 public ExtensionRegistryObserver { | 39 public ExtensionRegistryObserver { |
| 40 public: | 40 public: |
| 41 typedef RulesRegistry::WebViewKey WebViewKey; | 41 static const int kDefultRulesRegistryID = 0; |
|
Fady Samuel
2014/11/26 23:39:41
typo: kDefaultRulesRegistryID
Xi Han
2014/11/27 23:25:25
Renamed.
| |
| 42 | |
| 42 struct RulesRegistryKey { | 43 struct RulesRegistryKey { |
| 43 std::string event_name; | 44 std::string event_name; |
| 44 WebViewKey webview_key; | 45 int rules_registry_id; |
| 45 RulesRegistryKey(const std::string event_name, | 46 RulesRegistryKey(const std::string event_name, int rules_registry_id) |
| 46 const WebViewKey& webview_key) | 47 : event_name(event_name), rules_registry_id(rules_registry_id) {} |
|
Fady Samuel
2014/11/26 23:39:41
Put this on the next line.
Xi Han
2014/11/27 23:25:25
Done.
| |
| 47 : event_name(event_name), | |
| 48 webview_key(webview_key) {} | |
| 49 bool operator<(const RulesRegistryKey& other) const { | 48 bool operator<(const RulesRegistryKey& other) const { |
| 50 return (event_name < other.event_name) || | 49 return (event_name < other.event_name) || |
| 51 ((event_name == other.event_name) && | 50 ((event_name == other.event_name) && |
| 52 (webview_key < other.webview_key)); | 51 (rules_registry_id < other.rules_registry_id)); |
| 53 } | 52 } |
| 54 }; | 53 }; |
| 55 | 54 |
| 56 explicit RulesRegistryService(content::BrowserContext* context); | 55 explicit RulesRegistryService(content::BrowserContext* context); |
| 57 ~RulesRegistryService() override; | 56 ~RulesRegistryService() override; |
| 58 | 57 |
| 59 // Unregisters refptrs to concrete RulesRegistries at other objects that were | 58 // Unregisters refptrs to concrete RulesRegistries at other objects that were |
| 60 // created by us so that the RulesRegistries can be released. | 59 // created by us so that the RulesRegistries can be released. |
| 61 void Shutdown() override; | 60 void Shutdown() override; |
| 62 | 61 |
| 63 // BrowserContextKeyedAPI implementation. | 62 // BrowserContextKeyedAPI implementation. |
| 64 static BrowserContextKeyedAPIFactory<RulesRegistryService>* | 63 static BrowserContextKeyedAPIFactory<RulesRegistryService>* |
| 65 GetFactoryInstance(); | 64 GetFactoryInstance(); |
| 66 | 65 |
| 67 // Convenience method to get the RulesRegistryService for a context. | 66 // Convenience method to get the RulesRegistryService for a context. |
| 68 static RulesRegistryService* Get(content::BrowserContext* context); | 67 static RulesRegistryService* Get(content::BrowserContext* context); |
| 69 | 68 |
| 69 int GetNextRulesRegistryId(); | |
|
Fady Samuel
2014/11/26 23:39:41
GetNextRulesRegistryID
Xi Han
2014/11/27 23:25:25
Done.
| |
| 70 | |
| 70 // Registers the default RulesRegistries used in Chromium. | 71 // Registers the default RulesRegistries used in Chromium. |
| 71 void EnsureDefaultRulesRegistriesRegistered(const WebViewKey& webview_key); | 72 void EnsureDefaultRulesRegistriesRegistered(int rules_registry_id, |
| 73 bool is_web_view); | |
|
Fady Samuel
2014/11/26 23:39:41
Avoid this is_web_view. Maybe instead:
GetNextRul
Xi Han
2014/11/27 23:25:25
Yes, this name is more clear.
| |
| 72 | 74 |
| 73 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry. | 75 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry. |
| 74 void RegisterRulesRegistry(scoped_refptr<RulesRegistry> rule_registry); | 76 void RegisterRulesRegistry(scoped_refptr<RulesRegistry> rule_registry); |
| 75 | 77 |
| 76 // Returns the RulesRegistry for |event_name| and |webview_key| or NULL if no | 78 // Returns the RulesRegistry for |event_name| and |rules_registry_id| or |
| 77 // such registry has been registered. Default rules registries (such as the | 79 // NULL if no such registry has been registered. Default rules registries |
| 78 // WebRequest rules registry) will be created on first access. | 80 // (such as the WebRequest rules registry) will be created on first access. |
| 79 scoped_refptr<RulesRegistry> GetRulesRegistry(const WebViewKey& webview_key, | 81 scoped_refptr<RulesRegistry> GetRulesRegistry(int rules_registry_id, |
| 82 bool is_web_view, | |
| 80 const std::string& event_name); | 83 const std::string& event_name); |
| 81 | 84 |
| 82 // Accessors for each type of rules registry. | 85 // Accessors for each type of rules registry. |
| 83 ContentRulesRegistry* content_rules_registry() const { | 86 ContentRulesRegistry* content_rules_registry() const { |
| 84 CHECK(content_rules_registry_); | 87 CHECK(content_rules_registry_); |
| 85 return content_rules_registry_; | 88 return content_rules_registry_; |
| 86 } | 89 } |
| 87 | 90 |
| 88 // Removes all rules registries of a given webview embedder process ID. | 91 // Removes all rules registries of a given webview embedder process ID. |
| 89 void RemoveWebViewRulesRegistries(int process_id); | 92 void RemoveWebViewRulesRegistries(int process_id); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 void (RulesRegistry::*notification_callback)(const std::string&), | 125 void (RulesRegistry::*notification_callback)(const std::string&), |
| 123 const std::string& extension_id); | 126 const std::string& extension_id); |
| 124 | 127 |
| 125 // BrowserContextKeyedAPI implementation. | 128 // BrowserContextKeyedAPI implementation. |
| 126 static const char* service_name() { | 129 static const char* service_name() { |
| 127 return "RulesRegistryService"; | 130 return "RulesRegistryService"; |
| 128 } | 131 } |
| 129 static const bool kServiceHasOwnInstanceInIncognito = true; | 132 static const bool kServiceHasOwnInstanceInIncognito = true; |
| 130 static const bool kServiceIsNULLWhileTesting = true; | 133 static const bool kServiceIsNULLWhileTesting = true; |
| 131 | 134 |
| 135 int current_rules_registry_id_; | |
| 136 | |
| 132 RulesRegistryMap rule_registries_; | 137 RulesRegistryMap rule_registries_; |
| 133 | 138 |
| 134 // We own the parts of the registries which need to run on the UI thread. | 139 // We own the parts of the registries which need to run on the UI thread. |
| 135 ScopedVector<RulesCacheDelegate> cache_delegates_; | 140 ScopedVector<RulesCacheDelegate> cache_delegates_; |
| 136 | 141 |
| 137 // Weak pointer into rule_registries_ to make it easier to handle content rule | 142 // Weak pointer into rule_registries_ to make it easier to handle content rule |
| 138 // conditions. | 143 // conditions. |
| 139 ContentRulesRegistry* content_rules_registry_; | 144 ContentRulesRegistry* content_rules_registry_; |
| 140 | 145 |
| 141 content::NotificationRegistrar registrar_; | 146 content::NotificationRegistrar registrar_; |
| 142 | 147 |
| 143 // Listen to extension load, unloaded notification. | 148 // Listen to extension load, unloaded notification. |
| 144 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 149 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 145 extension_registry_observer_; | 150 extension_registry_observer_; |
| 146 | 151 |
| 147 content::BrowserContext* browser_context_; | 152 content::BrowserContext* browser_context_; |
| 148 | 153 |
| 149 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); | 154 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); |
| 150 }; | 155 }; |
| 151 | 156 |
| 152 } // namespace extensions | 157 } // namespace extensions |
| 153 | 158 |
| 154 #endif // EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ | 159 #endif // EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |
| OLD | NEW |