| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY_H_
_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY_H_
_ |
| 7 #pragma once |
| 8 |
| 9 #include "chrome/browser/extensions/api/declarative/rules_registry.h" |
| 10 |
| 11 #include <map> |
| 12 #include <set> |
| 13 |
| 14 #include "base/compiler_specific.h" |
| 15 #include "base/memory/scoped_ptr.h" |
| 16 |
| 17 namespace extensions { |
| 18 |
| 19 // Wrapper class for RulesRegistry objects that takes care that all optional |
| 20 // fields of rules are filled with valid values. |
| 21 class InitializingRulesRegistry : public RulesRegistry { |
| 22 public: |
| 23 explicit InitializingRulesRegistry(scoped_ptr<RulesRegistry> delegate); |
| 24 virtual ~InitializingRulesRegistry(); |
| 25 |
| 26 // Implementation for RulesRegistry: |
| 27 virtual std::string AddRules( |
| 28 const std::string& extension_id, |
| 29 const std::vector<base::DictionaryValue*>& rules) OVERRIDE; |
| 30 virtual std::string RemoveRules( |
| 31 const std::string& extension_id, |
| 32 const std::vector<std::string>& rule_identifiers) OVERRIDE; |
| 33 virtual std::string RemoveAllRules( |
| 34 const std::string& extension_id) OVERRIDE; |
| 35 virtual std::string GetRules( |
| 36 const std::string& extension_id, |
| 37 const std::vector<std::string>& rule_identifiers, |
| 38 std::vector<base::DictionaryValue*>* out) OVERRIDE; |
| 39 virtual std::string GetAllRules( |
| 40 const std::string& extension_id, |
| 41 std::vector<base::DictionaryValue*>* out) OVERRIDE; |
| 42 virtual void OnExtensionUnloaded(const std::string& extension_id) OVERRIDE; |
| 43 |
| 44 private: |
| 45 // Returns whether any existing rule is registered with identifier |rule_id| |
| 46 // for extension |extension_id|. |
| 47 bool IsUniqueId(const std::string& extension_id, |
| 48 const std::string& rule_id) const; |
| 49 |
| 50 // Creates an ID that is unique within the scope of|extension_id|. |
| 51 std::string GenerateUniqueId(std::string extension_id); |
| 52 |
| 53 // Verifies that all |rules| have unique IDs or initializes them with |
| 54 // unique IDs if they don't have one. In case of duplicate IDs, this function |
| 55 // returns a non-empty error message. |
| 56 std::string CheckAndFillInOptionalRules( |
| 57 const std::string& extension_id, |
| 58 const std::vector<base::DictionaryValue*>& rules); |
| 59 |
| 60 // Initializes the priority fields in case they have not been set. |
| 61 void FillInOptionalPriorities( |
| 62 const std::vector<base::DictionaryValue*>& rules); |
| 63 |
| 64 // Removes all |identifiers| of |extension_id| from |used_rule_identifiers_|. |
| 65 void RemoveUsedRuleIdentifiers(const std::string& extension_id, |
| 66 const std::vector<std::string>& identifiers); |
| 67 |
| 68 // Same as RemoveUsedRuleIdentifiers but operates on all rules of |
| 69 // |extension_id|. |
| 70 void RemoveAllUsedRuleIdentifiers(const std::string& extension_id); |
| 71 |
| 72 scoped_ptr<RulesRegistry> delegate_; |
| 73 |
| 74 typedef std::map<std::string, std::set<std::string> > RuleIdentifiersMap; |
| 75 RuleIdentifiersMap used_rule_identifiers_; |
| 76 int last_generated_rule_identifier_id_; |
| 77 }; |
| 78 |
| 79 } // namespace extensions |
| 80 |
| 81 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY
_H__ |
| OLD | NEW |