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

Unified Diff: chrome/browser/extensions/extension_prefs.cc

Issue 10514013: Filtered events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, reland Created 8 years, 5 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/extension_prefs.h ('k') | chrome/browser/extensions/extension_processes_api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_prefs.cc
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc
index 19e01dba7b8b63d237b2fd84d81476afcc6ccb58..7d210b9d95cb782c8b5afb9da76604fa87464c7c 100644
--- a/chrome/browser/extensions/extension_prefs.cc
+++ b/chrome/browser/extensions/extension_prefs.cc
@@ -179,6 +179,10 @@ const char kPrefIncognitoContentSettings[] = "incognito_content_settings";
// background page.
const char kRegisteredEvents[] = "events";
+// A dictionary of event names to lists of filters that this extension has
+// registered from its lazy background page.
+const char kFilteredEvents[] = "filtered_events";
+
// Persisted value for omnibox.setDefaultSuggestion.
const char kOmniboxDefaultSuggestion[] = "omnibox_default_suggestion";
@@ -986,6 +990,59 @@ std::set<std::string> ExtensionPrefs::GetRegisteredEvents(
return events;
}
+void ExtensionPrefs::AddFilterToEvent(const std::string& event_name,
+ const std::string& extension_id,
+ const DictionaryValue* filter) {
+ ScopedExtensionPrefUpdate update(prefs_, extension_id);
+ DictionaryValue* extension_dict = update.Get();
+ DictionaryValue* filtered_events = NULL;
+ if (!extension_dict->GetDictionary(kFilteredEvents, &filtered_events)) {
+ filtered_events = new DictionaryValue;
+ extension_dict->Set(kFilteredEvents, filtered_events);
+ }
+ ListValue* filter_list = NULL;
+ if (!filtered_events->GetList(event_name, &filter_list)) {
+ filter_list = new ListValue;
+ filtered_events->Set(event_name, filter_list);
+ }
+
+ filter_list->Append(filter->DeepCopy());
+}
+
+void ExtensionPrefs::RemoveFilterFromEvent(const std::string& event_name,
+ const std::string& extension_id,
+ const DictionaryValue* filter) {
+ ScopedExtensionPrefUpdate update(prefs_, extension_id);
+ DictionaryValue* extension_dict = update.Get();
+ DictionaryValue* filtered_events = NULL;
+
+ if (!extension_dict->GetDictionary(kFilteredEvents, &filtered_events))
+ return;
+ ListValue* filter_list = NULL;
+ if (!filtered_events->GetList(event_name, &filter_list))
+ return;
+
+ for (size_t i = 0; i < filter_list->GetSize(); i++) {
+ DictionaryValue* filter;
+ CHECK(filter_list->GetDictionary(i, &filter));
+ if (filter->Equals(filter)) {
+ filter_list->Remove(i, NULL);
+ break;
+ }
+ }
+}
+
+const DictionaryValue* ExtensionPrefs::GetFilteredEvents(
+ const std::string& extension_id) const {
+ const DictionaryValue* extension = GetExtensionPref(extension_id);
+ if (!extension)
+ return NULL;
+ DictionaryValue* result = NULL;
+ if (!extension->GetDictionary(kFilteredEvents, &result))
+ return NULL;
+ return result;
+}
+
void ExtensionPrefs::SetRegisteredEvents(
const std::string& extension_id, const std::set<std::string>& events) {
ListValue* value = new ListValue();
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_processes_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698