Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/extensions/api/declarative/rules_registry_service.h

Issue 9315010: RulesRegistry for declarative APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/values.h"
16 #include "chrome/browser/extensions/api/declarative/rules_registry.h"
17 #include "chrome/browser/profiles/profile_keyed_service.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20
21 class Profile;
22
23 namespace content {
24 class NotificationSource;
25 class NotificationSource;
26 }
27
28 namespace extensions {
29
30 // This is a dispatcher that delegates function calls to other RuleRegistries.
31 // Use the RulesRegistryServiceFactory to retrieve an instance of this class.
32 class RulesRegistryService
33 : public ProfileKeyedService, content::NotificationObserver {
battre 2012/01/31 21:03:54 Instead of making this a ProfileKeyedService we co
34 public:
35 RulesRegistryService();
36 virtual ~RulesRegistryService();
37 void Init(Profile* profile);
38
39 // Registers a RuleRegistry such that all calls for |event_name| are
40 // dispatched to this RuleRegistry.
41 // Public for testing.
42 void RegisterRuleRegistry(
43 const std::string& event_name,
44 scoped_ptr<RulesRegistry> rule_registry);
45
46 // RulesRegistry alike implementation. We add an additional |event_name|
47 // to each function, which represents the name of the JavaScript object
48 // on which the function was called.
49 bool AddRules(const std::string& event_name,
50 const std::string& extension_id,
51 const std::vector<DictionaryValue*>& rules,
52 RulesRegistry::SetErrorCallback set_error_callback);
53 bool RemoveRules(const std::string& event_name,
54 const std::string& extension_id,
55 const std::vector<std::string>& rule_identifiers,
56 RulesRegistry::SetErrorCallback set_error_callback);
57 void GetRules(const std::string& event_name,
58 const std::string& extension_id,
59 const std::vector<std::string>& rule_identifiers,
60 std::vector<DictionaryValue*>* out);
61 void OnExtensionUnloaded(const std::string& extension_id);
62
63 private:
64 // Maps event names to RuleRegistries that handle these events.
65 // Owns the RuleRegistry objects.
66 typedef std::map<std::string, RulesRegistry*> RulesRegistryMap;
67
68 // Implementation of content::NotificationObserver.
69 virtual void Observe(int type,
70 const content::NotificationSource& source,
71 const content::NotificationDetails& details) OVERRIDE;
72
73 content::NotificationRegistrar registrar_;
74
75 RulesRegistryMap rule_registries_;
76
77 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService);
78 };
79
80 }
81
82 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698