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

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

Issue 10560013: Persist declarative rules to the extension state store. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 8 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
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 49bb9ea5952e1d2fe6f1cc5053bd5254400e8573..e3c0fd08729acac4229057a5c31eb893a76e26f2 100644
--- a/chrome/browser/extensions/api/declarative/rules_registry_with_cache.cc
+++ b/chrome/browser/extensions/api/declarative/rules_registry_with_cache.cc
@@ -16,7 +16,19 @@ const char kDuplicateRuleId[] = "Duplicate rule ID: %s";
namespace extensions {
-RulesRegistryWithCache::RulesRegistryWithCache() {}
+RulesRegistryWithCache::RulesRegistryWithCache(Delegate* delegate)
+ : delegate_(delegate) {
+}
+
+void RulesRegistryWithCache::AddReadyCallback(const base::Closure& callback) {
+ ready_callbacks_.push_back(callback);
+}
+
+void RulesRegistryWithCache::OnReady() {
+ for (size_t i = 0; i < ready_callbacks_.size(); ++i)
+ ready_callbacks_[i].Run();
+ ready_callbacks_.clear();
+}
std::string RulesRegistryWithCache::AddRules(
const std::string& extension_id,
@@ -44,6 +56,8 @@ std::string RulesRegistryWithCache::AddRules(
RulesDictionaryKey key(extension_id, rule_id);
rules_[key] = *i;
}
+
+ NotifyRulesChanged(extension_id);
return kSuccess;
}
@@ -63,6 +77,8 @@ std::string RulesRegistryWithCache::RemoveRules(
RulesDictionaryKey lookup_key(extension_id, *i);
rules_.erase(lookup_key);
}
+
+ NotifyRulesChanged(extension_id);
return kSuccess;
}
@@ -83,6 +99,8 @@ std::string RulesRegistryWithCache::RemoveAllRules(
if (key.first == extension_id)
rules_.erase(key);
}
+
+ NotifyRulesChanged(extension_id);
return kSuccess;
}
@@ -124,6 +142,20 @@ void RulesRegistryWithCache::OnExtensionUnloaded(
LOG(ERROR) << error;
}
+void RulesRegistryWithCache::NotifyRulesChanged(
+ const std::string& extension_id) {
+ DCHECK(content::BrowserThread::CurrentlyOn(GetOwnerThread()));
+
+ if (!delegate_.get())
+ return;
+
+ std::vector<linked_ptr<RulesRegistry::Rule> > rules;
+ std::string error = GetAllRules(extension_id, &rules);
+ DCHECK_EQ(kSuccess, error);
battre 2012/06/15 22:56:49 should we pass |rules| to OnRulesChanged()? OnRule
Matt Perry 2012/06/18 21:01:01 Oops. I originally did do that, but decided it wou
+
+ delegate_->OnRulesChanged(this, extension_id);
+}
+
RulesRegistryWithCache::~RulesRegistryWithCache() {}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698