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

Side by Side Diff: extensions/browser/api/declarative/rules_registry.h

Issue 1158693006: Create a mechanism define declarative rules via the extension manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_H__ 5 #ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_H__
6 #define EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_H__ 6 #define EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_H__
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 13 matching lines...) Expand all
24 namespace content { 24 namespace content {
25 class BrowserContext; 25 class BrowserContext;
26 } 26 }
27 27
28 namespace base { 28 namespace base {
29 class Value; 29 class Value;
30 } // namespace base 30 } // namespace base
31 31
32 namespace extensions { 32 namespace extensions {
33 33
34 class Extension;
34 class RulesCacheDelegate; 35 class RulesCacheDelegate;
35 36
36 // A base class for RulesRegistries that takes care of storing the 37 // A base class for RulesRegistries that takes care of storing the
37 // RulesRegistry::Rule objects. It contains all the methods that need to run on 38 // RulesRegistry::Rule objects. It contains all the methods that need to run on
38 // the registry thread; methods that need to run on the UI thread are separated 39 // the registry thread; methods that need to run on the UI thread are separated
39 // in the RulesCacheDelegate object. 40 // in the RulesCacheDelegate object.
40 class RulesRegistry : public base::RefCountedThreadSafe<RulesRegistry> { 41 class RulesRegistry : public base::RefCountedThreadSafe<RulesRegistry> {
41 public: 42 public:
42 typedef extensions::core_api::events::Rule Rule; 43 typedef extensions::core_api::events::Rule Rule;
43 44
(...skipping 25 matching lines...) Expand all
69 // registered before, unless it has been removed again. 70 // registered before, unless it has been removed again.
70 // The ownership of rules remains with the caller. 71 // The ownership of rules remains with the caller.
71 // 72 //
72 // Returns an empty string if the function is successful or an error 73 // Returns an empty string if the function is successful or an error
73 // message otherwise. 74 // message otherwise.
74 // 75 //
75 // IMPORTANT: This function is atomic. Either all rules that are deemed 76 // IMPORTANT: This function is atomic. Either all rules that are deemed
76 // relevant are added or none. 77 // relevant are added or none.
77 std::string AddRules( 78 std::string AddRules(
78 const std::string& extension_id, 79 const std::string& extension_id,
79 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules); 80 const std::vector<linked_ptr<RulesRegistry::Rule>>& rules,
81 bool from_manifest);
not at google - send to devlin 2015/06/05 16:16:14 This from_manifest flag shouldn't be part of the p
danduong 2015/06/05 21:35:07 Done.
80 82
81 // Unregisters all rules listed in |rule_identifiers| and owned by 83 // Unregisters all rules listed in |rule_identifiers| and owned by
82 // |extension_id| from this RulesRegistry. 84 // |extension_id| from this RulesRegistry.
83 // Some or all IDs in |rule_identifiers| may not be stored in this 85 // Some or all IDs in |rule_identifiers| may not be stored in this
84 // RulesRegistry and are ignored. 86 // RulesRegistry and are ignored.
85 // 87 //
86 // Returns an empty string if the function is successful or an error 88 // Returns an empty string if the function is successful or an error
87 // message otherwise. 89 // message otherwise.
88 // 90 //
89 // IMPORTANT: This function is atomic. Either all rules that are deemed 91 // IMPORTANT: This function is atomic. Either all rules that are deemed
(...skipping 13 matching lines...) Expand all
103 void GetRules(const std::string& extension_id, 105 void GetRules(const std::string& extension_id,
104 const std::vector<std::string>& rule_identifiers, 106 const std::vector<std::string>& rule_identifiers,
105 std::vector<linked_ptr<RulesRegistry::Rule> >* out); 107 std::vector<linked_ptr<RulesRegistry::Rule> >* out);
106 108
107 // Same as GetRules but returns all rules owned by |extension_id|. 109 // Same as GetRules but returns all rules owned by |extension_id|.
108 void GetAllRules(const std::string& extension_id, 110 void GetAllRules(const std::string& extension_id,
109 std::vector<linked_ptr<RulesRegistry::Rule> >* out); 111 std::vector<linked_ptr<RulesRegistry::Rule> >* out);
110 112
111 // Called to notify the RulesRegistry that the extension availability has 113 // Called to notify the RulesRegistry that the extension availability has
112 // changed, so that the registry can update which rules are active. 114 // changed, so that the registry can update which rules are active.
113 void OnExtensionUnloaded(const std::string& extension_id); 115 void OnExtensionUnloaded(const Extension* extension);
114 void OnExtensionUninstalled(const std::string& extension_id); 116 void OnExtensionUninstalled(const Extension* extension);
115 void OnExtensionLoaded(const std::string& extension_id); 117 void OnExtensionLoaded(const Extension* extension);
not at google - send to devlin 2015/06/05 16:16:14 Thanks for doing this.
danduong 2015/06/05 21:35:07 Acknowledged.
116 118
117 // Returns the number of entries in used_rule_identifiers_ for leak detection. 119 // Returns the number of entries in used_rule_identifiers_ for leak detection.
118 // Every ExtensionId counts as one entry, even if it contains no rules. 120 // Every ExtensionId counts as one entry, even if it contains no rules.
119 size_t GetNumberOfUsedRuleIdentifiersForTesting() const; 121 size_t GetNumberOfUsedRuleIdentifiersForTesting() const;
120 122
121 // Returns the RulesCacheDelegate. This is used for testing. 123 // Returns the RulesCacheDelegate. This is used for testing.
122 RulesCacheDelegate* rules_cache_delegate_for_testing() const { 124 RulesCacheDelegate* rules_cache_delegate_for_testing() const {
123 return cache_delegate_.get(); 125 return cache_delegate_.get();
124 } 126 }
125 127
(...skipping 15 matching lines...) Expand all
141 143
142 // The precondition for calling this method is that all rules have unique IDs. 144 // The precondition for calling this method is that all rules have unique IDs.
143 // AddRules establishes this precondition and calls into this method. 145 // AddRules establishes this precondition and calls into this method.
144 // Stored rules already meet this precondition and so they avoid calling 146 // Stored rules already meet this precondition and so they avoid calling
145 // CheckAndFillInOptionalRules for improved performance. 147 // CheckAndFillInOptionalRules for improved performance.
146 // 148 //
147 // Returns an empty string if the function is successful or an error 149 // Returns an empty string if the function is successful or an error
148 // message otherwise. 150 // message otherwise.
149 std::string AddRulesNoFill( 151 std::string AddRulesNoFill(
150 const std::string& extension_id, 152 const std::string& extension_id,
151 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules); 153 const std::vector<linked_ptr<RulesRegistry::Rule>>& rules,
154 bool from_manifest);
152 155
153 // These functions need to apply the rules to the browser, while the base 156 // These functions need to apply the rules to the browser, while the base
154 // class will handle defaulting empty fields before calling *Impl, and will 157 // class will handle defaulting empty fields before calling *Impl, and will
155 // automatically cache the rules and re-call *Impl on browser startup. 158 // automatically cache the rules and re-call *Impl on browser startup.
156 virtual std::string AddRulesImpl( 159 virtual std::string AddRulesImpl(
157 const std::string& extension_id, 160 const std::string& extension_id,
158 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) = 0; 161 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) = 0;
159 virtual std::string RemoveRulesImpl( 162 virtual std::string RemoveRulesImpl(
160 const std::string& extension_id, 163 const std::string& extension_id,
161 const std::vector<std::string>& rule_identifiers) = 0; 164 const std::vector<std::string>& rule_identifiers) = 0;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 const content::BrowserThread::ID owner_thread_; 218 const content::BrowserThread::ID owner_thread_;
216 219
217 // The name of the event with which rules are registered. 220 // The name of the event with which rules are registered.
218 const std::string event_name_; 221 const std::string event_name_;
219 222
220 // The key that identifies the context in which these rules apply. 223 // The key that identifies the context in which these rules apply.
221 int id_; 224 int id_;
222 225
223 RulesDictionary rules_; 226 RulesDictionary rules_;
224 227
228 RulesDictionary manifest_rules_;
229
225 // Signaled when we have finished reading from storage for all extensions that 230 // Signaled when we have finished reading from storage for all extensions that
226 // are loaded on startup. 231 // are loaded on startup.
227 OneShotEvent ready_; 232 OneShotEvent ready_;
228 233
229 ProcessStateMap process_changed_rules_requested_; 234 ProcessStateMap process_changed_rules_requested_;
230 235
231 // Returns whether any existing rule is registered with identifier |rule_id| 236 // Returns whether any existing rule is registered with identifier |rule_id|
232 // for extension |extension_id|. 237 // for extension |extension_id|.
233 bool IsUniqueId(const std::string& extension_id, 238 bool IsUniqueId(const std::string& extension_id,
234 const std::string& rule_id) const; 239 const std::string& rule_id) const;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 base::WeakPtr<RulesCacheDelegate> cache_delegate_; 275 base::WeakPtr<RulesCacheDelegate> cache_delegate_;
271 276
272 base::WeakPtrFactory<RulesRegistry> weak_ptr_factory_; 277 base::WeakPtrFactory<RulesRegistry> weak_ptr_factory_;
273 278
274 DISALLOW_COPY_AND_ASSIGN(RulesRegistry); 279 DISALLOW_COPY_AND_ASSIGN(RulesRegistry);
275 }; 280 };
276 281
277 } // namespace extensions 282 } // namespace extensions
278 283
279 #endif // EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_H__ 284 #endif // EXTENSIONS_BROWSER_API_DECLARATIVE_RULES_REGISTRY_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698