OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/extensions/api/declarative/rules_cache_delegate.h" | 5 #include "chrome/browser/extensions/api/declarative/rules_cache_delegate.h" |
6 | 6 |
7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/extensions/api/declarative/rules_registry.h" | 8 #include "chrome/browser/extensions/api/declarative/rules_registry.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
11 #include "chrome/browser/extensions/state_store.h" | 11 #include "chrome/browser/extensions/state_store.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "content/public/browser/notification_details.h" | 13 #include "content/public/browser/notification_details.h" |
14 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
15 #include "extensions/browser/extension_registry.h" | |
15 #include "extensions/browser/extension_system.h" | 16 #include "extensions/browser/extension_system.h" |
16 #include "extensions/browser/info_map.h" | 17 #include "extensions/browser/info_map.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // Returns the key to use for storing declarative rules in the state store. | 21 // Returns the key to use for storing declarative rules in the state store. |
21 std::string GetDeclarativeRuleStorageKey(const std::string& event_name, | 22 std::string GetDeclarativeRuleStorageKey(const std::string& event_name, |
22 bool incognito) { | 23 bool incognito) { |
23 if (incognito) | 24 if (incognito) |
24 return "declarative_rules.incognito." + event_name; | 25 return "declarative_rules.incognito." + event_name; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 | 69 |
69 profile_ = registry->profile(); | 70 profile_ = registry->profile(); |
70 storage_key_ = | 71 storage_key_ = |
71 GetDeclarativeRuleStorageKey(registry->event_name(), | 72 GetDeclarativeRuleStorageKey(registry->event_name(), |
72 profile_->IsOffTheRecord()); | 73 profile_->IsOffTheRecord()); |
73 rules_stored_key_ = GetRulesStoredKey(registry->event_name(), | 74 rules_stored_key_ = GetRulesStoredKey(registry->event_name(), |
74 profile_->IsOffTheRecord()); | 75 profile_->IsOffTheRecord()); |
75 rules_registry_thread_ = registry->owner_thread(); | 76 rules_registry_thread_ = registry->owner_thread(); |
76 | 77 |
77 ExtensionSystem& system = *ExtensionSystem::Get(profile_); | 78 ExtensionSystem& system = *ExtensionSystem::Get(profile_); |
78 extensions::StateStore* store = system.rules_store(); | 79 StateStore* store = system.rules_store(); |
79 if (store) | 80 if (store) |
80 store->RegisterKey(storage_key_); | 81 store->RegisterKey(storage_key_); |
81 | 82 |
82 if (profile_->IsOffTheRecord()) | 83 if (profile_->IsOffTheRecord()) |
83 log_storage_init_delay_ = false; | 84 log_storage_init_delay_ = false; |
84 | 85 |
85 system.ready().Post( | 86 system.ready().Post( |
86 FROM_HERE, | 87 FROM_HERE, |
87 base::Bind(&RulesCacheDelegate::ReadRulesForInstalledExtensions, | 88 base::Bind(&RulesCacheDelegate::ReadRulesForInstalledExtensions, |
88 weak_ptr_factory_.GetWeakPtr())); | 89 weak_ptr_factory_.GetWeakPtr())); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 if (log_storage_init_delay_ && storage_init_time_.is_null()) | 156 if (log_storage_init_delay_ && storage_init_time_.is_null()) |
156 storage_init_time_ = base::Time::Now(); | 157 storage_init_time_ = base::Time::Now(); |
157 | 158 |
158 if (!GetDeclarativeRulesStored(extension_id)) { | 159 if (!GetDeclarativeRulesStored(extension_id)) { |
159 ExtensionSystem::Get(profile_)->ready().Post( | 160 ExtensionSystem::Get(profile_)->ready().Post( |
160 FROM_HERE, base::Bind(&RulesCacheDelegate::CheckIfReady, | 161 FROM_HERE, base::Bind(&RulesCacheDelegate::CheckIfReady, |
161 weak_ptr_factory_.GetWeakPtr())); | 162 weak_ptr_factory_.GetWeakPtr())); |
162 return; | 163 return; |
163 } | 164 } |
164 | 165 |
165 extensions::StateStore* store = ExtensionSystem::Get(profile_)->rules_store(); | 166 StateStore* store = ExtensionSystem::Get(profile_)->rules_store(); |
166 if (!store) | 167 if (!store) |
167 return; | 168 return; |
168 waiting_for_extensions_.insert(extension_id); | 169 waiting_for_extensions_.insert(extension_id); |
169 store->GetExtensionValue( | 170 store->GetExtensionValue( |
170 extension_id, | 171 extension_id, |
171 storage_key_, | 172 storage_key_, |
172 base::Bind(&RulesCacheDelegate::ReadFromStorageCallback, | 173 base::Bind(&RulesCacheDelegate::ReadFromStorageCallback, |
173 weak_ptr_factory_.GetWeakPtr(), | 174 weak_ptr_factory_.GetWeakPtr(), |
174 extension_id)); | 175 extension_id)); |
175 } | 176 } |
(...skipping 30 matching lines...) Expand all Loading... | |
206 | 207 |
207 // Safe default -- if we don't know that the rules are not stored, we force | 208 // Safe default -- if we don't know that the rules are not stored, we force |
208 // a read by returning true. | 209 // a read by returning true. |
209 return true; | 210 return true; |
210 } | 211 } |
211 | 212 |
212 void RulesCacheDelegate::SetDeclarativeRulesStored( | 213 void RulesCacheDelegate::SetDeclarativeRulesStored( |
213 const std::string& extension_id, | 214 const std::string& extension_id, |
214 bool rules_stored) { | 215 bool rules_stored) { |
215 CHECK(profile_); | 216 CHECK(profile_); |
216 ExtensionSystem& system = *ExtensionSystem::Get(profile_); | 217 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
Devlin
2014/05/22 22:09:12
Could you inline this?
DCHECK(ExtensionRegistry::G
limasdf
2014/05/23 15:19:41
Done.
| |
217 ExtensionService* extension_service = system.extension_service(); | 218 DCHECK( |
218 DCHECK(extension_service); | 219 registry->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING)); |
219 DCHECK(extension_service->GetInstalledExtension(extension_id)); | 220 |
220 ExtensionScopedPrefs* extension_prefs = ExtensionPrefs::Get(profile_); | 221 ExtensionScopedPrefs* extension_prefs = ExtensionPrefs::Get(profile_); |
221 extension_prefs->UpdateExtensionPref( | 222 extension_prefs->UpdateExtensionPref( |
222 extension_id, | 223 extension_id, |
223 rules_stored_key_, | 224 rules_stored_key_, |
224 new base::FundamentalValue(rules_stored)); | 225 new base::FundamentalValue(rules_stored)); |
225 } | 226 } |
226 | 227 |
227 } // namespace extensions | 228 } // namespace extensions |
OLD | NEW |