| 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 <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "chrome/common/extensions/api/events.h" | 18 #include "chrome/common/extensions/api/events.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
| 21 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
| 22 #include "extensions/common/one_shot_event.h" | 22 #include "extensions/common/one_shot_event.h" |
| 23 | 23 |
| 24 class Profile; | 24 namespace content { |
| 25 class BrowserContext; |
| 26 } |
| 25 | 27 |
| 26 namespace base { | 28 namespace base { |
| 27 class Value; | 29 class Value; |
| 28 } // namespace base | 30 } // namespace base |
| 29 | 31 |
| 30 namespace extensions { | 32 namespace extensions { |
| 31 | 33 |
| 32 class RulesCacheDelegate; | 34 class RulesCacheDelegate; |
| 33 | 35 |
| 34 // A base class for RulesRegistries that takes care of storing the | 36 // A base class for RulesRegistries that takes care of storing the |
| (...skipping 12 matching lines...) Expand all Loading... |
| 47 bool operator<(const WebViewKey& other) const { | 49 bool operator<(const WebViewKey& other) const { |
| 48 return embedder_process_id < other.embedder_process_id || | 50 return embedder_process_id < other.embedder_process_id || |
| 49 ((embedder_process_id == other.embedder_process_id) && | 51 ((embedder_process_id == other.embedder_process_id) && |
| 50 (webview_instance_id < other.webview_instance_id)); | 52 (webview_instance_id < other.webview_instance_id)); |
| 51 } | 53 } |
| 52 }; | 54 }; |
| 53 | 55 |
| 54 enum Defaults { DEFAULT_PRIORITY = 100 }; | 56 enum Defaults { DEFAULT_PRIORITY = 100 }; |
| 55 // After the RulesCacheDelegate object (the part of the registry which runs on | 57 // After the RulesCacheDelegate object (the part of the registry which runs on |
| 56 // the UI thread) is created, a pointer to it is passed to |*ui_part|. | 58 // the UI thread) is created, a pointer to it is passed to |*ui_part|. |
| 57 // In tests, |profile| and |ui_part| can be NULL (at the same time). In that | 59 // In tests, |browser_context| and |ui_part| can be NULL (at the same time). |
| 58 // case the storage functionality disabled (no RulesCacheDelegate object | 60 // In that case the storage functionality disabled (no RulesCacheDelegate |
| 59 // created). | 61 // object created). |
| 60 RulesRegistry(Profile* profile, | 62 RulesRegistry(content::BrowserContext* browser_context, |
| 61 const std::string& event_name, | 63 const std::string& event_name, |
| 62 content::BrowserThread::ID owner_thread, | 64 content::BrowserThread::ID owner_thread, |
| 63 RulesCacheDelegate* cache_delegate, | 65 RulesCacheDelegate* cache_delegate, |
| 64 const WebViewKey& webview_key); | 66 const WebViewKey& webview_key); |
| 65 | 67 |
| 66 const OneShotEvent& ready() const { | 68 const OneShotEvent& ready() const { |
| 67 return ready_; | 69 return ready_; |
| 68 } | 70 } |
| 69 | 71 |
| 70 // RulesRegistry implementation: | 72 // RulesRegistry implementation: |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 128 |
| 127 // Returns the number of entries in used_rule_identifiers_ for leak detection. | 129 // Returns the number of entries in used_rule_identifiers_ for leak detection. |
| 128 // Every ExtensionId counts as one entry, even if it contains no rules. | 130 // Every ExtensionId counts as one entry, even if it contains no rules. |
| 129 size_t GetNumberOfUsedRuleIdentifiersForTesting() const; | 131 size_t GetNumberOfUsedRuleIdentifiersForTesting() const; |
| 130 | 132 |
| 131 // Returns the RulesCacheDelegate. This is used for testing. | 133 // Returns the RulesCacheDelegate. This is used for testing. |
| 132 RulesCacheDelegate* rules_cache_delegate_for_testing() const { | 134 RulesCacheDelegate* rules_cache_delegate_for_testing() const { |
| 133 return cache_delegate_.get(); | 135 return cache_delegate_.get(); |
| 134 } | 136 } |
| 135 | 137 |
| 136 // Returns the profile where the rules registry lives. | 138 // Returns the context where the rules registry lives. |
| 137 Profile* profile() const { return profile_; } | 139 content::BrowserContext* browser_context() { return browser_context_; } |
| 138 | 140 |
| 139 // Returns the ID of the thread on which the rules registry lives. | 141 // Returns the ID of the thread on which the rules registry lives. |
| 140 // It is safe to call this function from any thread. | 142 // It is safe to call this function from any thread. |
| 141 content::BrowserThread::ID owner_thread() const { return owner_thread_; } | 143 content::BrowserThread::ID owner_thread() const { return owner_thread_; } |
| 142 | 144 |
| 143 // The name of the event with which rules are registered. | 145 // The name of the event with which rules are registered. |
| 144 const std::string& event_name() const { return event_name_; } | 146 const std::string& event_name() const { return event_name_; } |
| 145 | 147 |
| 146 // The key that identifies the webview (or tabs) in which these rules apply. | 148 // The key that identifies the webview (or tabs) in which these rules apply. |
| 147 // If the rules apply to the main browser, then this returns the tuple (0, 0). | 149 // If the rules apply to the main browser, then this returns the tuple (0, 0). |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 // uninstalled, that way there is no clash with the preferences being wiped. | 216 // uninstalled, that way there is no clash with the preferences being wiped. |
| 215 std::string RemoveAllRulesNoStoreUpdate(const std::string& extension_id); | 217 std::string RemoveAllRulesNoStoreUpdate(const std::string& extension_id); |
| 216 | 218 |
| 217 void MarkReady(base::Time storage_init_time); | 219 void MarkReady(base::Time storage_init_time); |
| 218 | 220 |
| 219 // Deserialize the rules from the given Value object and add them to the | 221 // Deserialize the rules from the given Value object and add them to the |
| 220 // RulesRegistry. | 222 // RulesRegistry. |
| 221 void DeserializeAndAddRules(const std::string& extension_id, | 223 void DeserializeAndAddRules(const std::string& extension_id, |
| 222 scoped_ptr<base::Value> rules); | 224 scoped_ptr<base::Value> rules); |
| 223 | 225 |
| 224 // The profile to which this rules registry belongs. | 226 // The context to which this rules registry belongs. |
| 225 Profile* profile_; | 227 content::BrowserContext* browser_context_; |
| 226 | 228 |
| 227 // The ID of the thread on which the rules registry lives. | 229 // The ID of the thread on which the rules registry lives. |
| 228 const content::BrowserThread::ID owner_thread_; | 230 const content::BrowserThread::ID owner_thread_; |
| 229 | 231 |
| 230 // The name of the event with which rules are registered. | 232 // The name of the event with which rules are registered. |
| 231 const std::string event_name_; | 233 const std::string event_name_; |
| 232 | 234 |
| 233 // The key that identifies the context in which these rules apply. | 235 // The key that identifies the context in which these rules apply. |
| 234 WebViewKey webview_key_; | 236 WebViewKey webview_key_; |
| 235 | 237 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 typedef std::map<ExtensionId, std::set<RuleIdentifier> > RuleIdentifiersMap; | 287 typedef std::map<ExtensionId, std::set<RuleIdentifier> > RuleIdentifiersMap; |
| 286 RuleIdentifiersMap used_rule_identifiers_; | 288 RuleIdentifiersMap used_rule_identifiers_; |
| 287 int last_generated_rule_identifier_id_; | 289 int last_generated_rule_identifier_id_; |
| 288 | 290 |
| 289 DISALLOW_COPY_AND_ASSIGN(RulesRegistry); | 291 DISALLOW_COPY_AND_ASSIGN(RulesRegistry); |
| 290 }; | 292 }; |
| 291 | 293 |
| 292 } // namespace extensions | 294 } // namespace extensions |
| 293 | 295 |
| 294 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__ | 296 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__ |
| OLD | NEW |