Chromium Code Reviews| Index: chrome/browser/extensions/api/declarative/rules_registry_service.h |
| diff --git a/chrome/browser/extensions/api/declarative/rules_registry_service.h b/chrome/browser/extensions/api/declarative/rules_registry_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4870178ed2cea51053da48eda5f7534599f1eb25 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/declarative/rules_registry_service.h |
| @@ -0,0 +1,82 @@ |
| +// 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_RULES_REGISTRY_SERVICE_H__ |
| +#define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |
| +#pragma once |
| + |
| +#include <map> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/extensions/api/declarative/rules_registry.h" |
| +#include "chrome/browser/profiles/profile_keyed_service.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_registrar.h" |
| + |
| +class Profile; |
| + |
| +namespace content { |
| +class NotificationSource; |
| +class NotificationSource; |
| +} |
| + |
| +namespace extensions { |
| + |
| +// This is a dispatcher that delegates function calls to other RuleRegistries. |
| +// Use the RulesRegistryServiceFactory to retrieve an instance of this class. |
| +class RulesRegistryService |
| + : public ProfileKeyedService, content::NotificationObserver { |
|
battre
2012/01/31 21:03:54
Instead of making this a ProfileKeyedService we co
|
| + public: |
| + RulesRegistryService(); |
| + virtual ~RulesRegistryService(); |
| + void Init(Profile* profile); |
| + |
| + // Registers a RuleRegistry such that all calls for |event_name| are |
| + // dispatched to this RuleRegistry. |
| + // Public for testing. |
| + void RegisterRuleRegistry( |
| + const std::string& event_name, |
| + scoped_ptr<RulesRegistry> rule_registry); |
| + |
| + // RulesRegistry alike implementation. We add an additional |event_name| |
| + // to each function, which represents the name of the JavaScript object |
| + // on which the function was called. |
| + bool AddRules(const std::string& event_name, |
| + const std::string& extension_id, |
| + const std::vector<DictionaryValue*>& rules, |
| + RulesRegistry::SetErrorCallback set_error_callback); |
| + bool RemoveRules(const std::string& event_name, |
| + const std::string& extension_id, |
| + const std::vector<std::string>& rule_identifiers, |
| + RulesRegistry::SetErrorCallback set_error_callback); |
| + void GetRules(const std::string& event_name, |
| + const std::string& extension_id, |
| + const std::vector<std::string>& rule_identifiers, |
| + std::vector<DictionaryValue*>* out); |
| + void OnExtensionUnloaded(const std::string& extension_id); |
| + |
| + private: |
| + // Maps event names to RuleRegistries that handle these events. |
| + // Owns the RuleRegistry objects. |
| + typedef std::map<std::string, RulesRegistry*> RulesRegistryMap; |
| + |
| + // Implementation of content::NotificationObserver. |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + |
| + content::NotificationRegistrar registrar_; |
| + |
| + RulesRegistryMap rule_registries_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); |
| +}; |
| + |
| +} |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |