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

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

Issue 4438001: First part to fix Bug 50726 "Save extension list and "winning" prefs from extensions" (Closed) Base URL: http://git.chromium.org/git/chromium.git/@trunk
Patch Set: whitespaces Created 10 years, 1 month 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
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/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
(...skipping 23 matching lines...) Expand all
34 // Indicates if an extension is blacklisted: 34 // Indicates if an extension is blacklisted:
35 const char kPrefBlacklist[] = "blacklist"; 35 const char kPrefBlacklist[] = "blacklist";
36 36
37 // Indicates whether to show an install warning when the user enables. 37 // Indicates whether to show an install warning when the user enables.
38 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable"; 38 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable";
39 39
40 // A preference that tracks browser action toolbar configuration. This is a list 40 // A preference that tracks browser action toolbar configuration. This is a list
41 // object stored in the Preferences file. The extensions are stored by ID. 41 // object stored in the Preferences file. The extensions are stored by ID.
42 const char kExtensionToolbar[] = "extensions.toolbar"; 42 const char kExtensionToolbar[] = "extensions.toolbar";
43 43
44 // An ordered list of extension IDs that determines which extension overwrites
45 // the values of other extensions. The last extension wins.
46 // The ExtensionPrefStore reads and writes this list to respect the precedences.
47 const char kExtensionsPrecedence[] = "extensions.precedence";
48
44 // The key for a serialized Time value indicating the start of the day (from the 49 // The key for a serialized Time value indicating the start of the day (from the
45 // server's perspective) an extension last included a "ping" parameter during 50 // server's perspective) an extension last included a "ping" parameter during
46 // its update check. 51 // its update check.
47 const char kLastPingDay[] = "lastpingday"; 52 const char kLastPingDay[] = "lastpingday";
48 53
49 // Path for settings specific to blacklist update. 54 // Path for settings specific to blacklist update.
50 const char kExtensionsBlacklistUpdate[] = "extensions.blacklistupdate"; 55 const char kExtensionsBlacklistUpdate[] = "extensions.blacklistupdate";
51 56
52 // Path and sub-keys for the idle install info dictionary preference. 57 // Path and sub-keys for the idle install info dictionary preference.
53 const char kIdleInstallInfo[] = "idle_install_info"; 58 const char kIdleInstallInfo[] = "idle_install_info";
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); 207 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
203 if (extensions) { 208 if (extensions) {
204 DictionaryValue* copy = 209 DictionaryValue* copy =
205 static_cast<DictionaryValue*>(extensions->DeepCopy()); 210 static_cast<DictionaryValue*>(extensions->DeepCopy());
206 MakePathsAbsolute(copy); 211 MakePathsAbsolute(copy);
207 return copy; 212 return copy;
208 } 213 }
209 return new DictionaryValue; 214 return new DictionaryValue;
210 } 215 }
211 216
217 void ExtensionPrefs::PersistExtensionPrecedences(
218 const std::vector<std::string>& precedence) {
219 ListValue* stored_precedence =
220 pref_service()->GetMutableList(kExtensionsPrecedence);
221
222 stored_precedence->Clear();
223
224 std::vector<std::string>::const_iterator i;
225 for (i = precedence.begin(); i != precedence.end(); ++i)
226 stored_precedence->Append(Value::CreateStringValue(*i));
227 pref_service()->ScheduleSavePersistentPrefs();
228 }
229
230 void ExtensionPrefs::GetExtensionPrecedences(
231 std::vector<std::string>* precedence) const {
232 precedence->clear();
233
234 const ListValue* stored_precedence =
235 pref_service()->GetList(kExtensionsPrecedence);
236 if (stored_precedence) {
237 precedence->reserve(stored_precedence->GetSize());
238 for (ListValue::const_iterator i = stored_precedence->begin();
239 i != stored_precedence->end(); ++i) {
240 std::string ext_id;
241 if (!(*i)->GetAsString(&ext_id)) {
242 LOG(WARNING) << "Invalid entry in " << kExtensionsPrecedence;
243 continue;
244 }
245 precedence->push_back(ext_id);
246 }
247 }
248 }
249
212 bool ExtensionPrefs::ReadBooleanFromPref( 250 bool ExtensionPrefs::ReadBooleanFromPref(
213 DictionaryValue* ext, const std::string& pref_key) { 251 DictionaryValue* ext, const std::string& pref_key) {
214 if (!ext->HasKey(pref_key)) return false; 252 if (!ext->HasKey(pref_key)) return false;
215 bool bool_value = false; 253 bool bool_value = false;
216 if (!ext->GetBoolean(pref_key, &bool_value)) { 254 if (!ext->GetBoolean(pref_key, &bool_value)) {
217 NOTREACHED() << "Failed to fetch " << pref_key << " flag."; 255 NOTREACHED() << "Failed to fetch " << pref_key << " flag.";
218 // In case we could not fetch the flag, we treat it as false. 256 // In case we could not fetch the flag, we treat it as false.
219 return false; 257 return false;
220 } 258 }
221 return bool_value; 259 return bool_value;
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 // static 936 // static
899 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { 937 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) {
900 prefs->RegisterDictionaryPref(kExtensionsPref); 938 prefs->RegisterDictionaryPref(kExtensionsPref);
901 prefs->RegisterListPref(kExtensionToolbar); 939 prefs->RegisterListPref(kExtensionToolbar);
902 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); 940 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1);
903 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); 941 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate);
904 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); 942 prefs->RegisterListPref(prefs::kExtensionInstallAllowList);
905 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); 943 prefs->RegisterListPref(prefs::kExtensionInstallDenyList);
906 prefs->RegisterListPref(prefs::kExtensionInstallForceList); 944 prefs->RegisterListPref(prefs::kExtensionInstallForceList);
907 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); 945 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */);
946 prefs->RegisterListPref(kExtensionsPrecedence);
908 } 947 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698