| OLD | NEW |
| 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/dom_ui/shown_sections_handler.h" | 5 #include "chrome/browser/dom_ui/shown_sections_handler.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/metrics/user_metrics.h" | 11 #include "chrome/browser/metrics/user_metrics.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/notification_details.h" | 16 #include "chrome/common/notification_details.h" |
| 17 #include "chrome/common/notification_type.h" | 17 #include "chrome/common/notification_type.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Will cause an UMA notification if the mode of the new tab page | 22 // Will cause an UMA notification if the mode of the new tab page |
| 23 // was changed to hide/show the most visited thumbnails. | 23 // was changed to hide/show the most visited thumbnails. |
| 24 void NotifySectionDisabled(int new_mode, int old_mode, Profile *profile) { | 24 void NotifySectionDisabled(int new_mode, int old_mode, Profile *profile) { |
| 25 // If the oldmode HAD either thumbs or lists visible. | 25 // If the oldmode HAD either thumbs or lists visible. |
| 26 bool old_had_it = (old_mode & THUMB) || (old_mode & LIST); | 26 bool old_had_it = old_mode & THUMB; |
| 27 bool new_has_it = (new_mode & THUMB) || (new_mode & LIST); | 27 bool new_has_it = new_mode & THUMB; |
| 28 | 28 |
| 29 if (old_had_it && !new_has_it) { | 29 if (old_had_it && !new_has_it) { |
| 30 UserMetrics::RecordAction( | 30 UserMetrics::RecordAction( |
| 31 UserMetricsAction("ShowSections_RecentSitesDisabled"), | 31 UserMetricsAction("ShowSections_RecentSitesDisabled"), |
| 32 profile); | 32 profile); |
| 33 } | 33 } |
| 34 | 34 |
| 35 if (new_has_it && !old_had_it) { | 35 if (new_has_it && !old_had_it) { |
| 36 UserMetrics::RecordAction( | 36 UserMetrics::RecordAction( |
| 37 UserMetricsAction("ShowSections_RecentSitesEnabled"), | 37 UserMetricsAction("ShowSections_RecentSitesEnabled"), |
| 38 profile); | 38 profile); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 // static | 44 // static |
| 45 int ShownSectionsHandler::GetShownSections(PrefService* prefs) { | 45 int ShownSectionsHandler::GetShownSections(PrefService* prefs) { |
| 46 int sections = prefs->GetInteger(prefs::kNTPShownSections); | 46 return prefs->GetInteger(prefs::kNTPShownSections); |
| 47 sections &= ~RECENT; | |
| 48 return sections; | |
| 49 } | 47 } |
| 50 | 48 |
| 51 ShownSectionsHandler::ShownSectionsHandler(PrefService* pref_service) | 49 ShownSectionsHandler::ShownSectionsHandler(PrefService* pref_service) |
| 52 : pref_service_(pref_service) { | 50 : pref_service_(pref_service) { |
| 53 pref_service_->AddPrefObserver(prefs::kNTPShownSections, this); | 51 pref_service_->AddPrefObserver(prefs::kNTPShownSections, this); |
| 54 } | 52 } |
| 55 | 53 |
| 56 ShownSectionsHandler::~ShownSectionsHandler() { | 54 ShownSectionsHandler::~ShownSectionsHandler() { |
| 57 pref_service_->RemovePrefObserver(prefs::kNTPShownSections, this); | 55 pref_service_->RemovePrefObserver(prefs::kNTPShownSections, this); |
| 58 } | 56 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 88 int old_mode = pref_service_->GetInteger(prefs::kNTPShownSections); | 86 int old_mode = pref_service_->GetInteger(prefs::kNTPShownSections); |
| 89 | 87 |
| 90 if (old_mode != mode) { | 88 if (old_mode != mode) { |
| 91 NotifySectionDisabled(mode, old_mode, dom_ui_->GetProfile()); | 89 NotifySectionDisabled(mode, old_mode, dom_ui_->GetProfile()); |
| 92 pref_service_->SetInteger(prefs::kNTPShownSections, mode); | 90 pref_service_->SetInteger(prefs::kNTPShownSections, mode); |
| 93 } | 91 } |
| 94 } | 92 } |
| 95 | 93 |
| 96 // static | 94 // static |
| 97 void ShownSectionsHandler::RegisterUserPrefs(PrefService* pref_service) { | 95 void ShownSectionsHandler::RegisterUserPrefs(PrefService* pref_service) { |
| 98 pref_service->RegisterIntegerPref(prefs::kNTPShownSections, | 96 pref_service->RegisterIntegerPref(prefs::kNTPShownSections, THUMB); |
| 99 THUMB | RECENT | TIPS | SYNC | APPS); | |
| 100 } | 97 } |
| 101 | 98 |
| 102 // static | 99 // static |
| 103 void ShownSectionsHandler::MigrateUserPrefs(PrefService* pref_service, | 100 void ShownSectionsHandler::MigrateUserPrefs(PrefService* pref_service, |
| 104 int old_pref_version, | 101 int old_pref_version, |
| 105 int new_pref_version) { | 102 int new_pref_version) { |
| 106 bool changed = false; | 103 bool changed = false; |
| 107 int shown_sections = pref_service->GetInteger(prefs::kNTPShownSections); | 104 int shown_sections = pref_service->GetInteger(prefs::kNTPShownSections); |
| 108 | 105 |
| 109 if (old_pref_version < 1) { | 106 if (old_pref_version < 3) { |
| 110 // TIPS was used in early builds of the NNTP but since it was removed before | 107 // In version 3, we went from being able to show multiple sections to being |
| 111 // Chrome 3.0 we want to ensure that it is shown by default. | 108 // able to show only one expanded at a time. The only two expandable |
| 112 shown_sections |= TIPS | SYNC; | 109 // sections are APPS and THUMBS. |
| 110 if (shown_sections & APPS) |
| 111 shown_sections = APPS; |
| 112 else |
| 113 shown_sections = THUMB; |
| 114 |
| 113 changed = true; | 115 changed = true; |
| 114 } | 116 } |
| 115 | 117 |
| 116 if (old_pref_version < 2) { | |
| 117 // LIST is no longer used. Change to THUMB. | |
| 118 shown_sections &= ~LIST; | |
| 119 shown_sections |= THUMB; | |
| 120 changed = true; | |
| 121 } | |
| 122 | |
| 123 if (changed) | 118 if (changed) |
| 124 pref_service->SetInteger(prefs::kNTPShownSections, shown_sections); | 119 pref_service->SetInteger(prefs::kNTPShownSections, shown_sections); |
| 125 } | 120 } |
| OLD | NEW |