| OLD | NEW |
| 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 "base/version.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 SessionStartupPref SessionStartupPref::GetStartupPref(Profile* profile) { | 114 SessionStartupPref SessionStartupPref::GetStartupPref(Profile* profile) { |
| 115 DCHECK(profile); | 115 DCHECK(profile); |
| 116 return GetStartupPref(profile->GetPrefs()); | 116 return GetStartupPref(profile->GetPrefs()); |
| 117 } | 117 } |
| 118 | 118 |
| 119 // static | 119 // static |
| 120 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) { | 120 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) { |
| 121 DCHECK(prefs); | 121 DCHECK(prefs); |
| 122 | 122 |
| 123 MigrateIfNecessary(prefs); | 123 MigrateIfNecessary(prefs); |
| 124 | 124 MigrateMacDefaultPrefIfNecessary(prefs); |
| 125 #if defined(OS_MACOSX) | |
| 126 if (restore_utils::IsWindowRestoreEnabled()) | |
| 127 MigrateMacDefaultPrefIfNecessary(prefs); | |
| 128 #endif | |
| 129 | 125 |
| 130 SessionStartupPref pref( | 126 SessionStartupPref pref( |
| 131 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup))); | 127 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup))); |
| 132 | 128 |
| 133 // Always load the urls, even if the pref type isn't URLS. This way the | 129 // Always load the urls, even if the pref type isn't URLS. This way the |
| 134 // preferences panels can show the user their last choice. | 130 // preferences panels can show the user their last choice. |
| 135 const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup); | 131 const ListValue* url_list = prefs->GetList(prefs::kURLsToRestoreOnStartup); |
| 136 URLListToPref(url_list, &pref); | 132 URLListToPref(url_list, &pref); |
| 137 | 133 |
| 138 return pref; | 134 return pref; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueURLs); | 177 prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueURLs); |
| 182 SetNewURLList(prefs); | 178 SetNewURLList(prefs); |
| 183 } | 179 } |
| 184 | 180 |
| 185 prefs->SetBoolean(prefs::kRestoreOnStartupMigrated, true); | 181 prefs->SetBoolean(prefs::kRestoreOnStartupMigrated, true); |
| 186 } | 182 } |
| 187 } | 183 } |
| 188 | 184 |
| 189 // static | 185 // static |
| 190 void SessionStartupPref::MigrateMacDefaultPrefIfNecessary(PrefService* prefs) { | 186 void SessionStartupPref::MigrateMacDefaultPrefIfNecessary(PrefService* prefs) { |
| 187 #if defined(OS_MACOSX) |
| 191 DCHECK(prefs); | 188 DCHECK(prefs); |
| 189 if (!restore_utils::IsWindowRestoreEnabled()) |
| 190 return; |
| 192 // The default startup pref used to be LAST, now it is DEFAULT. Don't change | 191 // 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), | 192 // the setting for existing profiles (even if the user has never changed it), |
| 194 // but make new profiles default to DEFAULT. | 193 // but make new profiles default to DEFAULT. |
| 195 bool old_profile_version = Version(prefs->GetString( | 194 bool old_profile_version = Version(prefs->GetString( |
| 196 prefs::kProfileCreatedByVersion)).IsOlderThan("21.0.1180.0"); | 195 prefs::kProfileCreatedByVersion)).IsOlderThan("21.0.1180.0"); |
| 197 if (old_profile_version && TypeIsDefault(prefs)) | 196 if (old_profile_version && TypeIsDefault(prefs)) |
| 198 prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueLast); | 197 prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueLast); |
| 198 #endif |
| 199 } | 199 } |
| 200 | 200 |
| 201 // static | 201 // static |
| 202 bool SessionStartupPref::TypeIsManaged(PrefService* prefs) { | 202 bool SessionStartupPref::TypeIsManaged(PrefService* prefs) { |
| 203 DCHECK(prefs); | 203 DCHECK(prefs); |
| 204 const PrefService::Preference* pref_restore = | 204 const PrefService::Preference* pref_restore = |
| 205 prefs->FindPreference(prefs::kRestoreOnStartup); | 205 prefs->FindPreference(prefs::kRestoreOnStartup); |
| 206 DCHECK(pref_restore); | 206 DCHECK(pref_restore); |
| 207 return pref_restore->IsManaged(); | 207 return pref_restore->IsManaged(); |
| 208 } | 208 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 CHECK(prefs_watcher->GetBackupForPref( | 258 CHECK(prefs_watcher->GetBackupForPref( |
| 259 prefs::kURLsToRestoreOnStartup)->GetAsList(&url_list)); | 259 prefs::kURLsToRestoreOnStartup)->GetAsList(&url_list)); |
| 260 URLListToPref(url_list, &backup_pref); | 260 URLListToPref(url_list, &backup_pref); |
| 261 | 261 |
| 262 return backup_pref; | 262 return backup_pref; |
| 263 } | 263 } |
| 264 | 264 |
| 265 SessionStartupPref::SessionStartupPref(Type type) : type(type) {} | 265 SessionStartupPref::SessionStartupPref(Type type) : type(type) {} |
| 266 | 266 |
| 267 SessionStartupPref::~SessionStartupPref() {} | 267 SessionStartupPref::~SessionStartupPref() {} |
| OLD | NEW |