| 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);
|
|
|