| 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 | 13 |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 | 15 |
| 16 namespace extensions { | 16 namespace extensions { |
| 17 | 17 |
| 18 // A base class for RulesRegistries that takes care of storing the | 18 // A base class for RulesRegistries that takes care of storing the |
| 19 // RulesRegistry::Rule objects. | 19 // RulesRegistry::Rule objects. |
| 20 class RulesRegistryWithCache : public RulesRegistry { | 20 class RulesRegistryWithCache : public RulesRegistry { |
| 21 public: | 21 public: |
| 22 RulesRegistryWithCache(); | 22 RulesRegistryWithCache(); |
| 23 virtual ~RulesRegistryWithCache(); | |
| 24 | 23 |
| 25 // RulesRegistry implementation: | 24 // RulesRegistry implementation: |
| 26 virtual std::string AddRules( | 25 virtual std::string AddRules( |
| 27 const std::string& extension_id, | 26 const std::string& extension_id, |
| 28 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE; | 27 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE; |
| 29 virtual std::string RemoveRules( | 28 virtual std::string RemoveRules( |
| 30 const std::string& extension_id, | 29 const std::string& extension_id, |
| 31 const std::vector<std::string>& rule_identifiers) OVERRIDE; | 30 const std::vector<std::string>& rule_identifiers) OVERRIDE; |
| 32 virtual std::string RemoveAllRules( | 31 virtual std::string RemoveAllRules( |
| 33 const std::string& extension_id) OVERRIDE; | 32 const std::string& extension_id) OVERRIDE; |
| 34 virtual std::string GetRules( | 33 virtual std::string GetRules( |
| 35 const std::string& extension_id, | 34 const std::string& extension_id, |
| 36 const std::vector<std::string>& rule_identifiers, | 35 const std::vector<std::string>& rule_identifiers, |
| 37 std::vector<linked_ptr<RulesRegistry::Rule> >* out) OVERRIDE; | 36 std::vector<linked_ptr<RulesRegistry::Rule> >* out) OVERRIDE; |
| 38 virtual std::string GetAllRules( | 37 virtual std::string GetAllRules( |
| 39 const std::string& extension_id, | 38 const std::string& extension_id, |
| 40 std::vector<linked_ptr<RulesRegistry::Rule> >* out) OVERRIDE; | 39 std::vector<linked_ptr<RulesRegistry::Rule> >* out) OVERRIDE; |
| 41 virtual void OnExtensionUnloaded(const std::string& extension_id) OVERRIDE; | 40 virtual void OnExtensionUnloaded(const std::string& extension_id) OVERRIDE; |
| 42 virtual content::BrowserThread::ID GetOwnerThread() const = 0; | 41 virtual content::BrowserThread::ID GetOwnerThread() const = 0; |
| 43 | 42 |
| 44 protected: | 43 protected: |
| 44 virtual ~RulesRegistryWithCache(); |
| 45 |
| 45 // These functions need to provide the same functionality as their | 46 // These functions need to provide the same functionality as their |
| 46 // RulesRegistry counterparts. They need to be atomic. | 47 // RulesRegistry counterparts. They need to be atomic. |
| 47 virtual std::string AddRulesImpl( | 48 virtual std::string AddRulesImpl( |
| 48 const std::string& extension_id, | 49 const std::string& extension_id, |
| 49 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) = 0; | 50 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) = 0; |
| 50 virtual std::string RemoveRulesImpl( | 51 virtual std::string RemoveRulesImpl( |
| 51 const std::string& extension_id, | 52 const std::string& extension_id, |
| 52 const std::vector<std::string>& rule_identifiers) = 0; | 53 const std::vector<std::string>& rule_identifiers) = 0; |
| 53 virtual std::string RemoveAllRulesImpl( | 54 virtual std::string RemoveAllRulesImpl( |
| 54 const std::string& extension_id) = 0; | 55 const std::string& extension_id) = 0; |
| 55 | 56 |
| 56 private: | 57 private: |
| 57 typedef std::string ExtensionId; | 58 typedef std::string ExtensionId; |
| 58 typedef std::string RuleId; | 59 typedef std::string RuleId; |
| 59 typedef std::pair<ExtensionId, RuleId> RulesDictionaryKey; | 60 typedef std::pair<ExtensionId, RuleId> RulesDictionaryKey; |
| 60 typedef std::map<RulesDictionaryKey, linked_ptr<RulesRegistry::Rule> > | 61 typedef std::map<RulesDictionaryKey, linked_ptr<RulesRegistry::Rule> > |
| 61 RulesDictionary; | 62 RulesDictionary; |
| 62 RulesDictionary rules_; | 63 RulesDictionary rules_; |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 } // namespace extensions | 66 } // namespace extensions |
| 66 | 67 |
| 67 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H
__ | 68 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H
__ |
| OLD | NEW |