Chromium Code Reviews| 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 <set> | |
| 12 | |
| 13 #include "base/compiler_specific.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 | |
| 16 namespace extensions { | |
| 17 class RuleIdentifier; | |
| 18 } | |
| 19 | |
| 20 namespace extensions { | |
| 21 | |
| 22 // Wrapper class for RulesRegistry objects that takes care that all optional | |
| 23 // fields of rules are filled with valid values. | |
| 24 class InitializingRulesRegistry : public RulesRegistry { | |
| 25 public: | |
| 26 explicit InitializingRulesRegistry(scoped_ptr<RulesRegistry> delegate); | |
| 27 virtual ~InitializingRulesRegistry(); | |
| 28 | |
| 29 // Implementation for RulesRegistry: | |
| 30 virtual bool AddRules(const std::string& extension_id, | |
| 31 const std::vector<DictionaryValue*>& rules, | |
| 32 std::string* error) OVERRIDE; | |
| 33 virtual bool RemoveRules(const std::string& extension_id, | |
| 34 const std::vector<std::string>& rule_identifiers, | |
| 35 std::string* error) OVERRIDE; | |
| 36 virtual void GetRules(const std::string& extension_id, | |
| 37 const std::vector<std::string>& rule_identifiers, | |
| 38 std::vector<DictionaryValue*>* out) OVERRIDE; | |
| 39 virtual void OnExtensionUnloaded(const std::string& extension_id) OVERRIDE; | |
| 40 | |
| 41 private: | |
| 42 // Returns whether any existing rule is registered with identifier |id|. | |
| 43 bool IsUniqueId(const RuleIdentifier& id) const; | |
| 44 | |
| 45 // Creates an ID that is unique within the scope of|extension_id|. | |
| 46 std::string GenerateUniqueId(std::string extension_id); | |
| 47 | |
| 48 // Verifies that all |rules| have unique IDs or initializes them with | |
| 49 // unique IDs if they don't have one. In case of duplicate IDs, this function | |
| 50 // fills |error| and returns false. | |
| 51 bool CheckAndFillInOptionalRules( | |
| 52 const std::string& extension_id, | |
| 53 const std::vector<DictionaryValue*>& rules, | |
| 54 std::string* error); | |
| 55 | |
| 56 // Initializes the priority fields in case they have not been set. | |
| 57 void FillInOptionalPriorities(const std::vector<DictionaryValue*>& rules); | |
| 58 | |
| 59 // Removes all |identifiers| of |extension_id| from |used_rule_identifiers_|. | |
| 60 void RemoveUsedRuleIdentifiers(const std::string& extension_id, | |
| 61 const std::vector<std::string>& identifiers); | |
| 62 | |
| 63 scoped_ptr<RulesRegistry> delegate_; | |
| 64 | |
| 65 std::set<RuleIdentifier> used_rule_identifiers_; | |
|
not at google - send to devlin
2012/02/07 03:25:10
Is there any reason why this can't be
std::map<st
battre
2012/02/07 18:45:33
Good point. This was not possible before the refac
| |
| 66 int last_generated_rule_identifier_id_; | |
| 67 }; | |
| 68 | |
| 69 } // namespace extensions | |
| 70 | |
| 71 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY _H__ | |
| OLD | NEW |