Chromium Code Reviews

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

Issue 5646003: Sanitize PrefStore interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix PrefService mock construction in PrefServiceTest to include command line store. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_util.h" 7 #include "base/string_util.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/extensions/extension_pref_store.h"
10 #include "chrome/browser/prefs/pref_notifier.h" 11 #include "chrome/browser/prefs/pref_notifier.h"
11 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/extensions/url_pattern.h" 13 #include "chrome/common/extensions/url_pattern.h"
13 #include "chrome/common/notification_service.h" 14 #include "chrome/common/notification_service.h"
14 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
15 16
16 using base::Time; 17 using base::Time;
17 18
18 namespace { 19 namespace {
19 20
(...skipping 113 matching lines...)
133 std::set<std::string>* result) { 134 std::set<std::string>* result) {
134 ExtensionExtent::PatternList patterns = host_extent.patterns(); 135 ExtensionExtent::PatternList patterns = host_extent.patterns();
135 ExtensionExtent::PatternList::const_iterator i; 136 ExtensionExtent::PatternList::const_iterator i;
136 137
137 for (i = patterns.begin(); i != patterns.end(); ++i) 138 for (i = patterns.begin(); i != patterns.end(); ++i)
138 result->insert(i->GetAsString()); 139 result->insert(i->GetAsString());
139 } 140 }
140 141
141 } // namespace 142 } // namespace
142 143
143 ExtensionPrefs::ExtensionPrefs(PrefService* prefs, const FilePath& root_dir) 144 ExtensionPrefs::ExtensionPrefs(PrefService* prefs,
145 const FilePath& root_dir,
146 ExtensionPrefStore* pref_store)
144 : prefs_(prefs), 147 : prefs_(prefs),
145 install_directory_(root_dir) { 148 install_directory_(root_dir),
149 pref_store_(pref_store) {
146 // TODO(asargent) - Remove this in a couple of months. (See comment above 150 // TODO(asargent) - Remove this in a couple of months. (See comment above
147 // CleanupBadExtensionKeys). 151 // CleanupBadExtensionKeys).
148 CleanupBadExtensionKeys(prefs_); 152 CleanupBadExtensionKeys(prefs_);
149 153
150 MakePathsRelative(); 154 MakePathsRelative();
151 155
152 InitPrefStore(); 156 InitPrefStore();
153 } 157 }
154 158
155 ExtensionPrefs::~ExtensionPrefs() {} 159 ExtensionPrefs::~ExtensionPrefs() {}
(...skipping 1027 matching lines...)
1183 1187
1184 // Collect the unique extension controlled preference keys of all extensions. 1188 // Collect the unique extension controlled preference keys of all extensions.
1185 PrefKeySet ext_controlled_prefs; 1189 PrefKeySet ext_controlled_prefs;
1186 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); 1190 for (ExtensionIdSet::iterator ext_id = extension_ids.begin();
1187 ext_id != extension_ids.end(); ++ext_id) { 1191 ext_id != extension_ids.end(); ++ext_id) {
1188 GetExtensionControlledPrefKeys(*ext_id, &ext_controlled_prefs); 1192 GetExtensionControlledPrefKeys(*ext_id, &ext_controlled_prefs);
1189 } 1193 }
1190 1194
1191 // Store winning preference for each extension controlled preference. 1195 // Store winning preference for each extension controlled preference.
1192 UpdatePrefStore(ext_controlled_prefs); 1196 UpdatePrefStore(ext_controlled_prefs);
1197 pref_store_->OnInitializationCompleted();
1193 } 1198 }
1194 1199
1195 const Value* ExtensionPrefs::GetWinningExtensionControlledPrefValue( 1200 const Value* ExtensionPrefs::GetWinningExtensionControlledPrefValue(
1196 const std::string& key) const { 1201 const std::string& key) const {
1197 Value *winner = NULL; 1202 Value *winner = NULL;
1198 base::Time winners_install_time = base::Time(); 1203 base::Time winners_install_time = base::Time();
1199 1204
1200 ExtensionIdSet extension_ids; 1205 ExtensionIdSet extension_ids;
1201 GetEnabledExtensions(&extension_ids); 1206 GetEnabledExtensions(&extension_ids);
1202 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); 1207 for (ExtensionIdSet::iterator ext_id = extension_ids.begin();
(...skipping 19 matching lines...)
1222 1227
1223 void ExtensionPrefs::UpdatePrefStore( 1228 void ExtensionPrefs::UpdatePrefStore(
1224 const ExtensionPrefs::PrefKeySet& pref_keys) { 1229 const ExtensionPrefs::PrefKeySet& pref_keys) {
1225 for (PrefKeySet::const_iterator i = pref_keys.begin(); 1230 for (PrefKeySet::const_iterator i = pref_keys.begin();
1226 i != pref_keys.end(); ++i) { 1231 i != pref_keys.end(); ++i) {
1227 UpdatePrefStore(*i); 1232 UpdatePrefStore(*i);
1228 } 1233 }
1229 } 1234 }
1230 1235
1231 void ExtensionPrefs::UpdatePrefStore(const std::string& pref_key) { 1236 void ExtensionPrefs::UpdatePrefStore(const std::string& pref_key) {
1232 PrefStore* extension_pref_store = 1237 if (pref_store_ == NULL)
1233 pref_service()->GetExtensionPrefStore(); 1238 return;
1234 if (extension_pref_store == NULL)
1235 return; // Profile is being shut down, Pref Service is already gone.
1236 const Value* winning_pref_value = 1239 const Value* winning_pref_value =
1237 GetWinningExtensionControlledPrefValue(pref_key); 1240 GetWinningExtensionControlledPrefValue(pref_key);
1238 Value* old_value = NULL;
1239 extension_pref_store->prefs()->Get(pref_key, &old_value);
1240 bool changed = !Value::Equals(winning_pref_value, old_value);
1241 1241
1242 if (winning_pref_value) { 1242 if (winning_pref_value)
1243 extension_pref_store->prefs()->Set(pref_key, 1243 pref_store_->SetExtensionPref(pref_key, winning_pref_value->DeepCopy());
1244 winning_pref_value->DeepCopy()); 1244 else
1245 } else { 1245 pref_store_->RemoveExtensionPref(pref_key);
1246 extension_pref_store->prefs()->Remove(pref_key, NULL);
1247 }
1248
1249 if (changed)
1250 pref_service()->pref_notifier()->OnPreferenceChanged(pref_key.c_str());
1251 } 1246 }
1252 1247
1253 void ExtensionPrefs::SetExtensionControlledPref(const std::string& extension_id, 1248 void ExtensionPrefs::SetExtensionControlledPref(const std::string& extension_id,
1254 const std::string& pref_key, 1249 const std::string& pref_key,
1255 Value* value) { 1250 Value* value) {
1256 scoped_ptr<Value> scoped_value(value); 1251 scoped_ptr<Value> scoped_value(value);
1257 DCHECK(pref_service()->FindPreference(pref_key.c_str())) 1252 DCHECK(pref_service()->FindPreference(pref_key.c_str()))
1258 << "Extension controlled preference key " << pref_key 1253 << "Extension controlled preference key " << pref_key
1259 << " not registered."; 1254 << " not registered.";
1260 DictionaryValue* extension_preferences = 1255 DictionaryValue* extension_preferences =
(...skipping 41 matching lines...)
1302 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { 1297 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) {
1303 prefs->RegisterDictionaryPref(kExtensionsPref); 1298 prefs->RegisterDictionaryPref(kExtensionsPref);
1304 prefs->RegisterListPref(kExtensionToolbar); 1299 prefs->RegisterListPref(kExtensionToolbar);
1305 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); 1300 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1);
1306 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); 1301 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate);
1307 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); 1302 prefs->RegisterListPref(prefs::kExtensionInstallAllowList);
1308 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); 1303 prefs->RegisterListPref(prefs::kExtensionInstallDenyList);
1309 prefs->RegisterListPref(prefs::kExtensionInstallForceList); 1304 prefs->RegisterListPref(prefs::kExtensionInstallForceList);
1310 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); 1305 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */);
1311 } 1306 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extensions_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine