| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // 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|. |
| 59 // In tests, |profile| and |ui_part| can be NULL (at the same time). In that | 59 // In tests, |profile| and |ui_part| can be NULL (at the same time). In that |
| 60 // case the storage functionality disabled (no RulesCacheDelegate object | 60 // case the storage functionality disabled (no RulesCacheDelegate object |
| 61 // created). | 61 // created). |
| 62 RulesRegistry(Profile* profile, | 62 RulesRegistry(Profile* profile, |
| 63 const std::string& event_name, | 63 const std::string& event_name, |
| 64 content::BrowserThread::ID owner_thread, | 64 content::BrowserThread::ID owner_thread, |
| 65 RulesCacheDelegate* cache_delegate, | 65 RulesCacheDelegate* cache_delegate, |
| 66 const WebViewKey& webview_key); | 66 const WebViewKey& webview_key); |
| 67 | 67 |
| 68 const OneShotEvent& ready() const { | 68 // If |ready()| returns NULL, the registry does not wait for the |
| 69 return ready_; | 69 // |cache_delegate_| to initialize and can be considered ready. |
| 70 const OneShotEvent* ready() const { |
| 71 return ready_.get(); |
| 70 } | 72 } |
| 71 | 73 |
| 72 // RulesRegistry implementation: | 74 // RulesRegistry implementation: |
| 73 | 75 |
| 74 // Registers |rules|, owned by |extension_id| to this RulesRegistry. | 76 // Registers |rules|, owned by |extension_id| to this RulesRegistry. |
| 75 // If a concrete RuleRegistry does not support some of the rules, | 77 // If a concrete RuleRegistry does not support some of the rules, |
| 76 // it may ignore them. | 78 // it may ignore them. |
| 77 // | 79 // |
| 78 // |rules| is a list of Rule instances following the definition of the | 80 // |rules| is a list of Rule instances following the definition of the |
| 79 // declarative extension APIs. It is guaranteed that each rule in |rules| has | 81 // declarative extension APIs. It is guaranteed that each rule in |rules| has |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 // The name of the event with which rules are registered. | 234 // The name of the event with which rules are registered. |
| 233 const std::string event_name_; | 235 const std::string event_name_; |
| 234 | 236 |
| 235 // The key that identifies the context in which these rules apply. | 237 // The key that identifies the context in which these rules apply. |
| 236 WebViewKey webview_key_; | 238 WebViewKey webview_key_; |
| 237 | 239 |
| 238 RulesDictionary rules_; | 240 RulesDictionary rules_; |
| 239 | 241 |
| 240 // Signaled when we have finished reading from storage for all extensions that | 242 // Signaled when we have finished reading from storage for all extensions that |
| 241 // are loaded on startup. | 243 // are loaded on startup. |
| 242 OneShotEvent ready_; | 244 scoped_ptr<OneShotEvent> ready_; |
| 243 | 245 |
| 244 // The factory needs to be declared before |cache_delegate_|, so that it can | 246 // The factory needs to be declared before |cache_delegate_|, so that it can |
| 245 // produce a pointer as a construction argument for |cache_delegate_|. | 247 // produce a pointer as a construction argument for |cache_delegate_|. |
| 246 base::WeakPtrFactory<RulesRegistry> weak_ptr_factory_; | 248 base::WeakPtrFactory<RulesRegistry> weak_ptr_factory_; |
| 247 | 249 |
| 248 // |cache_delegate_| is owned by the registry service. If |cache_delegate_| is | 250 // |cache_delegate_| is owned by the registry service. If |cache_delegate_| is |
| 249 // NULL, then the storage functionality is disabled (this is used in tests). | 251 // NULL, then the storage functionality is disabled (this is used in tests). |
| 250 // This registry cannot own |cache_delegate_| because during the time after | 252 // This registry cannot own |cache_delegate_| because during the time after |
| 251 // rules registry service shuts down on UI thread, and the registry is | 253 // rules registry service shuts down on UI thread, and the registry is |
| 252 // destroyed on its thread, the use of the |cache_delegate_| would not be | 254 // destroyed on its thread, the use of the |cache_delegate_| would not be |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 typedef std::map<ExtensionId, std::set<RuleIdentifier> > RuleIdentifiersMap; | 289 typedef std::map<ExtensionId, std::set<RuleIdentifier> > RuleIdentifiersMap; |
| 288 RuleIdentifiersMap used_rule_identifiers_; | 290 RuleIdentifiersMap used_rule_identifiers_; |
| 289 int last_generated_rule_identifier_id_; | 291 int last_generated_rule_identifier_id_; |
| 290 | 292 |
| 291 DISALLOW_COPY_AND_ASSIGN(RulesRegistry); | 293 DISALLOW_COPY_AND_ASSIGN(RulesRegistry); |
| 292 }; | 294 }; |
| 293 | 295 |
| 294 } // namespace extensions | 296 } // namespace extensions |
| 295 | 297 |
| 296 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__ | 298 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__ |
| OLD | NEW |