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

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

Issue 3611014: Fix 57090: NTP apps sorted in random-looking order.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 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) 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 const char kPrefAllowFileAccess[] = "allowFileAccess"; 72 const char kPrefAllowFileAccess[] = "allowFileAccess";
73 73
74 // A preference set by the web store to indicate login information for 74 // A preference set by the web store to indicate login information for
75 // purchased apps. 75 // purchased apps.
76 const char kWebStoreLogin[] = "extensions.webstore_login"; 76 const char kWebStoreLogin[] = "extensions.webstore_login";
77 77
78 // A preference set by the the NTP to persist the desired launch container type 78 // A preference set by the the NTP to persist the desired launch container type
79 // used for apps. 79 // used for apps.
80 const char kPrefLaunchType[] = "launchType"; 80 const char kPrefLaunchType[] = "launchType";
81 81
82 // A preference determining the order of which the apps appear on the NTP.
83 const char kPrefAppLaunchIndex[] = "app_launcher_index";
84
82 } // namespace 85 } // namespace
83 86
84 //////////////////////////////////////////////////////////////////////////////// 87 ////////////////////////////////////////////////////////////////////////////////
85 88
86 namespace { 89 namespace {
87 90
88 // TODO(asargent) - This is cleanup code for a key that was introduced into 91 // TODO(asargent) - This is cleanup code for a key that was introduced into
89 // the extensions.settings sub-dictionary which wasn't a valid extension 92 // the extensions.settings sub-dictionary which wasn't a valid extension
90 // id. We can remove this in a couple of months. (See http://crbug.com/40017 93 // id. We can remove this in a couple of months. (See http://crbug.com/40017
91 // and http://crbug.com/39745 for more details). 94 // and http://crbug.com/39745 for more details).
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 Value::CreateIntegerValue(extension->location())); 534 Value::CreateIntegerValue(extension->location()));
532 FilePath::StringType path = MakePathRelative(install_directory_, 535 FilePath::StringType path = MakePathRelative(install_directory_,
533 extension->path(), NULL); 536 extension->path(), NULL);
534 UpdateExtensionPref(id, kPrefPath, Value::CreateStringValue(path)); 537 UpdateExtensionPref(id, kPrefPath, Value::CreateStringValue(path));
535 // We store prefs about LOAD extensions, but don't cache their manifest 538 // We store prefs about LOAD extensions, but don't cache their manifest
536 // since it may change on disk. 539 // since it may change on disk.
537 if (extension->location() != Extension::LOAD) { 540 if (extension->location() != Extension::LOAD) {
538 UpdateExtensionPref(id, kPrefManifest, 541 UpdateExtensionPref(id, kPrefManifest,
539 extension->manifest_value()->DeepCopy()); 542 extension->manifest_value()->DeepCopy());
540 } 543 }
544 UpdateExtensionPref(id, kPrefAppLaunchIndex,
545 Value::CreateIntegerValue(GetNextAppLaunchIndex()));
541 SavePrefsAndNotify(); 546 SavePrefsAndNotify();
542 } 547 }
543 548
544 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, 549 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id,
545 const Extension::Location& location, 550 const Extension::Location& location,
546 bool external_uninstall) { 551 bool external_uninstall) {
547 // For external extensions, we save a preference reminding ourself not to try 552 // For external extensions, we save a preference reminding ourself not to try
548 // and install the extension anymore (except when |external_uninstall| is 553 // and install the extension anymore (except when |external_uninstall| is
549 // true, which signifies that the registry key was deleted or the pref file 554 // true, which signifies that the registry key was deleted or the pref file
550 // no longer lists the extension). 555 // no longer lists the extension).
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 return true; 862 return true;
858 } 863 }
859 return false; 864 return false;
860 } 865 }
861 866
862 void ExtensionPrefs::SetWebStoreLogin(const std::string& login) { 867 void ExtensionPrefs::SetWebStoreLogin(const std::string& login) {
863 prefs_->SetString(kWebStoreLogin, login); 868 prefs_->SetString(kWebStoreLogin, login);
864 SavePrefsAndNotify(); 869 SavePrefsAndNotify();
865 } 870 }
866 871
872 int ExtensionPrefs::GetAppLaunchIndex(const std::string& extension_id) {
873 int value;
874 if (ReadExtensionPrefInteger(extension_id, kPrefAppLaunchIndex, &value))
875 return value;
876
877 return -1;
878 }
879
880 void ExtensionPrefs::SetAppLaunchIndex(const std::string& extension_id,
881 int index) {
882 DCHECK_GE(index, 0);
883 UpdateExtensionPref(extension_id, kPrefAppLaunchIndex,
884 Value::CreateIntegerValue(index));
885 SavePrefsAndNotify();
886 }
887
888 int ExtensionPrefs::GetNextAppLaunchIndex() {
889 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
890 if (!extensions)
891 return 0;
892
893 int max_value = -1;
894 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys();
895 extension_id != extensions->end_keys(); ++extension_id) {
896 int value = GetAppLaunchIndex(*extension_id);
897 if (value > max_value)
898 max_value = value;
899 }
900 return max_value + 1;
901 }
902
867 // static 903 // static
868 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { 904 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) {
869 prefs->RegisterDictionaryPref(kExtensionsPref); 905 prefs->RegisterDictionaryPref(kExtensionsPref);
870 prefs->RegisterListPref(kExtensionToolbar); 906 prefs->RegisterListPref(kExtensionToolbar);
871 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); 907 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1);
872 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); 908 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate);
873 prefs->RegisterListPref(kExtensionInstallAllowList); 909 prefs->RegisterListPref(kExtensionInstallAllowList);
874 prefs->RegisterListPref(kExtensionInstallDenyList); 910 prefs->RegisterListPref(kExtensionInstallDenyList);
875 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); 911 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */);
876 } 912 }
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