| 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_WITH_CACHE_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H__ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "chrome/browser/extensions/api/declarative/rules_registry.h" | 9 #include "chrome/browser/extensions/api/declarative/rules_registry.h" |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> |
| 13 | 14 |
| 14 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/callback_forward.h" |
| 15 | 17 |
| 16 namespace extensions { | 18 namespace extensions { |
| 17 | 19 |
| 18 // A base class for RulesRegistries that takes care of storing the | 20 // A base class for RulesRegistries that takes care of storing the |
| 19 // RulesRegistry::Rule objects. | 21 // RulesRegistry::Rule objects. |
| 20 class RulesRegistryWithCache : public RulesRegistry { | 22 class RulesRegistryWithCache : public RulesRegistry { |
| 21 public: | 23 public: |
| 22 RulesRegistryWithCache(); | 24 class Delegate { |
| 25 public: |
| 26 virtual ~Delegate() {} |
| 27 |
| 28 // Returns true if the registry is ready and ready to start processing |
| 29 // rules. |
| 30 virtual bool IsReady() = 0; |
| 31 |
| 32 // Called to notify the Delegate that the rules for the given extension |
| 33 // have changed. |
| 34 virtual void OnRulesChanged(RulesRegistryWithCache* rules_registry, |
| 35 const std::string& extension_id) = 0; |
| 36 }; |
| 37 |
| 38 explicit RulesRegistryWithCache(Delegate* delegate); |
| 39 |
| 40 // Returns true if we are ready to process rules. |
| 41 bool IsReady() { |
| 42 return !delegate_.get() || delegate_->IsReady(); |
| 43 } |
| 44 |
| 45 // Add a callback to call when we transition to Ready. |
| 46 void AddReadyCallback(const base::Closure& callback); |
| 47 |
| 48 // Called by our delegate when we are ready. |
| 49 void OnReady(); |
| 23 | 50 |
| 24 // RulesRegistry implementation: | 51 // RulesRegistry implementation: |
| 25 virtual std::string AddRules( | 52 virtual std::string AddRules( |
| 26 const std::string& extension_id, | 53 const std::string& extension_id, |
| 27 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE; | 54 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE; |
| 28 virtual std::string RemoveRules( | 55 virtual std::string RemoveRules( |
| 29 const std::string& extension_id, | 56 const std::string& extension_id, |
| 30 const std::vector<std::string>& rule_identifiers) OVERRIDE; | 57 const std::vector<std::string>& rule_identifiers) OVERRIDE; |
| 31 virtual std::string RemoveAllRules( | 58 virtual std::string RemoveAllRules( |
| 32 const std::string& extension_id) OVERRIDE; | 59 const std::string& extension_id) OVERRIDE; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 53 const std::vector<std::string>& rule_identifiers) = 0; | 80 const std::vector<std::string>& rule_identifiers) = 0; |
| 54 virtual std::string RemoveAllRulesImpl( | 81 virtual std::string RemoveAllRulesImpl( |
| 55 const std::string& extension_id) = 0; | 82 const std::string& extension_id) = 0; |
| 56 | 83 |
| 57 private: | 84 private: |
| 58 typedef std::string ExtensionId; | 85 typedef std::string ExtensionId; |
| 59 typedef std::string RuleId; | 86 typedef std::string RuleId; |
| 60 typedef std::pair<ExtensionId, RuleId> RulesDictionaryKey; | 87 typedef std::pair<ExtensionId, RuleId> RulesDictionaryKey; |
| 61 typedef std::map<RulesDictionaryKey, linked_ptr<RulesRegistry::Rule> > | 88 typedef std::map<RulesDictionaryKey, linked_ptr<RulesRegistry::Rule> > |
| 62 RulesDictionary; | 89 RulesDictionary; |
| 90 |
| 91 // Notify our delegate that the given extension's rules have changed. |
| 92 void NotifyRulesChanged(const std::string& extension_id); |
| 93 |
| 63 RulesDictionary rules_; | 94 RulesDictionary rules_; |
| 95 |
| 96 scoped_ptr<Delegate> delegate_; |
| 97 std::vector<base::Closure> ready_callbacks_; |
| 64 }; | 98 }; |
| 65 | 99 |
| 66 } // namespace extensions | 100 } // namespace extensions |
| 67 | 101 |
| 68 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H
__ | 102 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H
__ |
| OLD | NEW |