Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: chrome/browser/extensions/api/declarative/rules_registry_with_cache.cc

Issue 14851011: RulesRegistryWithCache::ProcessChangedRules speed-up (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing the uninitialised WeakPtrFactory Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/api/declarative/rules_registry_with_cache.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/declarative/rules_registry_with_cache.cc
diff --git a/chrome/browser/extensions/api/declarative/rules_registry_with_cache.cc b/chrome/browser/extensions/api/declarative/rules_registry_with_cache.cc
index 3a22d5c1d9be89b9a649fc8baea72096cd79361a..a03278098badcd1c57a70c8354fead6c172bcb97 100644
--- a/chrome/browser/extensions/api/declarative/rules_registry_with_cache.cc
+++ b/chrome/browser/extensions/api/declarative/rules_registry_with_cache.cc
@@ -42,6 +42,7 @@ std::vector<linked_ptr<extensions::RulesRegistry::Rule> > RulesFromValue(
if (!value || !value->GetAsList(&list))
return rules;
+ rules.reserve(list->GetSize());
for (size_t i = 0; i < list->GetSize(); ++i) {
const base::DictionaryValue* dict = NULL;
if (!list->GetDictionary(i, &dict))
@@ -78,7 +79,7 @@ RulesRegistryWithCache::RulesRegistryWithCache(
bool log_storage_init_delay,
scoped_ptr<RuleStorageOnUI>* ui_part)
: RulesRegistry(owner_thread, event_name),
- weak_ptr_factory_((profile) ? this : NULL),
+ weak_ptr_factory_(this),
storage_on_ui_((profile
? (new RuleStorageOnUI(profile,
GetDeclarativeRuleStorageKey(
@@ -88,7 +89,8 @@ RulesRegistryWithCache::RulesRegistryWithCache(
weak_ptr_factory_.GetWeakPtr(),
log_storage_init_delay))
->GetWeakPtr()
- : base::WeakPtr<RuleStorageOnUI>())) {
+ : base::WeakPtr<RuleStorageOnUI>())),
+ process_changed_rules_requested_(false) {
if (!profile) {
CHECK(!ui_part);
return;
@@ -126,7 +128,13 @@ std::string RulesRegistryWithCache::AddRules(
rules_[key] = *i;
}
- ProcessChangedRules(extension_id);
+ if (!process_changed_rules_requested_) {
+ process_changed_rules_requested_ = true;
+ ready_.Post(FROM_HERE,
+ base::Bind(&RulesRegistryWithCache::ProcessChangedRules,
+ weak_ptr_factory_.GetWeakPtr(),
+ extension_id));
+ }
return kSuccess;
}
@@ -147,7 +155,13 @@ std::string RulesRegistryWithCache::RemoveRules(
rules_.erase(lookup_key);
}
- ProcessChangedRules(extension_id);
+ if (!process_changed_rules_requested_) {
+ process_changed_rules_requested_ = true;
+ ready_.Post(FROM_HERE,
+ base::Bind(&RulesRegistryWithCache::ProcessChangedRules,
+ weak_ptr_factory_.GetWeakPtr(),
+ extension_id));
+ }
return kSuccess;
}
@@ -169,7 +183,13 @@ std::string RulesRegistryWithCache::RemoveAllRules(
rules_.erase(key);
}
- ProcessChangedRules(extension_id);
+ if (!process_changed_rules_requested_) {
+ process_changed_rules_requested_ = true;
+ ready_.Post(FROM_HERE,
+ base::Bind(&RulesRegistryWithCache::ProcessChangedRules,
+ weak_ptr_factory_.GetWeakPtr(),
+ extension_id));
+ }
return kSuccess;
}
@@ -237,6 +257,8 @@ void RulesRegistryWithCache::ProcessChangedRules(
const std::string& extension_id) {
DCHECK(content::BrowserThread::CurrentlyOn(owner_thread()));
+ process_changed_rules_requested_ = false;
+
std::vector<linked_ptr<RulesRegistry::Rule> > new_rules;
std::string error = GetAllRules(extension_id, &new_rules);
DCHECK_EQ(std::string(), error);
« no previous file with comments | « chrome/browser/extensions/api/declarative/rules_registry_with_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698