| 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. This is called exactly once, |
| 49 // if we have a delegate. |
| 50 void OnReady(); |
| 23 | 51 |
| 24 // RulesRegistry implementation: | 52 // RulesRegistry implementation: |
| 25 virtual std::string AddRules( | 53 virtual std::string AddRules( |
| 26 const std::string& extension_id, | 54 const std::string& extension_id, |
| 27 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE; | 55 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE; |
| 28 virtual std::string RemoveRules( | 56 virtual std::string RemoveRules( |
| 29 const std::string& extension_id, | 57 const std::string& extension_id, |
| 30 const std::vector<std::string>& rule_identifiers) OVERRIDE; | 58 const std::vector<std::string>& rule_identifiers) OVERRIDE; |
| 31 virtual std::string RemoveAllRules( | 59 virtual std::string RemoveAllRules( |
| 32 const std::string& extension_id) OVERRIDE; | 60 const std::string& extension_id) OVERRIDE; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 53 const std::vector<std::string>& rule_identifiers) = 0; | 81 const std::vector<std::string>& rule_identifiers) = 0; |
| 54 virtual std::string RemoveAllRulesImpl( | 82 virtual std::string RemoveAllRulesImpl( |
| 55 const std::string& extension_id) = 0; | 83 const std::string& extension_id) = 0; |
| 56 | 84 |
| 57 private: | 85 private: |
| 58 typedef std::string ExtensionId; | 86 typedef std::string ExtensionId; |
| 59 typedef std::string RuleId; | 87 typedef std::string RuleId; |
| 60 typedef std::pair<ExtensionId, RuleId> RulesDictionaryKey; | 88 typedef std::pair<ExtensionId, RuleId> RulesDictionaryKey; |
| 61 typedef std::map<RulesDictionaryKey, linked_ptr<RulesRegistry::Rule> > | 89 typedef std::map<RulesDictionaryKey, linked_ptr<RulesRegistry::Rule> > |
| 62 RulesDictionary; | 90 RulesDictionary; |
| 91 |
| 92 // Notify our delegate that the given extension's rules have changed. |
| 93 void NotifyRulesChanged(const std::string& extension_id); |
| 94 |
| 63 RulesDictionary rules_; | 95 RulesDictionary rules_; |
| 96 |
| 97 scoped_ptr<Delegate> delegate_; |
| 98 std::vector<base::Closure> ready_callbacks_; |
| 64 }; | 99 }; |
| 65 | 100 |
| 66 } // namespace extensions | 101 } // namespace extensions |
| 67 | 102 |
| 68 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H
__ | 103 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H
__ |
| OLD | NEW |