| Index: chrome/browser/extensions/api/declarative/initializing_rules_registry.h
|
| diff --git a/chrome/browser/extensions/api/declarative/initializing_rules_registry.h b/chrome/browser/extensions/api/declarative/initializing_rules_registry.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..843e9b79f8530599d5d2ff16104999b761e39ad9
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/declarative/initializing_rules_registry.h
|
| @@ -0,0 +1,71 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY_H__
|
| +#define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY_H__
|
| +#pragma once
|
| +
|
| +#include "chrome/browser/extensions/api/declarative/rules_registry.h"
|
| +
|
| +#include <set>
|
| +
|
| +#include "base/compiler_specific.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +
|
| +namespace extensions {
|
| +class RuleIdentifier;
|
| +}
|
| +
|
| +namespace extensions {
|
| +
|
| +// Wrapper class for RulesRegistry objects that takes care that all optional
|
| +// fields of rules are filled with valid values.
|
| +class InitializingRulesRegistry : public RulesRegistry {
|
| + public:
|
| + explicit InitializingRulesRegistry(scoped_ptr<RulesRegistry> delegate);
|
| + virtual ~InitializingRulesRegistry();
|
| +
|
| + // Implementation for RulesRegistry:
|
| + virtual bool AddRules(const std::string& extension_id,
|
| + const std::vector<DictionaryValue*>& rules,
|
| + std::string* error) OVERRIDE;
|
| + virtual bool RemoveRules(const std::string& extension_id,
|
| + const std::vector<std::string>& rule_identifiers,
|
| + std::string* error) OVERRIDE;
|
| + virtual void GetRules(const std::string& extension_id,
|
| + const std::vector<std::string>& rule_identifiers,
|
| + std::vector<DictionaryValue*>* out) OVERRIDE;
|
| + virtual void OnExtensionUnloaded(const std::string& extension_id) OVERRIDE;
|
| +
|
| + private:
|
| + // Returns whether any existing rule is registered with identifier |id|.
|
| + bool IsUniqueId(const RuleIdentifier& id) const;
|
| +
|
| + // Creates an ID that is unique within the scope of|extension_id|.
|
| + std::string GenerateUniqueId(std::string extension_id);
|
| +
|
| + // Verifies that all |rules| have unique IDs or initializes them with
|
| + // unique IDs if they don't have one. In case of duplicate IDs, this function
|
| + // fills |error| and returns false.
|
| + bool CheckAndFillInOptionalRules(
|
| + const std::string& extension_id,
|
| + const std::vector<DictionaryValue*>& rules,
|
| + std::string* error);
|
| +
|
| + // Initializes the priority fields in case they have not been set.
|
| + void FillInOptionalPriorities(const std::vector<DictionaryValue*>& rules);
|
| +
|
| + // Removes all |identifiers| of |extension_id| from |used_rule_identifiers_|.
|
| + void RemoveUsedRuleIdentifiers(const std::string& extension_id,
|
| + const std::vector<std::string>& identifiers);
|
| +
|
| + scoped_ptr<RulesRegistry> delegate_;
|
| +
|
| + std::set<RuleIdentifier> used_rule_identifiers_;
|
| + int last_generated_rule_identifier_id_;
|
| +};
|
| +
|
| +} // namespace extensions
|
| +
|
| +#endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY_H__
|
|
|