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

Side by Side Diff: chrome/browser/prefs/session_startup_pref.cc

Issue 10581013: Make the default startup pref to be NTP also on Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: oops Created 8 years, 6 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
« no previous file with comments | « chrome/browser/prefs/session_startup_pref.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/prefs/session_startup_pref.h" 5 #include "chrome/browser/prefs/session_startup_pref.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "base/version.h"
10 #include "chrome/browser/net/url_fixer_upper.h" 11 #include "chrome/browser/net/url_fixer_upper.h"
11 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/prefs/scoped_user_pref_update.h" 13 #include "chrome/browser/prefs/scoped_user_pref_update.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/protector/protected_prefs_watcher.h" 15 #include "chrome/browser/protector/protected_prefs_watcher.h"
15 #include "chrome/browser/protector/protector_service.h" 16 #include "chrome/browser/protector/protector_service.h"
16 #include "chrome/browser/protector/protector_service_factory.h" 17 #include "chrome/browser/protector/protector_service_factory.h"
17 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
18 19
19 #if defined(OS_MACOSX) 20 #if defined(OS_MACOSX)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 prefs->RegisterListPref(prefs::kURLsToRestoreOnStartup, 66 prefs->RegisterListPref(prefs::kURLsToRestoreOnStartup,
66 PrefService::SYNCABLE_PREF); 67 PrefService::SYNCABLE_PREF);
67 prefs->RegisterBooleanPref(prefs::kRestoreOnStartupMigrated, 68 prefs->RegisterBooleanPref(prefs::kRestoreOnStartupMigrated,
68 false, 69 false,
69 PrefService::UNSYNCABLE_PREF); 70 PrefService::UNSYNCABLE_PREF);
70 } 71 }
71 72
72 // static 73 // static
73 SessionStartupPref::Type SessionStartupPref::GetDefaultStartupType() { 74 SessionStartupPref::Type SessionStartupPref::GetDefaultStartupType() {
74 #if defined(OS_CHROMEOS) 75 #if defined(OS_CHROMEOS)
75 SessionStartupPref::Type type = SessionStartupPref::LAST; 76 return SessionStartupPref::LAST;
76 #else 77 #else
77 SessionStartupPref::Type type = SessionStartupPref::DEFAULT; 78 return SessionStartupPref::DEFAULT;
78 #endif 79 #endif
79
80 #if defined(OS_MACOSX)
81 // Use Lion's system preference, if it is set.
82 if (restore_utils::IsWindowRestoreEnabled())
83 type = SessionStartupPref::LAST;
84 #endif
85
86 return type;
87 } 80 }
88 81
89 // static 82 // static
90 void SessionStartupPref::SetStartupPref( 83 void SessionStartupPref::SetStartupPref(
91 Profile* profile, 84 Profile* profile,
92 const SessionStartupPref& pref) { 85 const SessionStartupPref& pref) {
93 DCHECK(profile); 86 DCHECK(profile);
94 SetStartupPref(profile->GetPrefs(), pref); 87 SetStartupPref(profile->GetPrefs(), pref);
95 } 88 }
96 89
(...skipping 25 matching lines...) Expand all
122 DCHECK(profile); 115 DCHECK(profile);
123 return GetStartupPref(profile->GetPrefs()); 116 return GetStartupPref(profile->GetPrefs());
124 } 117 }
125 118
126 // static 119 // static
127 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) { 120 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) {
128 DCHECK(prefs); 121 DCHECK(prefs);
129 122
130 MigrateIfNecessary(prefs); 123 MigrateIfNecessary(prefs);
131 124
125 #if defined(OS_MACOSX)
126 if (restore_utils::IsWindowRestoreEnabled())
127 MigrateMacDefaultPrefIfNecessary(prefs);
128 #endif
129
132 SessionStartupPref pref( 130 SessionStartupPref pref(
133 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup))); 131 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup)));
134 132
135 // Always load the urls, even if the pref type isn't URLS. This way the 133 // Always load the urls, even if the pref type isn't URLS. This way the
136 // preferences panels can show the user their last choice. 134 // preferences panels can show the user their last choice.
137 const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup); 135 const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup);
138 URLListToPref(url_list, &pref); 136 URLListToPref(url_list, &pref);
139 137
140 return pref; 138 return pref;
141 } 139 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // default value is "open the new tab page" which is what we want.) 180 // default value is "open the new tab page" which is what we want.)
183 prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueURLs); 181 prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueURLs);
184 SetNewURLList(prefs); 182 SetNewURLList(prefs);
185 } 183 }
186 184
187 prefs->SetBoolean(prefs::kRestoreOnStartupMigrated, true); 185 prefs->SetBoolean(prefs::kRestoreOnStartupMigrated, true);
188 } 186 }
189 } 187 }
190 188
191 // static 189 // static
190 void SessionStartupPref::MigrateMacDefaultPrefIfNecessary(PrefService* prefs) {
191 DCHECK(prefs);
192 // The default startup pref used to be LAST, now it is DEFAULT. Don't change
193 // the setting for existing profiles (even if the user has never changed it),
194 // but make new profiles default to DEFAULT.
195 bool old_profile_version = Version(prefs->GetString(
196 prefs::kProfileCreatedByVersion)).IsOlderThan("21.0.1180.0");
197 if (old_profile_version && TypeIsDefault(prefs))
198 prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueLast);
Joao da Silva 2012/06/19 15:23:00 kPrevValueLast might not be the right value here,
marja 2012/06/19 15:24:48 This code only gets executed if restore_utils::IsW
199 }
200
201 // static
192 bool SessionStartupPref::TypeIsManaged(PrefService* prefs) { 202 bool SessionStartupPref::TypeIsManaged(PrefService* prefs) {
193 DCHECK(prefs); 203 DCHECK(prefs);
194 const PrefService::Preference* pref_restore = 204 const PrefService::Preference* pref_restore =
195 prefs->FindPreference(prefs::kRestoreOnStartup); 205 prefs->FindPreference(prefs::kRestoreOnStartup);
196 DCHECK(pref_restore); 206 DCHECK(pref_restore);
197 return pref_restore->IsManaged(); 207 return pref_restore->IsManaged();
198 } 208 }
199 209
200 // static 210 // static
201 bool SessionStartupPref::URLsAreManaged(PrefService* prefs) { 211 bool SessionStartupPref::URLsAreManaged(PrefService* prefs) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 CHECK(prefs_watcher->GetBackupForPref( 258 CHECK(prefs_watcher->GetBackupForPref(
249 prefs::kURLsToRestoreOnStartup)->GetAsList(&url_list)); 259 prefs::kURLsToRestoreOnStartup)->GetAsList(&url_list));
250 URLListToPref(url_list, &backup_pref); 260 URLListToPref(url_list, &backup_pref);
251 261
252 return backup_pref; 262 return backup_pref;
253 } 263 }
254 264
255 SessionStartupPref::SessionStartupPref(Type type) : type(type) {} 265 SessionStartupPref::SessionStartupPref(Type type) : type(type) {}
256 266
257 SessionStartupPref::~SessionStartupPref() {} 267 SessionStartupPref::~SessionStartupPref() {}
OLDNEW
« no previous file with comments | « chrome/browser/prefs/session_startup_pref.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698