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

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: Implemented ID and priority generation 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 <set>
11 #include <string>
12 #include <vector>
13
14 #include "base/basictypes.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/values.h"
17 #include "chrome/browser/extensions/api/declarative/rules_registry.h"
18 #include "chrome/browser/profiles/profile_keyed_service.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21
22 class Profile;
23
24 namespace extensions {
25 class RuleIdentifier;
26 }
27
28 namespace content {
29 class NotificationSource;
30 class NotificationSource;
31 }
32
33 namespace extensions {
34
35 // This is a dispatcher that delegates function calls to other RuleRegistries.
36 // Use the RulesRegistryServiceFactory to retrieve an instance of this class.
not at google - send to devlin 2012/02/02 11:59:16 Why the need for RulesRegistryServiceFactory? Can
battre 2012/02/02 19:12:36 I raised this concern in a previous Patch Set vers
Aaron Boodman 2012/02/03 18:04:51 It is OK to add members to ExtensionService right
37 class RulesRegistryService
38 : public ProfileKeyedService, content::NotificationObserver {
39 public:
40 RulesRegistryService();
41 virtual ~RulesRegistryService();
42 void Init(Profile* profile);
43
44 // Registers a RuleRegistry such that all calls for |event_name| are
45 // dispatched to this RuleRegistry.
46 // Public for testing.
47 void RegisterRuleRegistry(
not at google - send to devlin 2012/02/02 11:59:16 s/Rule/Rules/
battre 2012/02/02 19:12:36 Done.
48 const std::string& event_name,
49 scoped_ptr<RulesRegistry> rule_registry);
50
51 // RulesRegistry alike implementation. We add an additional |event_name|
52 // to each function, which represents the name of the JavaScript object
53 // on which the function was called.
not at google - send to devlin 2012/02/02 11:59:16 Is it possible to move much of the logic in this c
Aaron Boodman 2012/02/02 16:28:51 Feels like overdesign to use a decorator to add lo
Aaron Boodman 2012/02/02 16:30:25 Sorry, I meant to remove this paragraph. I think t
battre 2012/02/02 19:12:36 At first I considered this overdesign as well. But
54 bool AddRules(const std::string& event_name,
55 const std::string& extension_id,
56 const std::vector<DictionaryValue*>& rules,
57 RulesRegistry::SetErrorCallback set_error_callback);
58 bool RemoveRules(const std::string& event_name,
59 const std::string& extension_id,
60 const std::vector<std::string>& rule_identifiers,
61 RulesRegistry::SetErrorCallback set_error_callback);
62 void GetRules(const std::string& event_name,
63 const std::string& extension_id,
64 const std::vector<std::string>& rule_identifiers,
65 std::vector<DictionaryValue*>* out);
66 void OnExtensionUnloaded(const std::string& extension_id);
67
68 private:
69 // Maps event names to RuleRegistries that handle these events.
70 // Owns the RuleRegistry objects.
71 typedef std::map<std::string, RulesRegistry*> RulesRegistryMap;
72
73 // Returns whether any existing rule is registered with identifier |id|.
74 bool IsUniqueId(const RuleIdentifier& id) const;
75
76 // Creates a ID that is unique within the scope of
77 // (|extension_id|, |event_name|).
78 std::string GenerateUniqueId(std::string extension_id,
79 std::string event_name);
80
81 // Verifies that all |rules| have unique IDs or initializes them with
82 // unique IDs if they don't have one. In case of duplicate IDs, this function
83 // calls |set_error_callback| and returns false.
84 bool CheckAndFillInOptionalRules(
85 const std::string& event_name,
86 const std::string& extension_id,
87 const std::vector<DictionaryValue*>& rules,
88 RulesRegistry::SetErrorCallback set_error_callback);
89
90 // Initializes the priority fields in case they have not been set.
91 void FillInOptionalPriorities(const std::vector<DictionaryValue*>& rules);
92
93 // Implementation of content::NotificationObserver.
94 virtual void Observe(int type,
95 const content::NotificationSource& source,
96 const content::NotificationDetails& details) OVERRIDE;
97
98 content::NotificationRegistrar registrar_;
99
100 RulesRegistryMap rule_registries_;
101
102 std::set<RuleIdentifier> used_rule_identifiers_;
103 int last_generated_rule_identifier_id_;
104
105 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService);
106 };
107
108 }
109
110 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698