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

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

Issue 9296038: [uber] Redoing the homepage selection UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 10 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/string_piece.h" 9 #include "base/string_piece.h"
10 #include "base/values.h"
10 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/defaults.h" 12 #include "chrome/browser/defaults.h"
12 #include "chrome/browser/net/url_fixer_upper.h" 13 #include "chrome/browser/net/url_fixer_upper.h"
13 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/prefs/scoped_user_pref_update.h" 15 #include "chrome/browser/prefs/scoped_user_pref_update.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
17 18
18 #ifdef OS_MACOSX 19 #ifdef OS_MACOSX
19 #include "chrome/browser/first_run/first_run.h" 20 #include "chrome/browser/first_run/first_run.h"
20 #include "chrome/browser/ui/cocoa/window_restore_utils.h" 21 #include "chrome/browser/ui/cocoa/window_restore_utils.h"
21 #endif 22 #endif
22 23
23 namespace { 24 namespace {
24 25
25 // For historical reasons the enum and value registered in the prefs don't line 26 // For historical reasons the enum and value registered in the prefs don't line
26 // up. These are the values registered in prefs. 27 // up. These are the values registered in prefs.
27 const int kPrefValueDefault = 0; 28 const int kPrefValueHomePage = 0; // Deprecated
28 const int kPrefValueLast = 1; 29 const int kPrefValueLast = 1;
29 const int kPrefValueURLs = 4; 30 const int kPrefValueURLs = 4;
31 const int kPrefValueNewTab = 5;
30 32
31 // Converts a SessionStartupPref::Type to an integer written to prefs. 33 // Converts a SessionStartupPref::Type to an integer written to prefs.
32 int TypeToPrefValue(SessionStartupPref::Type type) { 34 int TypeToPrefValue(SessionStartupPref::Type type) {
33 switch (type) { 35 switch (type) {
34 case SessionStartupPref::LAST: return kPrefValueLast; 36 case SessionStartupPref::LAST: return kPrefValueLast;
35 case SessionStartupPref::URLS: return kPrefValueURLs; 37 case SessionStartupPref::URLS: return kPrefValueURLs;
36 default: return kPrefValueDefault; 38 default: return kPrefValueNewTab;
37 } 39 }
38 } 40 }
39 41
40 // Converts an integer pref value to a SessionStartupPref::Type. 42 // Converts an integer pref value to a SessionStartupPref::Type.
41 SessionStartupPref::Type PrefValueToType(int pref_value) { 43 SessionStartupPref::Type PrefValueToType(int pref_value) {
42 switch (pref_value) { 44 switch (pref_value) {
43 case kPrefValueLast: return SessionStartupPref::LAST; 45 case kPrefValueLast: return SessionStartupPref::LAST;
44 case kPrefValueURLs: return SessionStartupPref::URLS; 46 case kPrefValueURLs: return SessionStartupPref::URLS;
45 default: return SessionStartupPref::DEFAULT; 47 case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE;
48 default: return SessionStartupPref::DEFAULT;
46 } 49 }
47 } 50 }
48 51
52 // Sets the list of URLs to display at startup to a list consisting of only the
53 // user's home page.
54 void SetNewUrlList(PrefService* prefs) {
55 ListValue new_url_pref_list;
56 StringValue* home_page = new StringValue(prefs->GetString(prefs::kHomePage));
57 new_url_pref_list.Append(home_page);
58 prefs->Set(prefs::kURLsToRestoreOnStartup, new_url_pref_list);
59 }
60
49 } // namespace 61 } // namespace
50 62
51 // static 63 // static
52 void SessionStartupPref::RegisterUserPrefs(PrefService* prefs) { 64 void SessionStartupPref::RegisterUserPrefs(PrefService* prefs) {
53 SessionStartupPref::Type type = browser_defaults::kDefaultSessionStartupType; 65 SessionStartupPref::Type type = browser_defaults::kDefaultSessionStartupType;
54 66
55 #ifdef OS_MACOSX 67 #ifdef OS_MACOSX
56 // During first run the calling code relies on |DEFAULT| session preference 68 // During first run the calling code relies on |DEFAULT| session preference
57 // value to avoid session restore. That is respected here. 69 // value to avoid session restore. That is respected here.
58 if (!first_run::IsChromeFirstRun()) { 70 if (!first_run::IsChromeFirstRun()) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 DCHECK(profile); 120 DCHECK(profile);
109 return GetStartupPref(profile->GetPrefs()); 121 return GetStartupPref(profile->GetPrefs());
110 } 122 }
111 123
112 // static 124 // static
113 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) { 125 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) {
114 DCHECK(prefs); 126 DCHECK(prefs);
115 SessionStartupPref pref( 127 SessionStartupPref pref(
116 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup))); 128 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup)));
117 129
130 // Migrate from "Open the home page" to "Open the following URLs". If the user
131 // had the "Open the homepage" option selected, then we need switch them to
132 // "Open the following URLs" and set the list of URLs to a list containing
133 // just the user's homepage.
134 if (pref.type == SessionStartupPref::HOMEPAGE) {
135 prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueURLs);
136 pref.type = SessionStartupPref::URLS;
137 SetNewUrlList(prefs);
138 }
139
118 // Always load the urls, even if the pref type isn't URLS. This way the 140 // Always load the urls, even if the pref type isn't URLS. This way the
119 // preferences panels can show the user their last choice. 141 // preferences panels can show the user their last choice.
120 const ListValue* url_pref_list = prefs->GetList( 142 const ListValue* url_pref_list = prefs->GetList(
121 prefs::kURLsToRestoreOnStartup); 143 prefs::kURLsToRestoreOnStartup);
122 if (url_pref_list) { 144 if (url_pref_list) {
123 for (size_t i = 0; i < url_pref_list->GetSize(); ++i) { 145 for (size_t i = 0; i < url_pref_list->GetSize(); ++i) {
124 Value* value = NULL; 146 Value* value = NULL;
125 if (url_pref_list->Get(i, &value)) { 147 if (url_pref_list->Get(i, &value)) {
126 std::string url_text; 148 std::string url_text;
127 if (value->GetAsString(&url_text)) { 149 if (value->GetAsString(&url_text)) {
(...skipping 17 matching lines...) Expand all
145 167
146 // static 168 // static
147 bool SessionStartupPref::URLsAreManaged(PrefService* prefs) { 169 bool SessionStartupPref::URLsAreManaged(PrefService* prefs) {
148 DCHECK(prefs); 170 DCHECK(prefs);
149 const PrefService::Preference* pref_urls = 171 const PrefService::Preference* pref_urls =
150 prefs->FindPreference(prefs::kURLsToRestoreOnStartup); 172 prefs->FindPreference(prefs::kURLsToRestoreOnStartup);
151 DCHECK(pref_urls); 173 DCHECK(pref_urls);
152 return pref_urls->IsManaged(); 174 return pref_urls->IsManaged();
153 } 175 }
154 176
155 SessionStartupPref::SessionStartupPref() : type(DEFAULT) {}
156
157 SessionStartupPref::SessionStartupPref(Type type) : type(type) {} 177 SessionStartupPref::SessionStartupPref(Type type) : type(type) {}
158 178
159 SessionStartupPref::~SessionStartupPref() {} 179 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