| 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_RULES_REGISTRY_SERVICE_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |
| 7 #pragma once |
| 8 |
| 9 #include <map> |
| 10 #include <string> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/linked_ptr.h" |
| 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/values.h" |
| 17 |
| 18 namespace extensions { |
| 19 class RulesRegistry; |
| 20 } |
| 21 |
| 22 namespace extensions { |
| 23 |
| 24 // This is a dispatcher that delegates function calls to other RuleRegistries |
| 25 // according to the names of events to which the RuleRegistries are mapped. |
| 26 class RulesRegistryService { |
| 27 public: |
| 28 RulesRegistryService(); |
| 29 virtual ~RulesRegistryService(); |
| 30 |
| 31 // Registers a RulesRegistry such that all calls for |event_name| are |
| 32 // dispatched to this RulesRegistry. The |rule_registry| is wrapped |
| 33 // in an InitializingRulesRegistry. |
| 34 // Public for testing. |
| 35 void RegisterRulesRegistry(const std::string& event_name, |
| 36 scoped_ptr<RulesRegistry> rule_registry); |
| 37 |
| 38 // RulesRegistry alike implementation. We add an additional |event_name| |
| 39 // to each function, which represents the name of the JavaScript object |
| 40 // on which the function was called. |
| 41 bool AddRules(const std::string& event_name, |
| 42 const std::string& extension_id, |
| 43 const std::vector<DictionaryValue*>& rules, |
| 44 std::string* error); |
| 45 bool RemoveRules(const std::string& event_name, |
| 46 const std::string& extension_id, |
| 47 const std::vector<std::string>& rule_identifiers, |
| 48 std::string* error); |
| 49 void GetRules(const std::string& event_name, |
| 50 const std::string& extension_id, |
| 51 const std::vector<std::string>& rule_identifiers, |
| 52 std::vector<DictionaryValue*>* out); |
| 53 void OnExtensionUnloaded(const std::string& extension_id); |
| 54 |
| 55 private: |
| 56 // Maps event names to RuleRegistries that handle these events. |
| 57 // Owns the RuleRegistry objects. |
| 58 typedef std::map<std::string, linked_ptr<RulesRegistry> > RulesRegistryMap; |
| 59 RulesRegistryMap rule_registries_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); |
| 62 }; |
| 63 |
| 64 } // namespace extensions |
| 65 |
| 66 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |
| OLD | NEW |