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 // ProcessChangedRules can never be called, |storage_on_ui_| is NULL. |
| 181 NEVER_PROCESS, |
| 182 // A task to call ProcessChangedRules is scheduled for future execution. |
| 183 SCHEDULED_FOR_PROCESSING, |
| 184 // No task to call ProcessChangedRules is scheduled yet, but it is possible |
| 185 // to schedule one. |
| 186 NOT_SCHEDULED_FOR_PROCESSING |
| 187 }; |
179 | 188 |
180 // Common processing after extension's rules have changed. | 189 // Common processing after extension's rules have changed. |
181 void ProcessChangedRules(const std::string& extension_id); | 190 void ProcessChangedRules(const std::string& extension_id); |
182 | 191 |
| 192 // Calls ProcessChangedRules if |process_changed_rules_requested_| == |
| 193 // NOT_SCHEDULED_FOR_PROCESSING. |
| 194 void MaybeProcessChangedRules(const std::string& extension_id); |
| 195 |
183 // Process the callbacks once the registry gets ready. | 196 // Process the callbacks once the registry gets ready. |
184 void MarkReady(base::Time storage_init_time); | 197 void MarkReady(base::Time storage_init_time); |
185 | 198 |
186 // Deserialize the rules from the given Value object and add them to the | 199 // Deserialize the rules from the given Value object and add them to the |
187 // RulesRegistry. | 200 // RulesRegistry. |
188 void DeserializeAndAddRules(const std::string& extension_id, | 201 void DeserializeAndAddRules(const std::string& extension_id, |
189 scoped_ptr<base::Value> rules); | 202 scoped_ptr<base::Value> rules); |
190 | 203 |
191 | 204 |
192 RulesDictionary rules_; | 205 RulesDictionary rules_; |
193 | 206 |
194 // Signaled when we have finished reading from storage for all extensions that | 207 // Signaled when we have finished reading from storage for all extensions that |
195 // are loaded on startup. | 208 // are loaded on startup. |
196 OneShotEvent ready_; | 209 OneShotEvent ready_; |
197 | 210 |
198 // The factory needs to be declared before |storage_on_ui_|, so that it can | 211 // 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_|. | 212 // produce a pointer as a construction argument for |storage_on_ui_|. |
200 base::WeakPtrFactory<RulesRegistryWithCache> weak_ptr_factory_; | 213 base::WeakPtrFactory<RulesRegistryWithCache> weak_ptr_factory_; |
201 | 214 |
202 // |storage_on_ui_| is owned by the registry service. If |storage_on_ui_| is | 215 // |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). | 216 // 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 | 217 // 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 | 218 // 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 | 219 // 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. | 220 // safe. The registry only ever associates with one RuleStorageOnUI instance. |
208 const base::WeakPtr<RuleStorageOnUI> storage_on_ui_; | 221 const base::WeakPtr<RuleStorageOnUI> storage_on_ui_; |
209 | 222 |
| 223 ProcessChangedRulesState process_changed_rules_requested_; |
| 224 |
210 DISALLOW_COPY_AND_ASSIGN(RulesRegistryWithCache); | 225 DISALLOW_COPY_AND_ASSIGN(RulesRegistryWithCache); |
211 }; | 226 }; |
212 | 227 |
213 } // namespace extensions | 228 } // namespace extensions |
214 | 229 |
215 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H
__ | 230 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_WITH_CACHE_H
__ |
OLD | NEW |