diff options
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.h | 2 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler.cc | 29 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler.h | 7 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler_unittest.cc | 37 | ||||
-rw-r--r-- | chrome/browser/resources/new_new_tab.html | 6 | ||||
-rw-r--r-- | chrome/browser/resources/ntp/apps.js | 2 |
6 files changed, 32 insertions, 51 deletions
diff --git a/chrome/browser/dom_ui/new_tab_ui.h b/chrome/browser/dom_ui/new_tab_ui.h index e091fcf..35e2a87 100644 --- a/chrome/browser/dom_ui/new_tab_ui.h +++ b/chrome/browser/dom_ui/new_tab_ui.h @@ -96,7 +96,7 @@ class NewTabUI : public DOMUI, NotificationRegistrar registrar_; // The preference version. This used for migrating prefs of the NTP. - static const int current_pref_version_ = 2; + static const int current_pref_version_ = 3; DISALLOW_COPY_AND_ASSIGN(NewTabUI); }; diff --git a/chrome/browser/dom_ui/shown_sections_handler.cc b/chrome/browser/dom_ui/shown_sections_handler.cc index 4af2d0b..78ff716 100644 --- a/chrome/browser/dom_ui/shown_sections_handler.cc +++ b/chrome/browser/dom_ui/shown_sections_handler.cc @@ -23,8 +23,8 @@ namespace { // was changed to hide/show the most visited thumbnails. void NotifySectionDisabled(int new_mode, int old_mode, Profile *profile) { // If the oldmode HAD either thumbs or lists visible. - bool old_had_it = (old_mode & THUMB) || (old_mode & LIST); - bool new_has_it = (new_mode & THUMB) || (new_mode & LIST); + bool old_had_it = old_mode & THUMB; + bool new_has_it = new_mode & THUMB; if (old_had_it && !new_has_it) { UserMetrics::RecordAction( @@ -43,9 +43,7 @@ void NotifySectionDisabled(int new_mode, int old_mode, Profile *profile) { // static int ShownSectionsHandler::GetShownSections(PrefService* prefs) { - int sections = prefs->GetInteger(prefs::kNTPShownSections); - sections &= ~RECENT; - return sections; + return prefs->GetInteger(prefs::kNTPShownSections); } ShownSectionsHandler::ShownSectionsHandler(PrefService* pref_service) @@ -95,8 +93,7 @@ void ShownSectionsHandler::HandleSetShownSections(const ListValue* args) { // static void ShownSectionsHandler::RegisterUserPrefs(PrefService* pref_service) { - pref_service->RegisterIntegerPref(prefs::kNTPShownSections, - THUMB | RECENT | TIPS | SYNC | APPS); + pref_service->RegisterIntegerPref(prefs::kNTPShownSections, THUMB); } // static @@ -106,17 +103,15 @@ void ShownSectionsHandler::MigrateUserPrefs(PrefService* pref_service, bool changed = false; int shown_sections = pref_service->GetInteger(prefs::kNTPShownSections); - if (old_pref_version < 1) { - // TIPS was used in early builds of the NNTP but since it was removed before - // Chrome 3.0 we want to ensure that it is shown by default. - shown_sections |= TIPS | SYNC; - changed = true; - } + if (old_pref_version < 3) { + // In version 3, we went from being able to show multiple sections to being + // able to show only one expanded at a time. The only two expandable + // sections are APPS and THUMBS. + if (shown_sections & APPS) + shown_sections = APPS; + else + shown_sections = THUMB; - if (old_pref_version < 2) { - // LIST is no longer used. Change to THUMB. - shown_sections &= ~LIST; - shown_sections |= THUMB; changed = true; } diff --git a/chrome/browser/dom_ui/shown_sections_handler.h b/chrome/browser/dom_ui/shown_sections_handler.h index 8821d640..14a3215 100644 --- a/chrome/browser/dom_ui/shown_sections_handler.h +++ b/chrome/browser/dom_ui/shown_sections_handler.h @@ -14,13 +14,10 @@ class Value; class PrefService; // Use for the shown sections bitmask. +// Currently, only the THUMB and APPS sections can be toggled by the user. Other +// sections are shown automatically if they have data, and hidden otherwise. enum Section { THUMB = 1, - LIST = 2, - RECENT = 4, - TIPS = 8, - SYNC = 16, - DEBUG = 32, APPS = 64 }; diff --git a/chrome/browser/dom_ui/shown_sections_handler_unittest.cc b/chrome/browser/dom_ui/shown_sections_handler_unittest.cc index 48ca9a1..9e89b1b 100644 --- a/chrome/browser/dom_ui/shown_sections_handler_unittest.cc +++ b/chrome/browser/dom_ui/shown_sections_handler_unittest.cc @@ -15,35 +15,30 @@ class ShownSectionsHandlerTest : public testing::Test { }; -TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs) { - scoped_ptr<PrefService> pref(new TestingPrefService); - - // Set an *old* value - pref->RegisterIntegerPref(prefs::kNTPShownSections, 0); - pref->SetInteger(prefs::kNTPShownSections, THUMB); +namespace { - ShownSectionsHandler::MigrateUserPrefs(pref.get(), 0, 1); - - int shown_sections = pref->GetInteger(prefs::kNTPShownSections); +int MigratePrefValue(PrefService* prefs, int starting_value) { + prefs->SetInteger(prefs::kNTPShownSections, starting_value); + ShownSectionsHandler::MigrateUserPrefs(prefs, 1, 3); + return prefs->GetInteger(prefs::kNTPShownSections); +} - EXPECT_TRUE(shown_sections & THUMB); - EXPECT_FALSE(shown_sections & LIST); - EXPECT_FALSE(shown_sections & RECENT); - EXPECT_TRUE(shown_sections & TIPS); - EXPECT_TRUE(shown_sections & SYNC); } -TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs1To2) { +TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs) { scoped_ptr<PrefService> pref(new TestingPrefService); - // Set an *old* value pref->RegisterIntegerPref(prefs::kNTPShownSections, 0); - pref->SetInteger(prefs::kNTPShownSections, LIST); - ShownSectionsHandler::MigrateUserPrefs(pref.get(), 1, 2); + EXPECT_EQ(APPS, MigratePrefValue(pref.get(), APPS)); + EXPECT_EQ(THUMB, MigratePrefValue(pref.get(), THUMB)); + EXPECT_EQ(APPS, MigratePrefValue(pref.get(), APPS | THUMB)); - int shown_sections = pref->GetInteger(prefs::kNTPShownSections); + // 2 is not currently used, but older state may contain it and we should do + // something reasonable. + EXPECT_EQ(THUMB, MigratePrefValue(pref.get(), 3)); - EXPECT_TRUE(shown_sections & THUMB); - EXPECT_FALSE(shown_sections & LIST); + // 0 can't correspond to any section, but we should still do something + // reasonable. + EXPECT_EQ(THUMB, MigratePrefValue(pref.get(), 0)); } diff --git a/chrome/browser/resources/new_new_tab.html b/chrome/browser/resources/new_new_tab.html index e1c6574..e306dd8 100644 --- a/chrome/browser/resources/new_new_tab.html +++ b/chrome/browser/resources/new_new_tab.html @@ -67,11 +67,6 @@ registerCallback('setShownSections'); */ var Section = { THUMB: 1, - // LIST is no longer used - RECENT: 4, - // TIPS is no longer used - SYNC: 16, - DEBUG: 32, APPS: 64 }; @@ -222,7 +217,6 @@ cr.ui.decorate('button[menu]', cr.ui.MenuButton); <script> updateSimpleSection('apps', Section.APPS); updateSimpleSection('most-visited', Section.THUMB); - updateSimpleSection('recently-closed', Section.RECENT); layoutSections(); </script> </html> diff --git a/chrome/browser/resources/ntp/apps.js b/chrome/browser/resources/ntp/apps.js index 0ae457a..7d30f9e 100644 --- a/chrome/browser/resources/ntp/apps.js +++ b/chrome/browser/resources/ntp/apps.js @@ -12,7 +12,7 @@ function getAppsCallback(data) { if (data.apps.length == 0) { appsSection.classList.add('disabled'); - layoutSections(); + setShownSections(Section.THUMB); return; } |