#ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H__
#define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H__
#include "chrome/browser/extensions/api/declarative/rules_registry.h"
#include <map>
#include <string>
#include <vector>
#include "base/compiler_specific.h"
#include "base/callback_forward.h"
namespace extensions {
class RulesRegistryWithCache : public RulesRegistry {
public:
class Delegate {
public:
virtual ~Delegate() {}
virtual bool IsReady() = 0;
virtual void OnRulesChanged(RulesRegistryWithCache* rules_registry,
const std::string& extension_id) = 0;
};
explicit RulesRegistryWithCache(Delegate* delegate);
bool IsReady() {
return !delegate_.get() || delegate_->IsReady();
}
void AddReadyCallback(const base::Closure& callback);
void OnReady();
virtual std::string AddRules(
const std::string& extension_id,
const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE;
virtual std::string RemoveRules(
const std::string& extension_id,
const std::vector<std::string>& rule_identifiers) OVERRIDE;
virtual std::string RemoveAllRules(
const std::string& extension_id) OVERRIDE;
virtual std::string GetRules(
const std::string& extension_id,
const std::vector<std::string>& rule_identifiers,
std::vector<linked_ptr<RulesRegistry::Rule> >* out) OVERRIDE;
virtual std::string GetAllRules(
const std::string& extension_id,
std::vector<linked_ptr<RulesRegistry::Rule> >* out) OVERRIDE;
virtual void OnExtensionUnloaded(const std::string& extension_id) OVERRIDE;
virtual content::BrowserThread::ID GetOwnerThread() const = 0;
protected:
virtual ~RulesRegistryWithCache();
virtual std::string AddRulesImpl(
const std::string& extension_id,
const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) = 0;
virtual std::string RemoveRulesImpl(
const std::string& extension_id,
const std::vector<std::string>& rule_identifiers) = 0;
virtual std::string RemoveAllRulesImpl(
const std::string& extension_id) = 0;
private:
typedef std::string ExtensionId;
typedef std::string RuleId;
typedef std::pair<ExtensionId, RuleId> RulesDictionaryKey;
typedef std::map<RulesDictionaryKey, linked_ptr<RulesRegistry::Rule> >
RulesDictionary;
void NotifyRulesChanged(const std::string& extension_id);
RulesDictionary rules_;
scoped_ptr<Delegate> delegate_;
std::vector<base::Closure> ready_callbacks_;
};
}
#endif