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_util.h" | 9 #include "base/string_util.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/pref_service.h" | 12 #include "chrome/browser/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/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Will cause an UMA notification if the mode of the new tab page | 20 // Will cause an UMA notification if the mode of the new tab page |
20 // was changed to hide/show the most visited thumbnails. | 21 // was changed to hide/show the most visited thumbnails. |
21 void NotifySectionDisabled(int new_mode, int old_mode, Profile *profile) { | 22 void NotifySectionDisabled(int new_mode, int old_mode, Profile *profile) { |
22 // If the oldmode HAD either thumbs or lists visible. | 23 // If the oldmode HAD either thumbs or lists visible. |
23 bool old_had_it = (old_mode & THUMB) || (old_mode & LIST); | 24 bool old_had_it = (old_mode & THUMB) || (old_mode & LIST); |
24 bool new_has_it = (new_mode & THUMB) || (new_mode & LIST); | 25 bool new_has_it = (new_mode & THUMB) || (new_mode & LIST); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 prefs::kNTPShownSections, mode); | 81 prefs::kNTPShownSections, mode); |
81 } | 82 } |
82 } | 83 } |
83 | 84 |
84 // static | 85 // static |
85 void ShownSectionsHandler::SetFirstAppLauncherRunPref( | 86 void ShownSectionsHandler::SetFirstAppLauncherRunPref( |
86 PrefService* pref_service) { | 87 PrefService* pref_service) { |
87 // If we have turned on Apps we want to hide most visited and recent to give | 88 // If we have turned on Apps we want to hide most visited and recent to give |
88 // more focus to the Apps section. We do not do this in MigrateUserPrefs | 89 // more focus to the Apps section. We do not do this in MigrateUserPrefs |
89 // because the pref version should not depend on command line switches. | 90 // because the pref version should not depend on command line switches. |
90 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableApps) && | 91 if (Extension::AppsAreEnabled() && |
91 !pref_service->GetBoolean(prefs::kNTPAppLauncherFirstRun)) { | 92 !pref_service->GetBoolean(prefs::kNTPAppLauncherFirstRun)) { |
92 int sections = pref_service->GetInteger(prefs::kNTPShownSections); | 93 int sections = pref_service->GetInteger(prefs::kNTPShownSections); |
93 sections &= ~THUMB; | 94 sections &= ~THUMB; |
94 sections &= ~RECENT; | 95 sections &= ~RECENT; |
95 pref_service->SetInteger(prefs::kNTPShownSections, sections); | 96 pref_service->SetInteger(prefs::kNTPShownSections, sections); |
96 pref_service->SetBoolean(prefs::kNTPAppLauncherFirstRun, true); | 97 pref_service->SetBoolean(prefs::kNTPAppLauncherFirstRun, true); |
97 } | 98 } |
98 } | 99 } |
99 | 100 |
100 // static | 101 // static |
101 void ShownSectionsHandler::RegisterUserPrefs(PrefService* pref_service) { | 102 void ShownSectionsHandler::RegisterUserPrefs(PrefService* pref_service) { |
102 pref_service->RegisterIntegerPref(prefs::kNTPShownSections, | 103 pref_service->RegisterIntegerPref(prefs::kNTPShownSections, |
103 THUMB | RECENT | TIPS | SYNC); | 104 THUMB | RECENT | TIPS | SYNC); |
104 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableApps)) { | 105 if (Extension::AppsAreEnabled()) { |
105 pref_service->RegisterBooleanPref(prefs::kNTPAppLauncherFirstRun, false); | 106 pref_service->RegisterBooleanPref(prefs::kNTPAppLauncherFirstRun, false); |
106 } | 107 } |
107 } | 108 } |
108 | 109 |
109 // static | 110 // static |
110 void ShownSectionsHandler::MigrateUserPrefs(PrefService* pref_service, | 111 void ShownSectionsHandler::MigrateUserPrefs(PrefService* pref_service, |
111 int old_pref_version, | 112 int old_pref_version, |
112 int new_pref_version) { | 113 int new_pref_version) { |
113 bool changed = false; | 114 bool changed = false; |
114 int shown_sections = pref_service->GetInteger(prefs::kNTPShownSections); | 115 int shown_sections = pref_service->GetInteger(prefs::kNTPShownSections); |
115 | 116 |
116 if (old_pref_version < 1) { | 117 if (old_pref_version < 1) { |
117 // TIPS was used in early builds of the NNTP but since it was removed before | 118 // TIPS was used in early builds of the NNTP but since it was removed before |
118 // Chrome 3.0 we want to ensure that it is shown by default. | 119 // Chrome 3.0 we want to ensure that it is shown by default. |
119 shown_sections |= TIPS | SYNC; | 120 shown_sections |= TIPS | SYNC; |
120 changed = true; | 121 changed = true; |
121 } | 122 } |
122 | 123 |
123 if (old_pref_version < 2) { | 124 if (old_pref_version < 2) { |
124 // LIST is no longer used. Change to THUMB. | 125 // LIST is no longer used. Change to THUMB. |
125 shown_sections &= ~LIST; | 126 shown_sections &= ~LIST; |
126 shown_sections |= THUMB; | 127 shown_sections |= THUMB; |
127 changed = true; | 128 changed = true; |
128 } | 129 } |
129 | 130 |
130 if (changed) | 131 if (changed) |
131 pref_service->SetInteger(prefs::kNTPShownSections, shown_sections); | 132 pref_service->SetInteger(prefs::kNTPShownSections, shown_sections); |
132 } | 133 } |
OLD | NEW |