| Index: chrome/browser/extensions/api/declarative/rules_registry_service.cc
|
| diff --git a/chrome/browser/extensions/api/declarative/rules_registry_service.cc b/chrome/browser/extensions/api/declarative/rules_registry_service.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0285fb50559cd60839b80cb1c9e1a497e4e88608
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/declarative/rules_registry_service.cc
|
| @@ -0,0 +1,93 @@
|
| +// 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.
|
| +
|
| +#include "chrome/browser/extensions/api/declarative/rules_registry_service.h"
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/logging.h"
|
| +#include "base/stl_util.h"
|
| +#include "chrome/common/chrome_notification_types.h"
|
| +#include "chrome/common/extensions/extension.h"
|
| +#include "content/public/browser/notification_details.h"
|
| +#include "content/public/browser/notification_source.h"
|
| +
|
| +namespace extensions {
|
| +
|
| +RulesRegistryService::RulesRegistryService() {
|
| +}
|
| +
|
| +RulesRegistryService::~RulesRegistryService() {
|
| + STLDeleteContainerPairSecondPointers(
|
| + rule_registries_.begin(), rule_registries_.end());
|
| +}
|
| +
|
| +void RulesRegistryService::Init(Profile* profile) {
|
| + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
|
| + content::Source<Profile>(profile));
|
| +
|
| + // TODO(battre): Register various rules registries here.
|
| + // RegisterRuleRegistry("chrome.net", new FoobarRulesRegistry());
|
| +}
|
| +
|
| +void RulesRegistryService::RegisterRuleRegistry(
|
| + const std::string& event_name,
|
| + scoped_ptr<RulesRegistry> rule_registry) {
|
| + DCHECK(rule_registries_.find(event_name) == rule_registries_.end());
|
| + rule_registries_[event_name] = rule_registry.release();
|
| +}
|
| +
|
| +bool RulesRegistryService::AddRules(
|
| + const std::string& event_name,
|
| + const std::string& extension_id,
|
| + const std::vector<DictionaryValue*>& rules,
|
| + RulesRegistry::SetErrorCallback set_error_callback) {
|
| + DCHECK(rule_registries_.find(event_name) != rule_registries_.end());
|
| + // TODO(battre): Ensure that rules IDs are unique.
|
| + return rule_registries_[event_name]->AddRules(
|
| + extension_id, rules, set_error_callback);
|
| +}
|
| +
|
| +bool RulesRegistryService::RemoveRules(
|
| + const std::string& event_name,
|
| + const std::string& extension_id,
|
| + const std::vector<std::string>& rule_identifiers,
|
| + RulesRegistry::SetErrorCallback set_error_callback) {
|
| + DCHECK(rule_registries_.find(event_name) != rule_registries_.end());
|
| + return rule_registries_[event_name]->RemoveRules(
|
| + extension_id, rule_identifiers, set_error_callback);
|
| +}
|
| +
|
| +void RulesRegistryService::GetRules(
|
| + const std::string& event_name,
|
| + const std::string& extension_id,
|
| + const std::vector<std::string>& rule_identifiers,
|
| + std::vector<DictionaryValue*>* out) {
|
| + DCHECK(rule_registries_.find(event_name) != rule_registries_.end());
|
| + rule_registries_[event_name]->GetRules(extension_id, rule_identifiers, out);
|
| +}
|
| +
|
| +void RulesRegistryService::OnExtensionUnloaded(
|
| + const std::string& extension_id) {
|
| + RulesRegistryMap::iterator i;
|
| + for (i = rule_registries_.begin(); i != rule_registries_.end(); ++i)
|
| + i->second->OnExtensionUnloaded(extension_id);
|
| +}
|
| +
|
| +void RulesRegistryService::Observe(
|
| + int type,
|
| + const content::NotificationSource& source,
|
| + const content::NotificationDetails& details) {
|
| + switch (type) {
|
| + case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
|
| + const Extension* extension =
|
| + content::Details<UnloadedExtensionInfo>(details)->extension;
|
| + OnExtensionUnloaded(extension->id());
|
| + break;
|
| + }
|
| + default:
|
| + NOTREACHED();
|
| + }
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|