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

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

Issue 10661038: Revert 143896 - Filtered events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
Property Changes:
Added: svn:mergeinfo
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
180 // Persisted value for omnibox.setDefaultSuggestion. 176 // Persisted value for omnibox.setDefaultSuggestion.
181 const char kOmniboxDefaultSuggestion[] = "omnibox_default_suggestion"; 177 const char kOmniboxDefaultSuggestion[] = "omnibox_default_suggestion";
182 178
183 // Provider of write access to a dictionary storing extension prefs. 179 // Provider of write access to a dictionary storing extension prefs.
184 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { 180 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate {
185 public: 181 public:
186 ScopedExtensionPrefUpdate(PrefService* service, 182 ScopedExtensionPrefUpdate(PrefService* service,
187 const std::string& extension_id) : 183 const std::string& extension_id) :
188 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), 184 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref),
189 extension_id_(extension_id) {} 185 extension_id_(extension_id) {}
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 return events; 955 return events;
960 956
961 for (size_t i = 0; i < value->GetSize(); ++i) { 957 for (size_t i = 0; i < value->GetSize(); ++i) {
962 std::string event; 958 std::string event;
963 if (value->GetString(i, &event)) 959 if (value->GetString(i, &event))
964 events.insert(event); 960 events.insert(event);
965 } 961 }
966 return events; 962 return events;
967 } 963 }
968 964
969 void ExtensionPrefs::AddFilterToEvent(const std::string& event_name,
970 const std::string& extension_id,
971 const DictionaryValue* filter) {
972 ScopedExtensionPrefUpdate update(prefs_, extension_id);
973 DictionaryValue* extension_dict = update.Get();
974 DictionaryValue* filtered_events = NULL;
975 if (!extension_dict->GetDictionary(kFilteredEvents, &filtered_events)) {
976 filtered_events = new DictionaryValue;
977 extension_dict->Set(kFilteredEvents, filtered_events);
978 }
979 ListValue* filter_list = NULL;
980 if (!filtered_events->GetList(event_name, &filter_list)) {
981 filter_list = new ListValue;
982 filtered_events->Set(event_name, filter_list);
983 }
984
985 filter_list->Append(filter->DeepCopy());
986 }
987
988 void ExtensionPrefs::RemoveFilterFromEvent(const std::string& event_name,
989 const std::string& extension_id,
990 const DictionaryValue* filter) {
991 ScopedExtensionPrefUpdate update(prefs_, extension_id);
992 DictionaryValue* extension_dict = update.Get();
993 DictionaryValue* filtered_events = NULL;
994
995 if (!extension_dict->GetDictionary(kFilteredEvents, &filtered_events))
996 return;
997 ListValue* filter_list = NULL;
998 if (!filtered_events->GetList(event_name, &filter_list))
999 return;
1000
1001 for (size_t i = 0; i < filter_list->GetSize(); i++) {
1002 DictionaryValue* filter;
1003 CHECK(filter_list->GetDictionary(i, &filter));
1004 if (filter->Equals(filter)) {
1005 filter_list->Remove(i, NULL);
1006 break;
1007 }
1008 }
1009 }
1010
1011 const DictionaryValue* ExtensionPrefs::GetFilteredEvents(
1012 const std::string& extension_id) const {
1013 const DictionaryValue* extension = GetExtensionPref(extension_id);
1014 if (!extension)
1015 return NULL;
1016 DictionaryValue* result = NULL;
1017 if (!extension->GetDictionary(kFilteredEvents, &result))
1018 return NULL;
1019 return result;
1020 }
1021
1022 void ExtensionPrefs::SetRegisteredEvents( 965 void ExtensionPrefs::SetRegisteredEvents(
1023 const std::string& extension_id, const std::set<std::string>& events) { 966 const std::string& extension_id, const std::set<std::string>& events) {
1024 ListValue* value = new ListValue(); 967 ListValue* value = new ListValue();
1025 for (std::set<std::string>::const_iterator it = events.begin(); 968 for (std::set<std::string>::const_iterator it = events.begin();
1026 it != events.end(); ++it) { 969 it != events.end(); ++it) {
1027 value->Append(new StringValue(*it)); 970 value->Append(new StringValue(*it));
1028 } 971 }
1029 UpdateExtensionPref(extension_id, kRegisteredEvents, value); 972 UpdateExtensionPref(extension_id, kRegisteredEvents, value);
1030 } 973 }
1031 974
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 PrefService::UNSYNCABLE_PREF); 1884 PrefService::UNSYNCABLE_PREF);
1942 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, 1885 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck,
1943 0, // default value 1886 0, // default value
1944 PrefService::UNSYNCABLE_PREF); 1887 PrefService::UNSYNCABLE_PREF);
1945 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, 1888 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck,
1946 0, // default value 1889 0, // default value
1947 PrefService::UNSYNCABLE_PREF); 1890 PrefService::UNSYNCABLE_PREF);
1948 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, 1891 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites,
1949 PrefService::UNSYNCABLE_PREF); 1892 PrefService::UNSYNCABLE_PREF);
1950 } 1893 }
OLDNEW
« 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