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 CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H__ |
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H__ |
7 | 7 |
8 #include "chrome/browser/extensions/api/declarative/rules_registry.h" | 8 #include "chrome/browser/extensions/api/declarative/rules_registry.h" |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 const std::vector<std::string>& rule_identifiers) = 0; | 169 const std::vector<std::string>& rule_identifiers) = 0; |
170 virtual std::string RemoveAllRulesImpl( | 170 virtual std::string RemoveAllRulesImpl( |
171 const std::string& extension_id) = 0; | 171 const std::string& extension_id) = 0; |
172 | 172 |
173 private: | 173 private: |
174 typedef std::string ExtensionId; | 174 typedef std::string ExtensionId; |
175 typedef std::string RuleId; | 175 typedef std::string RuleId; |
176 typedef std::pair<ExtensionId, RuleId> RulesDictionaryKey; | 176 typedef std::pair<ExtensionId, RuleId> RulesDictionaryKey; |
177 typedef std::map<RulesDictionaryKey, linked_ptr<RulesRegistry::Rule> > | 177 typedef std::map<RulesDictionaryKey, linked_ptr<RulesRegistry::Rule> > |
178 RulesDictionary; | 178 RulesDictionary; |
179 enum ProcessChangedRulesState { | |
180 NEVER_PROCESS, | |
181 SCHEDULED_FOR_PROCESSING, | |
182 NOT_SCHEDULED_FOR_PROCESSING | |
183 }; | |
179 | 184 |
180 // Common processing after extension's rules have changed. | 185 // Common processing after extension's rules have changed. |
181 void ProcessChangedRules(const std::string& extension_id); | 186 void ProcessChangedRules(const std::string& extension_id); |
182 | 187 |
188 // Calls ProcessChangedRules if |process_changed_rules_requested_| == | |
189 // NOT_SCHEDULED_FOR_PROCESSING. | |
190 void MaybeProcessChangedRules(const std::string& extension_id); | |
191 | |
183 // Process the callbacks once the registry gets ready. | 192 // Process the callbacks once the registry gets ready. |
184 void MarkReady(base::Time storage_init_time); | 193 void MarkReady(base::Time storage_init_time); |
185 | 194 |
186 // Deserialize the rules from the given Value object and add them to the | 195 // Deserialize the rules from the given Value object and add them to the |
187 // RulesRegistry. | 196 // RulesRegistry. |
188 void DeserializeAndAddRules(const std::string& extension_id, | 197 void DeserializeAndAddRules(const std::string& extension_id, |
189 scoped_ptr<base::Value> rules); | 198 scoped_ptr<base::Value> rules); |
190 | 199 |
191 | 200 |
192 RulesDictionary rules_; | 201 RulesDictionary rules_; |
193 | 202 |
194 // Signaled when we have finished reading from storage for all extensions that | 203 // Signaled when we have finished reading from storage for all extensions that |
195 // are loaded on startup. | 204 // are loaded on startup. |
196 OneShotEvent ready_; | 205 OneShotEvent ready_; |
197 | 206 |
198 // The factory needs to be declared before |storage_on_ui_|, so that it can | 207 // The factory needs to be declared before |storage_on_ui_|, so that it can |
199 // produce a pointer as a construction argument for |storage_on_ui_|. | 208 // produce a pointer as a construction argument for |storage_on_ui_|. |
200 base::WeakPtrFactory<RulesRegistryWithCache> weak_ptr_factory_; | 209 base::WeakPtrFactory<RulesRegistryWithCache> weak_ptr_factory_; |
201 | 210 |
202 // |storage_on_ui_| is owned by the registry service. If |storage_on_ui_| is | 211 // |storage_on_ui_| is owned by the registry service. If |storage_on_ui_| is |
203 // NULL, then the storage functionality is disabled (this is used in tests). | 212 // NULL, then the storage functionality is disabled (this is used in tests). |
204 // This registry cannot own |storage_on_ui_| because during the time after | 213 // This registry cannot own |storage_on_ui_| because during the time after |
205 // rules registry service shuts down on UI thread, and the registry is | 214 // rules registry service shuts down on UI thread, and the registry is |
206 // destroyed on its thread, the use of the |storage_on_ui_| would not be | 215 // destroyed on its thread, the use of the |storage_on_ui_| would not be |
207 // safe. The registry only ever associates with one RuleStorageOnUI instance. | 216 // safe. The registry only ever associates with one RuleStorageOnUI instance. |
208 const base::WeakPtr<RuleStorageOnUI> storage_on_ui_; | 217 const base::WeakPtr<RuleStorageOnUI> storage_on_ui_; |
209 | 218 |
219 // Possible values: | |
220 // NEVER_PROCESS -- ProcessChangedRules can never be called, because | |
221 // |storage_on_ui_| is NULL. | |
222 // SCHEDULED_FOR_PROCESSING -- a task to call ProcessChangedRules is scheduled | |
223 // for execution in the future. | |
224 // NOT_SCHEDULED_FOR_PROCESSING -- no task to call ProcessChangedRules is | |
225 // scheduled yet, but it is possible to schedule one. | |
battre
2013/06/04 08:22:34
nit: I think this should go to the typedef above.
| |
226 ProcessChangedRulesState process_changed_rules_requested_; | |
227 | |
210 DISALLOW_COPY_AND_ASSIGN(RulesRegistryWithCache); | 228 DISALLOW_COPY_AND_ASSIGN(RulesRegistryWithCache); |
211 }; | 229 }; |
212 | 230 |
213 } // namespace extensions | 231 } // namespace extensions |
214 | 232 |
215 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H __ | 233 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H __ |
OLD | NEW |