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 6d0c73565acdf9cf0a4e9ddcb206d16bd4ad036d..716a703e777b387835a406fcd8938d8153263dee 100644 |
--- a/chrome/browser/extensions/api/declarative/rules_registry_with_cache.cc |
+++ b/chrome/browser/extensions/api/declarative/rules_registry_with_cache.cc |
@@ -44,6 +44,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)) |
@@ -80,7 +81,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_(profile ? this : NULL), |
storage_on_ui_((profile |
? (new RuleStorageOnUI(profile, |
GetDeclarativeRuleStorageKey( |
@@ -90,7 +91,9 @@ RulesRegistryWithCache::RulesRegistryWithCache( |
weak_ptr_factory_.GetWeakPtr(), |
log_storage_init_delay)) |
->GetWeakPtr() |
- : base::WeakPtr<RuleStorageOnUI>())) { |
+ : base::WeakPtr<RuleStorageOnUI>())), |
+ process_changed_rules_requested_(profile ? NOT_SCHEDULED_FOR_PROCESSING |
+ : NEVER_PROCESS) { |
if (!profile) { |
CHECK(!ui_part); |
return; |
@@ -128,7 +131,7 @@ std::string RulesRegistryWithCache::AddRules( |
rules_[key] = *i; |
} |
- ProcessChangedRules(extension_id); |
+ MaybeProcessChangedRules(extension_id); |
return kSuccess; |
} |
@@ -149,7 +152,7 @@ std::string RulesRegistryWithCache::RemoveRules( |
rules_.erase(lookup_key); |
} |
- ProcessChangedRules(extension_id); |
+ MaybeProcessChangedRules(extension_id); |
return kSuccess; |
} |
@@ -171,7 +174,7 @@ std::string RulesRegistryWithCache::RemoveAllRules( |
rules_.erase(key); |
} |
- ProcessChangedRules(extension_id); |
+ MaybeProcessChangedRules(extension_id); |
return kSuccess; |
} |
@@ -239,6 +242,8 @@ void RulesRegistryWithCache::ProcessChangedRules( |
const std::string& extension_id) { |
DCHECK(content::BrowserThread::CurrentlyOn(owner_thread())); |
+ process_changed_rules_requested_ = NOT_SCHEDULED_FOR_PROCESSING; |
+ |
std::vector<linked_ptr<RulesRegistry::Rule> > new_rules; |
std::string error = GetAllRules(extension_id, &new_rules); |
DCHECK_EQ(std::string(), error); |
@@ -251,6 +256,18 @@ void RulesRegistryWithCache::ProcessChangedRules( |
base::Passed(RulesToValue(new_rules)))); |
} |
+void RulesRegistryWithCache::MaybeProcessChangedRules( |
+ const std::string& extension_id) { |
+ if (process_changed_rules_requested_ != NOT_SCHEDULED_FOR_PROCESSING) |
+ return; |
+ |
+ process_changed_rules_requested_ = SCHEDULED_FOR_PROCESSING; |
+ ready_.Post(FROM_HERE, |
+ base::Bind(&RulesRegistryWithCache::ProcessChangedRules, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ extension_id)); |
+} |
+ |
// RulesRegistryWithCache::RuleStorageOnUI |
const char RulesRegistryWithCache::RuleStorageOnUI::kRulesStoredKey[] = |