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

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

Issue 9583025: Revert 124583 (See crbug.com/114259) Original info for r124583 is: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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"
10 #include "chrome/browser/net/url_fixer_upper.h" 9 #include "chrome/browser/net/url_fixer_upper.h"
11 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/prefs/scoped_user_pref_update.h" 11 #include "chrome/browser/prefs/scoped_user_pref_update.h"
13 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
15 14
16 #if defined(OS_MACOSX) 15 #if defined(OS_MACOSX)
17 #include "chrome/browser/ui/cocoa/window_restore_utils.h" 16 #include "chrome/browser/ui/cocoa/window_restore_utils.h"
18 #endif 17 #endif
19 18
20 namespace { 19 namespace {
21 20
22 // For historical reasons the enum and value registered in the prefs don't line 21 // For historical reasons the enum and value registered in the prefs don't line
23 // up. These are the values registered in prefs. 22 // up. These are the values registered in prefs.
24 const int kPrefValueHomePage = 0; // Deprecated 23 const int kPrefValueHomePage = 0;
25 const int kPrefValueLast = 1; 24 const int kPrefValueLast = 1;
26 const int kPrefValueURLs = 4; 25 const int kPrefValueURLs = 4;
27 const int kPrefValueNewTab = 5; 26 const int kPrefValueNewTab = 5;
28 27
29 // Converts a SessionStartupPref::Type to an integer written to prefs. 28 // Converts a SessionStartupPref::Type to an integer written to prefs.
30 int TypeToPrefValue(SessionStartupPref::Type type) { 29 int TypeToPrefValue(SessionStartupPref::Type type) {
31 switch (type) { 30 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
45 } // namespace 38 } // namespace
46 39
47 // static 40 // static
48 void SessionStartupPref::RegisterUserPrefs(PrefService* prefs) { 41 void SessionStartupPref::RegisterUserPrefs(PrefService* prefs) {
49 #if defined(OS_CHROMEOS) 42 #if defined(OS_CHROMEOS)
50 SessionStartupPref::Type type = SessionStartupPref::LAST; 43 SessionStartupPref::Type type = SessionStartupPref::LAST;
51 #else 44 #else
52 SessionStartupPref::Type type = SessionStartupPref::DEFAULT; 45 SessionStartupPref::Type type = SessionStartupPref::DEFAULT;
53 #endif 46 #endif
54 47
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 DCHECK(profile); 94 DCHECK(profile);
102 return GetStartupPref(profile->GetPrefs()); 95 return GetStartupPref(profile->GetPrefs());
103 } 96 }
104 97
105 // static 98 // static
106 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) { 99 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) {
107 DCHECK(prefs); 100 DCHECK(prefs);
108 SessionStartupPref pref( 101 SessionStartupPref pref(
109 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup))); 102 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup)));
110 103
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) {
116 prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueURLs);
117 pref.type = SessionStartupPref::URLS;
118 SetNewUrlList(prefs);
119 }
120
121 // Always load the urls, even if the pref type isn't URLS. This way the 104 // Always load the urls, even if the pref type isn't URLS. This way the
122 // preferences panels can show the user their last choice. 105 // preferences panels can show the user their last choice.
123 const ListValue* url_pref_list = prefs->GetList( 106 const ListValue* url_pref_list = prefs->GetList(
124 prefs::kURLsToRestoreOnStartup); 107 prefs::kURLsToRestoreOnStartup);
125 if (url_pref_list) { 108 if (url_pref_list) {
126 for (size_t i = 0; i < url_pref_list->GetSize(); ++i) { 109 for (size_t i = 0; i < url_pref_list->GetSize(); ++i) {
127 Value* value = NULL; 110 Value* value = NULL;
128 if (url_pref_list->Get(i, &value)) { 111 if (url_pref_list->Get(i, &value)) {
129 std::string url_text; 112 std::string url_text;
130 if (value->GetAsString(&url_text)) { 113 if (value->GetAsString(&url_text)) {
(...skipping 30 matching lines...) Expand all
161 case kPrefValueLast: return SessionStartupPref::LAST; 144 case kPrefValueLast: return SessionStartupPref::LAST;
162 case kPrefValueURLs: return SessionStartupPref::URLS; 145 case kPrefValueURLs: return SessionStartupPref::URLS;
163 case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE; 146 case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE;
164 default: return SessionStartupPref::DEFAULT; 147 default: return SessionStartupPref::DEFAULT;
165 } 148 }
166 } 149 }
167 150
168 SessionStartupPref::SessionStartupPref(Type type) : type(type) {} 151 SessionStartupPref::SessionStartupPref(Type type) : type(type) {}
169 152
170 SessionStartupPref::~SessionStartupPref() {} 153 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