| 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 bool AddRules(const std::string& extension_id, |
| 28 const std::vector<DictionaryValue*>& rules, |
| 29 std::string* error) OVERRIDE; |
| 30 virtual bool RemoveRules(const std::string& extension_id, |
| 31 const std::vector<std::string>& rule_identifiers, |
| 32 std::string* error) OVERRIDE; |
| 33 virtual bool RemoveAllRules(const std::string& extension_id, |
| 34 std::string* error) OVERRIDE; |
| 35 virtual void GetRules(const std::string& extension_id, |
| 36 const std::vector<std::string>& rule_identifiers, |
| 37 std::vector<DictionaryValue*>* out) OVERRIDE; |
| 38 virtual void GetAllRules(const std::string& extension_id, |
| 39 std::vector<DictionaryValue*>* out) OVERRIDE; |
| 40 virtual void OnExtensionUnloaded(const std::string& extension_id) OVERRIDE; |
| 41 |
| 42 private: |
| 43 // Returns whether any existing rule is registered with identifier |rule_id| |
| 44 // for extension |extension_id|. |
| 45 bool IsUniqueId(const std::string& extension_id, |
| 46 const std::string& rule_id) const; |
| 47 |
| 48 // Creates an ID that is unique within the scope of|extension_id|. |
| 49 std::string GenerateUniqueId(std::string extension_id); |
| 50 |
| 51 // Verifies that all |rules| have unique IDs or initializes them with |
| 52 // unique IDs if they don't have one. In case of duplicate IDs, this function |
| 53 // fills |error| and returns false. |
| 54 bool CheckAndFillInOptionalRules( |
| 55 const std::string& extension_id, |
| 56 const std::vector<DictionaryValue*>& rules, |
| 57 std::string* error); |
| 58 |
| 59 // Initializes the priority fields in case they have not been set. |
| 60 void FillInOptionalPriorities(const std::vector<DictionaryValue*>& rules); |
| 61 |
| 62 // Removes all |identifiers| of |extension_id| from |used_rule_identifiers_|. |
| 63 void RemoveUsedRuleIdentifiers(const std::string& extension_id, |
| 64 const std::vector<std::string>& identifiers); |
| 65 |
| 66 // Same as RemoveUsedRuleIdentifiers but operates on all rules of |
| 67 // |extension_id|. |
| 68 void RemoveAllUsedRuleIdentifiers(const std::string& extension_id); |
| 69 |
| 70 scoped_ptr<RulesRegistry> delegate_; |
| 71 |
| 72 typedef std::map<std::string, std::set<std::string> > RuleIdentifiersMap; |
| 73 RuleIdentifiersMap used_rule_identifiers_; |
| 74 int last_generated_rule_identifier_id_; |
| 75 }; |
| 76 |
| 77 } // namespace extensions |
| 78 |
| 79 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY
_H__ |
| OLD | NEW |