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

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

Issue 15911005: RulesRegistryWithCache::ProcessChangedRules postponed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Type description for ProcessChangedRulesState moved to the enum's def Created 7 years, 6 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 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[] =
« 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