| 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_H__ | 5 #ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_H__ | 
| 6 #define EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_H__ | 6 #define EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_H__ | 
| 7 | 7 | 
| 8 #include <map> | 8 #include <map> | 
| 9 #include <set> | 9 #include <set> | 
| 10 #include <string> | 10 #include <string> | 
| (...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::core_api::events::Rule Rule; | 42   typedef extensions::core_api::events::Rule Rule; | 
| 43   struct WebViewKey { |  | 
| 44     int embedder_process_id; |  | 
| 45     int webview_instance_id; |  | 
| 46     WebViewKey(int embedder_process_id, int webview_instance_id) |  | 
| 47         : embedder_process_id(embedder_process_id), |  | 
| 48           webview_instance_id(webview_instance_id) {} |  | 
| 49     bool operator<(const WebViewKey& other) const { |  | 
| 50       return embedder_process_id < other.embedder_process_id || |  | 
| 51           ((embedder_process_id == other.embedder_process_id) && |  | 
| 52            (webview_instance_id < other.webview_instance_id)); |  | 
| 53     } |  | 
| 54   }; |  | 
| 55 | 43 | 
| 56   enum Defaults { DEFAULT_PRIORITY = 100 }; | 44   enum Defaults { DEFAULT_PRIORITY = 100 }; | 
| 57   // After the RulesCacheDelegate object (the part of the registry which runs on | 45   // After the RulesCacheDelegate object (the part of the registry which runs on | 
| 58   // the UI thread) is created, a pointer to it is passed to |*ui_part|. | 46   // the UI thread) is created, a pointer to it is passed to |*ui_part|. | 
| 59   // In tests, |browser_context| and |ui_part| can be NULL (at the same time). | 47   // In tests, |browser_context| and |ui_part| can be NULL (at the same time). | 
| 60   // In that case the storage functionality disabled (no RulesCacheDelegate | 48   // In that case the storage functionality disabled (no RulesCacheDelegate | 
| 61   // object created). | 49   // object created). | 
| 62   RulesRegistry(content::BrowserContext* browser_context, | 50   RulesRegistry(content::BrowserContext* browser_context, | 
| 63                 const std::string& event_name, | 51                 const std::string& event_name, | 
| 64                 content::BrowserThread::ID owner_thread, | 52                 content::BrowserThread::ID owner_thread, | 
| 65                 RulesCacheDelegate* cache_delegate, | 53                 RulesCacheDelegate* cache_delegate, | 
| 66                 const WebViewKey& webview_key); | 54                 int id); | 
| 67 | 55 | 
| 68   const OneShotEvent& ready() const { | 56   const OneShotEvent& ready() const { | 
| 69     return ready_; | 57     return ready_; | 
| 70   } | 58   } | 
| 71 | 59 | 
| 72   // RulesRegistry implementation: | 60   // RulesRegistry implementation: | 
| 73 | 61 | 
| 74   // Registers |rules|, owned by |extension_id| to this RulesRegistry. | 62   // Registers |rules|, owned by |extension_id| to this RulesRegistry. | 
| 75   // If a concrete RuleRegistry does not support some of the rules, | 63   // If a concrete RuleRegistry does not support some of the rules, | 
| 76   // it may ignore them. | 64   // it may ignore them. | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 138   // Returns the context where the rules registry lives. | 126   // Returns the context where the rules registry lives. | 
| 139   content::BrowserContext* browser_context() { return browser_context_; } | 127   content::BrowserContext* browser_context() { return browser_context_; } | 
| 140 | 128 | 
| 141   // Returns the ID of the thread on which the rules registry lives. | 129   // Returns the ID of the thread on which the rules registry lives. | 
| 142   // It is safe to call this function from any thread. | 130   // It is safe to call this function from any thread. | 
| 143   content::BrowserThread::ID owner_thread() const { return owner_thread_; } | 131   content::BrowserThread::ID owner_thread() const { return owner_thread_; } | 
| 144 | 132 | 
| 145   // The name of the event with which rules are registered. | 133   // The name of the event with which rules are registered. | 
| 146   const std::string& event_name() const { return event_name_; } | 134   const std::string& event_name() const { return event_name_; } | 
| 147 | 135 | 
| 148   // The key that identifies the webview (or tabs) in which these rules apply. | 136   // The unique identifier for this RulesRegistry object. | 
| 149   // If the rules apply to the main browser, then this returns the tuple (0, 0). | 137   int id() const { return id_; } | 
| 150   const WebViewKey& webview_key() const { |  | 
| 151     return webview_key_; |  | 
| 152   } |  | 
| 153 | 138 | 
| 154  protected: | 139  protected: | 
| 155   virtual ~RulesRegistry(); | 140   virtual ~RulesRegistry(); | 
| 156 | 141 | 
| 157   // The precondition for calling this method is that all rules have unique IDs. | 142   // The precondition for calling this method is that all rules have unique IDs. | 
| 158   // AddRules establishes this precondition and calls into this method. | 143   // AddRules establishes this precondition and calls into this method. | 
| 159   // Stored rules already meet this precondition and so they avoid calling | 144   // Stored rules already meet this precondition and so they avoid calling | 
| 160   // CheckAndFillInOptionalRules for improved performance. | 145   // CheckAndFillInOptionalRules for improved performance. | 
| 161   // | 146   // | 
| 162   // Returns an empty string if the function is successful or an error | 147   // Returns an empty string if the function is successful or an error | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 226   // The context to which this rules registry belongs. | 211   // The context to which this rules registry belongs. | 
| 227   content::BrowserContext* browser_context_; | 212   content::BrowserContext* browser_context_; | 
| 228 | 213 | 
| 229   // The ID of the thread on which the rules registry lives. | 214   // The ID of the thread on which the rules registry lives. | 
| 230   const content::BrowserThread::ID owner_thread_; | 215   const content::BrowserThread::ID owner_thread_; | 
| 231 | 216 | 
| 232   // The name of the event with which rules are registered. | 217   // The name of the event with which rules are registered. | 
| 233   const std::string event_name_; | 218   const std::string event_name_; | 
| 234 | 219 | 
| 235   // The key that identifies the context in which these rules apply. | 220   // The key that identifies the context in which these rules apply. | 
| 236   WebViewKey webview_key_; | 221   int id_; | 
| 237 | 222 | 
| 238   RulesDictionary rules_; | 223   RulesDictionary rules_; | 
| 239 | 224 | 
| 240   // Signaled when we have finished reading from storage for all extensions that | 225   // Signaled when we have finished reading from storage for all extensions that | 
| 241   // are loaded on startup. | 226   // are loaded on startup. | 
| 242   OneShotEvent ready_; | 227   OneShotEvent ready_; | 
| 243 | 228 | 
| 244   ProcessStateMap process_changed_rules_requested_; | 229   ProcessStateMap process_changed_rules_requested_; | 
| 245 | 230 | 
| 246   // Returns whether any existing rule is registered with identifier |rule_id| | 231   // Returns whether any existing rule is registered with identifier |rule_id| | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 287   // safe. The registry only ever associates with one RulesCacheDelegate | 272   // safe. The registry only ever associates with one RulesCacheDelegate | 
| 288   // instance. | 273   // instance. | 
| 289   base::WeakPtr<RulesCacheDelegate> cache_delegate_; | 274   base::WeakPtr<RulesCacheDelegate> cache_delegate_; | 
| 290 | 275 | 
| 291   DISALLOW_COPY_AND_ASSIGN(RulesRegistry); | 276   DISALLOW_COPY_AND_ASSIGN(RulesRegistry); | 
| 292 }; | 277 }; | 
| 293 | 278 | 
| 294 }  // namespace extensions | 279 }  // namespace extensions | 
| 295 | 280 | 
| 296 #endif  // EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_H__ | 281 #endif  // EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_H__ | 
| OLD | NEW | 
|---|