| 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_INITIALIZING_RULES_REGISTRY_H_
_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY_H_
_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY_H_
_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY_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 <set> | 12 #include <set> |
| 13 | 13 |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 | 16 |
| 17 namespace extensions { | 17 namespace extensions { |
| 18 | 18 |
| 19 // Wrapper class for RulesRegistry objects that takes care that all optional | 19 // Wrapper class for RulesRegistry objects that takes care that all optional |
| 20 // fields of rules are filled with valid values. | 20 // fields of rules are filled with valid values. |
| 21 class InitializingRulesRegistry : public RulesRegistry { | 21 class InitializingRulesRegistry : public RulesRegistry { |
| 22 public: | 22 public: |
| 23 enum Defaults { DEFAULT_PRIORITY = 100 }; | 23 enum Defaults { DEFAULT_PRIORITY = 100 }; |
| 24 | 24 |
| 25 explicit InitializingRulesRegistry(scoped_refptr<RulesRegistry> delegate); | 25 explicit InitializingRulesRegistry(scoped_refptr<RulesRegistry> delegate); |
| 26 virtual ~InitializingRulesRegistry(); | |
| 27 | 26 |
| 28 // Implementation for RulesRegistry: | 27 // Implementation for RulesRegistry: |
| 29 virtual std::string AddRules( | 28 virtual std::string AddRules( |
| 30 const std::string& extension_id, | 29 const std::string& extension_id, |
| 31 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE; | 30 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE; |
| 32 virtual std::string RemoveRules( | 31 virtual std::string RemoveRules( |
| 33 const std::string& extension_id, | 32 const std::string& extension_id, |
| 34 const std::vector<std::string>& rule_identifiers) OVERRIDE; | 33 const std::vector<std::string>& rule_identifiers) OVERRIDE; |
| 35 virtual std::string RemoveAllRules( | 34 virtual std::string RemoveAllRules( |
| 36 const std::string& extension_id) OVERRIDE; | 35 const std::string& extension_id) OVERRIDE; |
| 37 virtual std::string GetRules( | 36 virtual std::string GetRules( |
| 38 const std::string& extension_id, | 37 const std::string& extension_id, |
| 39 const std::vector<std::string>& rule_identifiers, | 38 const std::vector<std::string>& rule_identifiers, |
| 40 std::vector<linked_ptr<RulesRegistry::Rule> >* out) OVERRIDE; | 39 std::vector<linked_ptr<RulesRegistry::Rule> >* out) OVERRIDE; |
| 41 virtual std::string GetAllRules( | 40 virtual std::string GetAllRules( |
| 42 const std::string& extension_id, | 41 const std::string& extension_id, |
| 43 std::vector<linked_ptr<RulesRegistry::Rule> >* out) OVERRIDE; | 42 std::vector<linked_ptr<RulesRegistry::Rule> >* out) OVERRIDE; |
| 44 virtual void OnExtensionUnloaded(const std::string& extension_id) OVERRIDE; | 43 virtual void OnExtensionUnloaded(const std::string& extension_id) OVERRIDE; |
| 45 virtual content::BrowserThread::ID GetOwnerThread() const OVERRIDE; | 44 virtual content::BrowserThread::ID GetOwnerThread() const OVERRIDE; |
| 46 | 45 |
| 47 private: | 46 private: |
| 47 virtual ~InitializingRulesRegistry(); |
| 48 |
| 48 // Returns whether any existing rule is registered with identifier |rule_id| | 49 // Returns whether any existing rule is registered with identifier |rule_id| |
| 49 // for extension |extension_id|. | 50 // for extension |extension_id|. |
| 50 bool IsUniqueId(const std::string& extension_id, | 51 bool IsUniqueId(const std::string& extension_id, |
| 51 const std::string& rule_id) const; | 52 const std::string& rule_id) const; |
| 52 | 53 |
| 53 // Creates an ID that is unique within the scope of|extension_id|. | 54 // Creates an ID that is unique within the scope of|extension_id|. |
| 54 std::string GenerateUniqueId(const std::string& extension_id); | 55 std::string GenerateUniqueId(const std::string& extension_id); |
| 55 | 56 |
| 56 // Verifies that all |rules| have unique IDs or initializes them with | 57 // Verifies that all |rules| have unique IDs or initializes them with |
| 57 // unique IDs if they don't have one. In case of duplicate IDs, this function | 58 // unique IDs if they don't have one. In case of duplicate IDs, this function |
| (...skipping 17 matching lines...) Expand all Loading... |
| 75 scoped_refptr<RulesRegistry> delegate_; | 76 scoped_refptr<RulesRegistry> delegate_; |
| 76 | 77 |
| 77 typedef std::map<std::string, std::set<std::string> > RuleIdentifiersMap; | 78 typedef std::map<std::string, std::set<std::string> > RuleIdentifiersMap; |
| 78 RuleIdentifiersMap used_rule_identifiers_; | 79 RuleIdentifiersMap used_rule_identifiers_; |
| 79 int last_generated_rule_identifier_id_; | 80 int last_generated_rule_identifier_id_; |
| 80 }; | 81 }; |
| 81 | 82 |
| 82 } // namespace extensions | 83 } // namespace extensions |
| 83 | 84 |
| 84 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY
_H__ | 85 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY
_H__ |
| OLD | NEW |