OLD | NEW |
---|---|
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 // registered before, unless it has been removed again. | 69 // registered before, unless it has been removed again. |
70 // The ownership of rules remains with the caller. | 70 // The ownership of rules remains with the caller. |
71 // | 71 // |
72 // Returns an empty string if the function is successful or an error | 72 // Returns an empty string if the function is successful or an error |
73 // message otherwise. | 73 // message otherwise. |
74 // | 74 // |
75 // IMPORTANT: This function is atomic. Either all rules that are deemed | 75 // IMPORTANT: This function is atomic. Either all rules that are deemed |
76 // relevant are added or none. | 76 // relevant are added or none. |
77 std::string AddRules( | 77 std::string AddRules( |
78 const std::string& extension_id, | 78 const std::string& extension_id, |
79 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules); | 79 const std::vector<linked_ptr<RulesRegistry::Rule>>& rules, |
80 bool from_manifest = false); | |
not at google - send to devlin
2015/06/04 22:00:51
default parameters are against style guide
danduong
2015/06/04 23:06:37
Done.
| |
80 | 81 |
81 // Unregisters all rules listed in |rule_identifiers| and owned by | 82 // Unregisters all rules listed in |rule_identifiers| and owned by |
82 // |extension_id| from this RulesRegistry. | 83 // |extension_id| from this RulesRegistry. |
83 // Some or all IDs in |rule_identifiers| may not be stored in this | 84 // Some or all IDs in |rule_identifiers| may not be stored in this |
84 // RulesRegistry and are ignored. | 85 // RulesRegistry and are ignored. |
85 // | 86 // |
86 // Returns an empty string if the function is successful or an error | 87 // Returns an empty string if the function is successful or an error |
87 // message otherwise. | 88 // message otherwise. |
88 // | 89 // |
89 // IMPORTANT: This function is atomic. Either all rules that are deemed | 90 // IMPORTANT: This function is atomic. Either all rules that are deemed |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 | 142 |
142 // The precondition for calling this method is that all rules have unique IDs. | 143 // The precondition for calling this method is that all rules have unique IDs. |
143 // AddRules establishes this precondition and calls into this method. | 144 // AddRules establishes this precondition and calls into this method. |
144 // Stored rules already meet this precondition and so they avoid calling | 145 // Stored rules already meet this precondition and so they avoid calling |
145 // CheckAndFillInOptionalRules for improved performance. | 146 // CheckAndFillInOptionalRules for improved performance. |
146 // | 147 // |
147 // Returns an empty string if the function is successful or an error | 148 // Returns an empty string if the function is successful or an error |
148 // message otherwise. | 149 // message otherwise. |
149 std::string AddRulesNoFill( | 150 std::string AddRulesNoFill( |
150 const std::string& extension_id, | 151 const std::string& extension_id, |
151 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules); | 152 const std::vector<linked_ptr<RulesRegistry::Rule>>& rules, |
153 bool from_manifest); | |
152 | 154 |
153 // These functions need to apply the rules to the browser, while the base | 155 // 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 | 156 // class will handle defaulting empty fields before calling *Impl, and will |
155 // automatically cache the rules and re-call *Impl on browser startup. | 157 // automatically cache the rules and re-call *Impl on browser startup. |
156 virtual std::string AddRulesImpl( | 158 virtual std::string AddRulesImpl( |
157 const std::string& extension_id, | 159 const std::string& extension_id, |
158 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) = 0; | 160 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) = 0; |
159 virtual std::string RemoveRulesImpl( | 161 virtual std::string RemoveRulesImpl( |
160 const std::string& extension_id, | 162 const std::string& extension_id, |
161 const std::vector<std::string>& rule_identifiers) = 0; | 163 const std::vector<std::string>& rule_identifiers) = 0; |
162 virtual std::string RemoveAllRulesImpl( | 164 virtual std::string RemoveAllRulesImpl( |
163 const std::string& extension_id) = 0; | 165 const std::string& extension_id) = 0; |
164 | 166 |
165 private: | 167 private: |
166 friend class base::RefCountedThreadSafe<RulesRegistry>; | 168 friend class base::RefCountedThreadSafe<RulesRegistry>; |
167 friend class RulesCacheDelegate; | 169 friend class RulesCacheDelegate; |
168 | 170 |
169 typedef std::string ExtensionId; | 171 typedef std::string ExtensionId; |
170 typedef std::string RuleId; | 172 typedef std::string RuleId; |
171 typedef std::pair<ExtensionId, RuleId> RulesDictionaryKey; | 173 typedef std::pair<ExtensionId, RuleId> RulesDictionaryKey; |
172 typedef std::map<RulesDictionaryKey, linked_ptr<RulesRegistry::Rule> > | 174 typedef std::map<RulesDictionaryKey, linked_ptr<RulesRegistry::Rule> > |
173 RulesDictionary; | 175 RulesDictionary; |
176 typedef std::set<RulesDictionaryKey> RuleIdSet; | |
174 enum ProcessChangedRulesState { | 177 enum ProcessChangedRulesState { |
175 // ProcessChangedRules can never be called, |cache_delegate_| is NULL. | 178 // ProcessChangedRules can never be called, |cache_delegate_| is NULL. |
176 NEVER_PROCESS, | 179 NEVER_PROCESS, |
177 // A task to call ProcessChangedRules is scheduled for future execution. | 180 // A task to call ProcessChangedRules is scheduled for future execution. |
178 SCHEDULED_FOR_PROCESSING, | 181 SCHEDULED_FOR_PROCESSING, |
179 // No task to call ProcessChangedRules is scheduled yet, but it is possible | 182 // No task to call ProcessChangedRules is scheduled yet, but it is possible |
180 // to schedule one. | 183 // to schedule one. |
181 NOT_SCHEDULED_FOR_PROCESSING | 184 NOT_SCHEDULED_FOR_PROCESSING |
182 }; | 185 }; |
183 typedef std::map<ExtensionId, ProcessChangedRulesState> ProcessStateMap; | 186 typedef std::map<ExtensionId, ProcessChangedRulesState> ProcessStateMap; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 RuleIdSet manifest_rule_ids_; | |
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 Loading... | |
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__ |
OLD | NEW |