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 #include "chrome/browser/extensions/api/declarative/rules_registry_storage_deleg
ate.h" | 5 #include "chrome/browser/extensions/api/declarative/rules_registry_storage_deleg
ate.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/extensions/extension_info_map.h" | 8 #include "chrome/browser/extensions/extension_info_map.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/extension_system.h" | 10 #include "chrome/browser/extensions/extension_system.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 134 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
135 extensions::StateStore* store = ExtensionSystem::Get(profile)->state_store(); | 135 extensions::StateStore* store = ExtensionSystem::Get(profile)->state_store(); |
136 if (store) | 136 if (store) |
137 store->RegisterKey(storage_key); | 137 store->RegisterKey(storage_key); |
138 inner_ = new Inner(profile, rules_registry, storage_key); | 138 inner_ = new Inner(profile, rules_registry, storage_key); |
139 } | 139 } |
140 | 140 |
141 void RulesRegistryStorageDelegate::CleanupOnUIThread() { | 141 void RulesRegistryStorageDelegate::CleanupOnUIThread() { |
142 // The registrar must be deleted on the UI thread. | 142 // The registrar must be deleted on the UI thread. |
143 inner_->registrar_.reset(); | 143 inner_->registrar_.reset(); |
| 144 inner_->profile_ = NULL; // no longer safe to use. |
144 } | 145 } |
145 | 146 |
146 bool RulesRegistryStorageDelegate::IsReady() { | 147 bool RulesRegistryStorageDelegate::IsReady() { |
147 DCHECK(content::BrowserThread::CurrentlyOn(inner_->rules_registry_thread_)); | 148 DCHECK(content::BrowserThread::CurrentlyOn(inner_->rules_registry_thread_)); |
148 return inner_->ready_; | 149 return inner_->ready_; |
149 } | 150 } |
150 | 151 |
151 void RulesRegistryStorageDelegate::OnRulesChanged( | 152 void RulesRegistryStorageDelegate::OnRulesChanged( |
152 RulesRegistryWithCache* rules_registry, | 153 RulesRegistryWithCache* rules_registry, |
153 const std::string& extension_id) { | 154 const std::string& extension_id) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 223 } |
223 } | 224 } |
224 } else if (type == chrome::NOTIFICATION_EXTENSIONS_READY) { | 225 } else if (type == chrome::NOTIFICATION_EXTENSIONS_READY) { |
225 CheckIfReady(); | 226 CheckIfReady(); |
226 } | 227 } |
227 } | 228 } |
228 | 229 |
229 void RulesRegistryStorageDelegate::Inner::ReadFromStorage( | 230 void RulesRegistryStorageDelegate::Inner::ReadFromStorage( |
230 const std::string& extension_id) { | 231 const std::string& extension_id) { |
231 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 232 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 233 if (!profile_) |
| 234 return; |
| 235 |
232 extensions::StateStore* store = ExtensionSystem::Get(profile_)->state_store(); | 236 extensions::StateStore* store = ExtensionSystem::Get(profile_)->state_store(); |
233 if (store) { | 237 if (store) { |
234 waiting_for_extensions_.insert(extension_id); | 238 waiting_for_extensions_.insert(extension_id); |
235 store->GetExtensionValue(extension_id, storage_key_, | 239 store->GetExtensionValue(extension_id, storage_key_, |
236 base::Bind(&Inner::ReadFromStorageCallback, this, extension_id)); | 240 base::Bind(&Inner::ReadFromStorageCallback, this, extension_id)); |
237 } | 241 } |
238 } | 242 } |
239 | 243 |
240 void RulesRegistryStorageDelegate::Inner::ReadFromStorageCallback( | 244 void RulesRegistryStorageDelegate::Inner::ReadFromStorageCallback( |
241 const std::string& extension_id, scoped_ptr<base::Value> value) { | 245 const std::string& extension_id, scoped_ptr<base::Value> value) { |
242 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 246 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
243 content::BrowserThread::PostTask( | 247 content::BrowserThread::PostTask( |
244 rules_registry_thread_, FROM_HERE, | 248 rules_registry_thread_, FROM_HERE, |
245 base::Bind(&Inner::ReadFromStorageOnRegistryThread, this, | 249 base::Bind(&Inner::ReadFromStorageOnRegistryThread, this, |
246 extension_id, base::Passed(value.Pass()))); | 250 extension_id, base::Passed(value.Pass()))); |
247 | 251 |
248 waiting_for_extensions_.erase(extension_id); | 252 waiting_for_extensions_.erase(extension_id); |
249 CheckIfReady(); | 253 CheckIfReady(); |
250 } | 254 } |
251 | 255 |
252 void RulesRegistryStorageDelegate::Inner::WriteToStorage( | 256 void RulesRegistryStorageDelegate::Inner::WriteToStorage( |
253 const std::string& extension_id, scoped_ptr<base::Value> value) { | 257 const std::string& extension_id, scoped_ptr<base::Value> value) { |
254 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 258 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 259 if (!profile_) |
| 260 return; |
| 261 |
255 StateStore* store = ExtensionSystem::Get(profile_)->state_store(); | 262 StateStore* store = ExtensionSystem::Get(profile_)->state_store(); |
256 if (store) | 263 if (store) |
257 store->SetExtensionValue(extension_id, storage_key_, value.Pass()); | 264 store->SetExtensionValue(extension_id, storage_key_, value.Pass()); |
258 } | 265 } |
259 | 266 |
260 void RulesRegistryStorageDelegate::Inner::CheckIfReady() { | 267 void RulesRegistryStorageDelegate::Inner::CheckIfReady() { |
261 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 268 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
262 if (!waiting_for_extensions_.empty()) | 269 if (!waiting_for_extensions_.empty()) |
263 return; | 270 return; |
264 | 271 |
(...skipping 14 matching lines...) Expand all Loading... |
279 void RulesRegistryStorageDelegate::Inner::NotifyReadyOnRegistryThread() { | 286 void RulesRegistryStorageDelegate::Inner::NotifyReadyOnRegistryThread() { |
280 DCHECK(content::BrowserThread::CurrentlyOn(rules_registry_thread_)); | 287 DCHECK(content::BrowserThread::CurrentlyOn(rules_registry_thread_)); |
281 if (ready_) | 288 if (ready_) |
282 return; // we've already notified our readiness | 289 return; // we've already notified our readiness |
283 | 290 |
284 ready_ = true; | 291 ready_ = true; |
285 rules_registry_->OnReady(); | 292 rules_registry_->OnReady(); |
286 } | 293 } |
287 | 294 |
288 } // namespace extensions | 295 } // namespace extensions |
OLD | NEW |