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

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

Issue 9559002: Bug 111139: Deprecate HOMEPAGE option, remove the UI for it, migrate users away from it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 9 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
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 "chrome/browser/net/url_fixer_upper.h" 10 #include "chrome/browser/net/url_fixer_upper.h"
10 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/prefs/scoped_user_pref_update.h" 12 #include "chrome/browser/prefs/scoped_user_pref_update.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
14 15
15 #if defined(OS_MACOSX) 16 #if defined(OS_MACOSX)
16 #include "chrome/browser/ui/cocoa/window_restore_utils.h" 17 #include "chrome/browser/ui/cocoa/window_restore_utils.h"
17 #endif 18 #endif
18 19
19 namespace { 20 namespace {
20 21
21 // For historical reasons the enum and value registered in the prefs don't line 22 // For historical reasons the enum and value registered in the prefs don't line
22 // up. These are the values registered in prefs. 23 // up. These are the values registered in prefs.
23 const int kPrefValueHomePage = 0; 24 const int kPrefValueHomePage = 0; // Deprecated
24 const int kPrefValueLast = 1; 25 const int kPrefValueLast = 1;
25 const int kPrefValueURLs = 4; 26 const int kPrefValueURLs = 4;
26 const int kPrefValueNewTab = 5; 27 const int kPrefValueNewTab = 5;
27 28
28 // Converts a SessionStartupPref::Type to an integer written to prefs. 29 // Converts a SessionStartupPref::Type to an integer written to prefs.
29 int TypeToPrefValue(SessionStartupPref::Type type) { 30 int TypeToPrefValue(SessionStartupPref::Type type) {
30 switch (type) { 31 switch (type) {
31 case SessionStartupPref::HOMEPAGE: return kPrefValueHomePage;
32 case SessionStartupPref::LAST: return kPrefValueLast; 32 case SessionStartupPref::LAST: return kPrefValueLast;
33 case SessionStartupPref::URLS: return kPrefValueURLs; 33 case SessionStartupPref::URLS: return kPrefValueURLs;
34 default: return kPrefValueNewTab; 34 default: return kPrefValueNewTab;
35 } 35 }
36 } 36 }
37 37
38 void SetNewUrlList(PrefService* prefs) {
39 ListValue new_url_pref_list;
40 StringValue* home_page = new StringValue(prefs->GetString(prefs::kHomePage));
41 new_url_pref_list.Append(home_page);
42 prefs->Set(prefs::kURLsToRestoreOnStartup, new_url_pref_list);
43 }
44
38 } // namespace 45 } // namespace
39 46
40 // static 47 // static
41 void SessionStartupPref::RegisterUserPrefs(PrefService* prefs) { 48 void SessionStartupPref::RegisterUserPrefs(PrefService* prefs) {
42 #if defined(OS_CHROMEOS) 49 #if defined(OS_CHROMEOS)
43 SessionStartupPref::Type type = SessionStartupPref::LAST; 50 SessionStartupPref::Type type = SessionStartupPref::LAST;
44 #else 51 #else
45 SessionStartupPref::Type type = SessionStartupPref::DEFAULT; 52 SessionStartupPref::Type type = SessionStartupPref::DEFAULT;
46 #endif 53 #endif
47 54
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 DCHECK(profile); 101 DCHECK(profile);
95 return GetStartupPref(profile->GetPrefs()); 102 return GetStartupPref(profile->GetPrefs());
96 } 103 }
97 104
98 // static 105 // static
99 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) { 106 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) {
100 DCHECK(prefs); 107 DCHECK(prefs);
101 SessionStartupPref pref( 108 SessionStartupPref pref(
102 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup))); 109 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup)));
103 110
111 // Migrate from "Open the home page" to "Open the following URLs". If the user
112 // had the "Open the homepage" option selected, then we need to switch them to
113 // "Open the following URLs" and set the list of URLs to a list containing
114 // just the user's homepage.
115 if (pref.type == SessionStartupPref::HOMEPAGE) {
Dan Beam 2012/03/02 22:18:08 how does one ever delete this code?
Tyler Breisacher (Chromium) 2012/03/02 22:35:54 If all users have upgraded to a version that has t
116 prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueURLs);
117 pref.type = SessionStartupPref::URLS;
118 SetNewUrlList(prefs);
119 }
120
104 // Always load the urls, even if the pref type isn't URLS. This way the 121 // Always load the urls, even if the pref type isn't URLS. This way the
105 // preferences panels can show the user their last choice. 122 // preferences panels can show the user their last choice.
106 const ListValue* url_pref_list = prefs->GetList( 123 const ListValue* url_pref_list = prefs->GetList(
107 prefs::kURLsToRestoreOnStartup); 124 prefs::kURLsToRestoreOnStartup);
108 if (url_pref_list) { 125 if (url_pref_list) {
109 for (size_t i = 0; i < url_pref_list->GetSize(); ++i) { 126 for (size_t i = 0; i < url_pref_list->GetSize(); ++i) {
110 Value* value = NULL; 127 Value* value = NULL;
111 if (url_pref_list->Get(i, &value)) { 128 if (url_pref_list->Get(i, &value)) {
112 std::string url_text; 129 std::string url_text;
113 if (value->GetAsString(&url_text)) { 130 if (value->GetAsString(&url_text)) {
(...skipping 30 matching lines...) Expand all
144 case kPrefValueLast: return SessionStartupPref::LAST; 161 case kPrefValueLast: return SessionStartupPref::LAST;
145 case kPrefValueURLs: return SessionStartupPref::URLS; 162 case kPrefValueURLs: return SessionStartupPref::URLS;
146 case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE; 163 case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE;
147 default: return SessionStartupPref::DEFAULT; 164 default: return SessionStartupPref::DEFAULT;
148 } 165 }
149 } 166 }
150 167
151 SessionStartupPref::SessionStartupPref(Type type) : type(type) {} 168 SessionStartupPref::SessionStartupPref(Type type) : type(type) {}
152 169
153 SessionStartupPref::~SessionStartupPref() {} 170 SessionStartupPref::~SessionStartupPref() {}
OLDNEW
« no previous file with comments | « chrome/browser/prefs/session_startup_pref.h ('k') | chrome/browser/prefs/session_startup_pref_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698