Chromium Code Reviews| 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_with_cache.h" | 5 #include "chrome/browser/extensions/api/declarative/rules_registry_with_cache.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 | 73 |
| 74 // RulesRegistryWithCache | 74 // RulesRegistryWithCache |
| 75 | 75 |
| 76 RulesRegistryWithCache::RulesRegistryWithCache( | 76 RulesRegistryWithCache::RulesRegistryWithCache( |
| 77 Profile* profile, | 77 Profile* profile, |
| 78 const char* event_name, | 78 const char* event_name, |
| 79 content::BrowserThread::ID owner_thread, | 79 content::BrowserThread::ID owner_thread, |
| 80 bool log_storage_init_delay, | 80 bool log_storage_init_delay, |
| 81 scoped_ptr<RuleStorageOnUI>* ui_part) | 81 scoped_ptr<RuleStorageOnUI>* ui_part) |
| 82 : RulesRegistry(owner_thread, event_name), | 82 : RulesRegistry(owner_thread, event_name), |
| 83 weak_ptr_factory_((profile) ? this : NULL), | 83 weak_ptr_factory_(this), |
| 84 storage_on_ui_((profile | 84 storage_on_ui_((profile |
| 85 ? (new RuleStorageOnUI(profile, | 85 ? (new RuleStorageOnUI(profile, |
| 86 GetDeclarativeRuleStorageKey( | 86 GetDeclarativeRuleStorageKey( |
| 87 event_name, | 87 event_name, |
| 88 profile->IsOffTheRecord()), | 88 profile->IsOffTheRecord()), |
| 89 owner_thread, | 89 owner_thread, |
| 90 weak_ptr_factory_.GetWeakPtr(), | 90 weak_ptr_factory_.GetWeakPtr(), |
| 91 log_storage_init_delay)) | 91 log_storage_init_delay)) |
| 92 ->GetWeakPtr() | 92 ->GetWeakPtr() |
| 93 : base::WeakPtr<RuleStorageOnUI>())) { | 93 : base::WeakPtr<RuleStorageOnUI>())) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 | 210 |
| 211 void RulesRegistryWithCache::OnExtensionUnloaded( | 211 void RulesRegistryWithCache::OnExtensionUnloaded( |
| 212 const std::string& extension_id) { | 212 const std::string& extension_id) { |
| 213 DCHECK(content::BrowserThread::CurrentlyOn(owner_thread())); | 213 DCHECK(content::BrowserThread::CurrentlyOn(owner_thread())); |
| 214 std::string error = RemoveAllRules(extension_id); | 214 std::string error = RemoveAllRules(extension_id); |
| 215 if (!error.empty()) | 215 if (!error.empty()) |
| 216 LOG(ERROR) << error; | 216 LOG(ERROR) << error; |
| 217 } | 217 } |
| 218 | 218 |
| 219 RulesRegistryWithCache::~RulesRegistryWithCache() { | 219 RulesRegistryWithCache::~RulesRegistryWithCache() { |
| 220 weak_ptr_factory_.DetachFromThread(); | |
|
Jeffrey Yasskin
2013/05/28 22:37:10
This isn't safe, according to the thread-safety ru
Jeffrey Yasskin
2013/05/28 22:48:49
One way to work around this would be to add a meth
| |
| 220 } | 221 } |
| 221 | 222 |
| 222 void RulesRegistryWithCache::MarkReady(base::Time storage_init_time) { | 223 void RulesRegistryWithCache::MarkReady(base::Time storage_init_time) { |
| 223 DCHECK(content::BrowserThread::CurrentlyOn(owner_thread())); | 224 DCHECK(content::BrowserThread::CurrentlyOn(owner_thread())); |
| 224 | 225 |
| 225 if (!storage_init_time.is_null()) { | 226 if (!storage_init_time.is_null()) { |
| 226 UMA_HISTOGRAM_TIMES("Extensions.DeclarativeRulesStorageInitialization", | 227 UMA_HISTOGRAM_TIMES("Extensions.DeclarativeRulesStorageInitialization", |
| 227 base::Time::Now() - storage_init_time); | 228 base::Time::Now() - storage_init_time); |
| 228 } | 229 } |
| 229 | 230 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 void RulesRegistryWithCache::RuleStorageOnUI::SetDeclarativeRulesStored( | 432 void RulesRegistryWithCache::RuleStorageOnUI::SetDeclarativeRulesStored( |
| 432 const std::string& extension_id, | 433 const std::string& extension_id, |
| 433 bool rules_stored) { | 434 bool rules_stored) { |
| 434 CHECK(profile_); | 435 CHECK(profile_); |
| 435 ExtensionScopedPrefs* extension_prefs = ExtensionPrefs::Get(profile_); | 436 ExtensionScopedPrefs* extension_prefs = ExtensionPrefs::Get(profile_); |
| 436 extension_prefs->UpdateExtensionPref( | 437 extension_prefs->UpdateExtensionPref( |
| 437 extension_id, kRulesStoredKey, new base::FundamentalValue(rules_stored)); | 438 extension_id, kRulesStoredKey, new base::FundamentalValue(rules_stored)); |
| 438 } | 439 } |
| 439 | 440 |
| 440 } // namespace extensions | 441 } // namespace extensions |
| OLD | NEW |