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

Side by Side Diff: chrome/browser/extensions/extension_prefs.cc

Issue 10514013: Filtered events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, fix cross_incognito_args bug 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_prefs.h" 5 #include "chrome/browser/extensions/extension_prefs.h"
6 6
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/extensions/admin_policy.h" 10 #include "chrome/browser/extensions/admin_policy.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // A preference that contains extension-set content settings. 166 // A preference that contains extension-set content settings.
167 const char kPrefContentSettings[] = "content_settings"; 167 const char kPrefContentSettings[] = "content_settings";
168 168
169 // A preference that contains extension-set content settings. 169 // A preference that contains extension-set content settings.
170 const char kPrefIncognitoContentSettings[] = "incognito_content_settings"; 170 const char kPrefIncognitoContentSettings[] = "incognito_content_settings";
171 171
172 // A list of event names that this extension has registered from its lazy 172 // A list of event names that this extension has registered from its lazy
173 // background page. 173 // background page.
174 const char kRegisteredEvents[] = "events"; 174 const char kRegisteredEvents[] = "events";
175 175
176 // A dictionary of event names to lists of filters that this extension has
177 // registered from its lazy background page.
178 const char kFilteredEvents[] = "filtered_events";
179
176 // Persisted value for omnibox.setDefaultSuggestion. 180 // Persisted value for omnibox.setDefaultSuggestion.
177 const char kOmniboxDefaultSuggestion[] = "omnibox_default_suggestion"; 181 const char kOmniboxDefaultSuggestion[] = "omnibox_default_suggestion";
178 182
179 // Provider of write access to a dictionary storing extension prefs. 183 // Provider of write access to a dictionary storing extension prefs.
180 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { 184 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate {
181 public: 185 public:
182 ScopedExtensionPrefUpdate(PrefService* service, 186 ScopedExtensionPrefUpdate(PrefService* service,
183 const std::string& extension_id) : 187 const std::string& extension_id) :
184 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), 188 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref),
185 extension_id_(extension_id) {} 189 extension_id_(extension_id) {}
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 return events; 954 return events;
951 955
952 for (size_t i = 0; i < value->GetSize(); ++i) { 956 for (size_t i = 0; i < value->GetSize(); ++i) {
953 std::string event; 957 std::string event;
954 if (value->GetString(i, &event)) 958 if (value->GetString(i, &event))
955 events.insert(event); 959 events.insert(event);
956 } 960 }
957 return events; 961 return events;
958 } 962 }
959 963
964 void ExtensionPrefs::AddFilterToEvent(const std::string& event_name,
965 const std::string& extension_id,
966 const DictionaryValue* filter) {
967 const DictionaryValue* filtered_events = GetFilteredEvents(extension_id);
968 scoped_ptr<DictionaryValue> new_filtered_events;
969 if (!filtered_events)
970 new_filtered_events.reset(new DictionaryValue);
971 else
972 new_filtered_events.reset(filtered_events->DeepCopy());
973
974 ListValue* filter_list = NULL;
975 if (!new_filtered_events->GetList(event_name, &filter_list)) {
976 filter_list = new ListValue();
977 new_filtered_events->Set(event_name, filter_list);
978 }
979 filter_list->Append(filter->DeepCopy());
980
981 UpdateExtensionPref(extension_id, kFilteredEvents,
982 new_filtered_events.release());
battre 2012/06/19 14:26:23 What do you think of modifying the list instead of
koz (OOO until 15th September) 2012/06/20 08:05:56 Sounds good! Done.
983 }
984
985 void ExtensionPrefs::RemoveFilterFromEvent(const std::string& event_name,
986 const std::string& extension_id,
987 const DictionaryValue* filter) {
988 const DictionaryValue* filtered_events = GetFilteredEvents(extension_id);
989 if (!filtered_events)
990 return;
991
992 scoped_ptr<DictionaryValue> new_filtered_events(filtered_events->DeepCopy());
993 ListValue* filter_list;
994 if (!new_filtered_events->GetList(event_name, &filter_list))
995 return;
996
997 bool removed = false;
998 for (size_t i = 0; i < filter_list->GetSize(); i++) {
999 DictionaryValue* filter;
1000 CHECK(filter_list->GetDictionary(i, &filter));
1001 if (filter->Equals(filter)) {
1002 filter_list->Remove(i, NULL);
1003 removed = true;
1004 break;
1005 }
1006 }
1007
1008 if (removed)
1009 UpdateExtensionPref(extension_id, kFilteredEvents,
1010 new_filtered_events.release());
1011 }
1012
1013 const DictionaryValue* ExtensionPrefs::GetFilteredEvents(
1014 const std::string& extension_id) {
1015 const DictionaryValue* extension = GetExtensionPref(extension_id);
1016 if (!extension)
1017 return NULL;
1018 DictionaryValue* result = NULL;
1019 if (!extension->GetDictionary(kFilteredEvents, &result))
1020 return NULL;
1021 return result;
1022 }
1023
960 void ExtensionPrefs::SetRegisteredEvents( 1024 void ExtensionPrefs::SetRegisteredEvents(
961 const std::string& extension_id, const std::set<std::string>& events) { 1025 const std::string& extension_id, const std::set<std::string>& events) {
962 ListValue* value = new ListValue(); 1026 ListValue* value = new ListValue();
963 for (std::set<std::string>::const_iterator it = events.begin(); 1027 for (std::set<std::string>::const_iterator it = events.begin();
964 it != events.end(); ++it) { 1028 it != events.end(); ++it) {
965 value->Append(new StringValue(*it)); 1029 value->Append(new StringValue(*it));
966 } 1030 }
967 UpdateExtensionPref(extension_id, kRegisteredEvents, value); 1031 UpdateExtensionPref(extension_id, kRegisteredEvents, value);
968 } 1032 }
969 1033
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 PrefService::UNSYNCABLE_PREF); 1943 PrefService::UNSYNCABLE_PREF);
1880 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, 1944 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck,
1881 0, // default value 1945 0, // default value
1882 PrefService::UNSYNCABLE_PREF); 1946 PrefService::UNSYNCABLE_PREF);
1883 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, 1947 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck,
1884 0, // default value 1948 0, // default value
1885 PrefService::UNSYNCABLE_PREF); 1949 PrefService::UNSYNCABLE_PREF);
1886 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, 1950 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites,
1887 PrefService::UNSYNCABLE_PREF); 1951 PrefService::UNSYNCABLE_PREF);
1888 } 1952 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698