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_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__ |
| 7 | 7 |
| 8 #include "chrome/browser/extensions/api/declarative/rules_registry.h" | 8 #include "chrome/browser/extensions/api/declarative/rules_registry.h" |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 | 33 |
| 34 class RulesCacheDelegate; | 34 class RulesCacheDelegate; |
| 35 | 35 |
| 36 // A base class for RulesRegistries that takes care of storing the | 36 // A base class for RulesRegistries that takes care of storing the |
| 37 // RulesRegistry::Rule objects. It contains all the methods that need to run on | 37 // RulesRegistry::Rule objects. It contains all the methods that need to run on |
| 38 // the registry thread; methods that need to run on the UI thread are separated | 38 // the registry thread; methods that need to run on the UI thread are separated |
| 39 // in the RulesCacheDelegate object. | 39 // in the RulesCacheDelegate object. |
| 40 class RulesRegistry : public base::RefCountedThreadSafe<RulesRegistry> { | 40 class RulesRegistry : public base::RefCountedThreadSafe<RulesRegistry> { |
| 41 public: | 41 public: |
| 42 typedef extensions::api::events::Rule Rule; | 42 typedef extensions::api::events::Rule Rule; |
| 43 typedef std::pair<int, int> WebViewKey; | |
|
Jeffrey Yasskin
2013/11/09 02:47:22
I'd rather make this an explicit struct so it can
Fady Samuel
2013/11/10 03:39:56
I've begun a discussion with some people on this t
Jeffrey Yasskin
2013/11/11 05:37:36
Thanks :)
| |
| 43 | 44 |
| 44 enum Defaults { DEFAULT_PRIORITY = 100 }; | 45 enum Defaults { DEFAULT_PRIORITY = 100 }; |
| 45 // After the RulesCacheDelegate object (the part of the registry which runs on | 46 // After the RulesCacheDelegate object (the part of the registry which runs on |
| 46 // the UI thread) is created, a pointer to it is passed to |*ui_part|. | 47 // the UI thread) is created, a pointer to it is passed to |*ui_part|. |
| 47 // In tests, |profile| and |ui_part| can be NULL (at the same time). In that | 48 // In tests, |profile| and |ui_part| can be NULL (at the same time). In that |
| 48 // case the storage functionality disabled (no RulesCacheDelegate object | 49 // case the storage functionality disabled (no RulesCacheDelegate object |
| 49 // created). | 50 // created). |
| 50 RulesRegistry(Profile* profile, | 51 RulesRegistry(Profile* profile, |
| 51 const std::string& event_name, | 52 const std::string& event_name, |
| 52 content::BrowserThread::ID owner_thread, | 53 content::BrowserThread::ID owner_thread, |
| 53 RulesCacheDelegate* cache_delegate); | 54 RulesCacheDelegate* cache_delegate, |
| 55 const WebViewKey& webview_key); | |
| 54 | 56 |
| 55 const OneShotEvent& ready() const { | 57 const OneShotEvent& ready() const { |
| 56 return ready_; | 58 return ready_; |
| 57 } | 59 } |
| 58 | 60 |
| 59 // RulesRegistry implementation: | 61 // RulesRegistry implementation: |
| 60 | 62 |
| 61 // Registers |rules|, owned by |extension_id| to this RulesRegistry. | 63 // Registers |rules|, owned by |extension_id| to this RulesRegistry. |
| 62 // If a concrete RuleRegistry does not support some of the rules, | 64 // If a concrete RuleRegistry does not support some of the rules, |
| 63 // it may ignore them. | 65 // it may ignore them. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 // Returns the profile where the rules registry lives. | 125 // Returns the profile where the rules registry lives. |
| 124 Profile* profile() const { return profile_; } | 126 Profile* profile() const { return profile_; } |
| 125 | 127 |
| 126 // Returns the ID of the thread on which the rules registry lives. | 128 // Returns the ID of the thread on which the rules registry lives. |
| 127 // It is safe to call this function from any thread. | 129 // It is safe to call this function from any thread. |
| 128 content::BrowserThread::ID owner_thread() const { return owner_thread_; } | 130 content::BrowserThread::ID owner_thread() const { return owner_thread_; } |
| 129 | 131 |
| 130 // The name of the event with which rules are registered. | 132 // The name of the event with which rules are registered. |
| 131 const std::string& event_name() const { return event_name_; } | 133 const std::string& event_name() const { return event_name_; } |
| 132 | 134 |
| 135 // The key that identifies the webview (or tabs) in which these rules apply. | |
|
Jeffrey Yasskin
2013/11/09 02:47:22
Document what this returns if the rules apply to t
Fady Samuel
2013/11/10 03:39:56
Done.
| |
| 136 const WebViewKey& webview_key() const { | |
| 137 return webview_key_; | |
| 138 } | |
| 139 | |
| 133 protected: | 140 protected: |
| 134 virtual ~RulesRegistry(); | 141 virtual ~RulesRegistry(); |
| 135 | 142 |
| 136 // These functions need to apply the rules to the browser, while the base | 143 // These functions need to apply the rules to the browser, while the base |
| 137 // class will handle defaulting empty fields before calling *Impl, and will | 144 // class will handle defaulting empty fields before calling *Impl, and will |
| 138 // automatically cache the rules and re-call *Impl on browser startup. | 145 // automatically cache the rules and re-call *Impl on browser startup. |
| 139 virtual std::string AddRulesImpl( | 146 virtual std::string AddRulesImpl( |
| 140 const std::string& extension_id, | 147 const std::string& extension_id, |
| 141 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) = 0; | 148 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) = 0; |
| 142 virtual std::string RemoveRulesImpl( | 149 virtual std::string RemoveRulesImpl( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 | 192 |
| 186 // The profile to which this rules registry belongs. | 193 // The profile to which this rules registry belongs. |
| 187 Profile* profile_; | 194 Profile* profile_; |
| 188 | 195 |
| 189 // The ID of the thread on which the rules registry lives. | 196 // The ID of the thread on which the rules registry lives. |
| 190 const content::BrowserThread::ID owner_thread_; | 197 const content::BrowserThread::ID owner_thread_; |
| 191 | 198 |
| 192 // The name of the event with which rules are registered. | 199 // The name of the event with which rules are registered. |
| 193 const std::string event_name_; | 200 const std::string event_name_; |
| 194 | 201 |
| 202 // The key that identifies the context in which these rules apply. | |
| 203 WebViewKey webview_key_; | |
| 204 | |
| 195 RulesDictionary rules_; | 205 RulesDictionary rules_; |
| 196 | 206 |
| 197 // Signaled when we have finished reading from storage for all extensions that | 207 // Signaled when we have finished reading from storage for all extensions that |
| 198 // are loaded on startup. | 208 // are loaded on startup. |
| 199 OneShotEvent ready_; | 209 OneShotEvent ready_; |
| 200 | 210 |
| 201 // The factory needs to be declared before |cache_delegate_|, so that it can | 211 // The factory needs to be declared before |cache_delegate_|, so that it can |
| 202 // produce a pointer as a construction argument for |cache_delegate_|. | 212 // produce a pointer as a construction argument for |cache_delegate_|. |
| 203 base::WeakPtrFactory<RulesRegistry> weak_ptr_factory_; | 213 base::WeakPtrFactory<RulesRegistry> weak_ptr_factory_; |
| 204 | 214 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 typedef std::map<ExtensionId, std::set<RuleIdentifier> > RuleIdentifiersMap; | 254 typedef std::map<ExtensionId, std::set<RuleIdentifier> > RuleIdentifiersMap; |
| 245 RuleIdentifiersMap used_rule_identifiers_; | 255 RuleIdentifiersMap used_rule_identifiers_; |
| 246 int last_generated_rule_identifier_id_; | 256 int last_generated_rule_identifier_id_; |
| 247 | 257 |
| 248 DISALLOW_COPY_AND_ASSIGN(RulesRegistry); | 258 DISALLOW_COPY_AND_ASSIGN(RulesRegistry); |
| 249 }; | 259 }; |
| 250 | 260 |
| 251 } // namespace extensions | 261 } // namespace extensions |
| 252 | 262 |
| 253 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__ | 263 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__ |
| OLD | NEW |