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

Unified Diff: chrome/browser/extensions/extension_prefs.cc

Issue 7717012: ntp4: default to 18 apps per page for new installs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove checks Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_prefs.cc
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc
index 95c10b1d1300d4e944bbf997e5539f0189db1807..816b5ce404ac39333cca2fa79b6ed0a45c7683f9 100644
--- a/chrome/browser/extensions/extension_prefs.cc
+++ b/chrome/browser/extensions/extension_prefs.cc
@@ -21,6 +21,10 @@ using base::Time;
namespace {
+// The number of apps per page. This isn't a hard limit, but new apps installed
+// from the webstore will overflow onto a new page if this limit is reached.
+const int kNaturalAppPageSize = 18;
+
// Additional preferences keys
// Where an extension was installed from. (see Extension::Location)
@@ -980,10 +984,15 @@ void ExtensionPrefs::OnExtensionInstalled(
extension_dict->Set(kPrefManifest,
extension->manifest_value()->DeepCopy());
}
- extension_dict->Set(kPrefPageIndex,
- Value::CreateIntegerValue(page_index));
- extension_dict->Set(kPrefAppLaunchIndex,
- Value::CreateIntegerValue(GetNextAppLaunchIndex(page_index)));
+
+ if (extension->is_app()) {
+ if (page_index == -1)
+ page_index = GetNaturalAppPageIndex();
+ extension_dict->Set(kPrefPageIndex,
+ Value::CreateIntegerValue(page_index));
+ extension_dict->Set(kPrefAppLaunchIndex,
+ Value::CreateIntegerValue(GetNextAppLaunchIndex(page_index)));
+ }
extension_pref_value_map_->RegisterExtension(
id, install_time, initial_state == Extension::ENABLED);
content_settings_store_->RegisterExtension(
@@ -1322,7 +1331,6 @@ int ExtensionPrefs::GetAppLaunchIndex(const std::string& extension_id) {
void ExtensionPrefs::SetAppLaunchIndex(const std::string& extension_id,
int index) {
- DCHECK_GE(index, 0);
UpdateExtensionPref(extension_id, kPrefAppLaunchIndex,
Value::CreateIntegerValue(index));
}
@@ -1343,6 +1351,25 @@ int ExtensionPrefs::GetNextAppLaunchIndex(int on_page) {
return max_value + 1;
}
+int ExtensionPrefs::GetNaturalAppPageIndex() {
+ const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
+ if (!extensions)
+ return 0;
+
+ std::map<int, int> page_counts;
+ for (DictionaryValue::key_iterator extension_id = extensions->begin_keys();
+ extension_id != extensions->end_keys(); ++extension_id) {
+ int page_index = GetPageIndex(*extension_id);
+ if (page_index >= 0)
+ page_counts[page_index] = page_counts[page_index] + 1;
+ }
+ for (int i = 0; ; i++) {
+ std::map<int, int>::const_iterator it = page_counts.find(i);
+ if (it == page_counts.end() || it->second < kNaturalAppPageSize)
+ return i;
+ }
+}
+
void ExtensionPrefs::SetAppLauncherOrder(
const std::vector<std::string>& extension_ids) {
for (size_t i = 0; i < extension_ids.size(); ++i)
@@ -1361,7 +1388,6 @@ int ExtensionPrefs::GetPageIndex(const std::string& extension_id) {
}
void ExtensionPrefs::SetPageIndex(const std::string& extension_id, int index) {
- CHECK_GE(index, 0);
UpdateExtensionPref(extension_id, kPrefPageIndex,
Value::CreateIntegerValue(index));
}

Powered by Google App Engine
This is Rietveld 408576698