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

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

Issue 7522025: Turn on session restore by default for mac on Lion (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years, 4 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
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/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/defaults.h" 11 #include "chrome/browser/defaults.h"
12 #include "chrome/browser/net/url_fixer_upper.h" 12 #include "chrome/browser/net/url_fixer_upper.h"
13 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/prefs/scoped_user_pref_update.h" 14 #include "chrome/browser/prefs/scoped_user_pref_update.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #ifdef OS_MACOSX
Robert Sesek 2011/07/28 18:30:22 Break this out to be in its own #include block
dhollowa 2011/07/28 20:05:35 Done.
17 #include "chrome/browser/ui/cocoa/window_restore_utils.h"
18 #endif
16 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
17 20
18 namespace { 21 namespace {
19 22
20 // For historical reasons the enum and value registered in the prefs don't line 23 // For historical reasons the enum and value registered in the prefs don't line
21 // up. These are the values registered in prefs. 24 // up. These are the values registered in prefs.
22 const int kPrefValueDefault = 0; 25 const int kPrefValueDefault = 0;
23 const int kPrefValueLast = 1; 26 const int kPrefValueLast = 1;
24 const int kPrefValueURLs = 4; 27 const int kPrefValueURLs = 4;
25 28
26 // Converts a SessionStartupPref::Type to an integer written to prefs. 29 // Converts a SessionStartupPref::Type to an integer written to prefs.
27 int TypeToPrefValue(SessionStartupPref::Type type) { 30 int TypeToPrefValue(SessionStartupPref::Type type) {
28 switch (type) { 31 switch (type) {
29 case SessionStartupPref::LAST: return kPrefValueLast; 32 case SessionStartupPref::LAST: return kPrefValueLast;
30 case SessionStartupPref::URLS: return kPrefValueURLs; 33 case SessionStartupPref::URLS: return kPrefValueURLs;
31 default: return kPrefValueDefault; 34 default: return kPrefValueDefault;
32 } 35 }
33 } 36 }
34 37
35 // Converts an integer pref value to a SessionStartupPref::Type. 38 // Converts an integer pref value to a SessionStartupPref::Type.
36 SessionStartupPref::Type PrefValueToType(int pref_value) { 39 SessionStartupPref::Type PrefValueToType(int pref_value) {
37 switch (pref_value) { 40 switch (pref_value) {
38 case kPrefValueLast: return SessionStartupPref::LAST; 41 case kPrefValueLast: return SessionStartupPref::LAST;
39 case kPrefValueURLs: return SessionStartupPref::URLS; 42 case kPrefValueURLs: return SessionStartupPref::URLS;
40 default: return SessionStartupPref::DEFAULT; 43 default: return SessionStartupPref::DEFAULT;
41 } 44 }
42 } 45 }
43 46
47 bool TypeIsDefaultValue(PrefService* prefs) {
48 const PrefService::Preference* pref_restore =
49 prefs->FindPreference(prefs::kRestoreOnStartup);
50 return pref_restore->IsDefaultValue();
51 }
52
44 } // namespace 53 } // namespace
45 54
46 // static 55 // static
47 void SessionStartupPref::RegisterUserPrefs(PrefService* prefs) { 56 void SessionStartupPref::RegisterUserPrefs(PrefService* prefs) {
48 prefs->RegisterIntegerPref(prefs::kRestoreOnStartup, 57 prefs->RegisterIntegerPref(prefs::kRestoreOnStartup,
49 TypeToPrefValue( 58 TypeToPrefValue(
50 browser_defaults::kDefaultSessionStartupType), 59 browser_defaults::kDefaultSessionStartupType),
51 PrefService::SYNCABLE_PREF); 60 PrefService::SYNCABLE_PREF);
52 prefs->RegisterListPref(prefs::kURLsToRestoreOnStartup, 61 prefs->RegisterListPref(prefs::kURLsToRestoreOnStartup,
53 PrefService::SYNCABLE_PREF); 62 PrefService::SYNCABLE_PREF);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 DCHECK(profile); 98 DCHECK(profile);
90 return GetStartupPref(profile->GetPrefs()); 99 return GetStartupPref(profile->GetPrefs());
91 } 100 }
92 101
93 // static 102 // static
94 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) { 103 SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) {
95 DCHECK(prefs); 104 DCHECK(prefs);
96 SessionStartupPref pref( 105 SessionStartupPref pref(
97 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup))); 106 PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup)));
98 107
108 #ifdef OS_MACOSX
109 if (TypeIsDefaultValue(prefs)) {
110 if (restore_utils::IsWindowRestoreEnabled())
111 pref.type = SessionStartupPref::LAST;
112 else
113 pref.type = SessionStartupPref::DEFAULT;
114 }
115 #endif
116
99 // Always load the urls, even if the pref type isn't URLS. This way the 117 // Always load the urls, even if the pref type isn't URLS. This way the
100 // preferences panels can show the user their last choice. 118 // preferences panels can show the user their last choice.
101 const ListValue* url_pref_list = prefs->GetList( 119 const ListValue* url_pref_list = prefs->GetList(
102 prefs::kURLsToRestoreOnStartup); 120 prefs::kURLsToRestoreOnStartup);
103 if (url_pref_list) { 121 if (url_pref_list) {
104 for (size_t i = 0; i < url_pref_list->GetSize(); ++i) { 122 for (size_t i = 0; i < url_pref_list->GetSize(); ++i) {
105 Value* value = NULL; 123 Value* value = NULL;
106 if (url_pref_list->Get(i, &value)) { 124 if (url_pref_list->Get(i, &value)) {
107 std::string url_text; 125 std::string url_text;
108 if (value->GetAsString(&url_text)) { 126 if (value->GetAsString(&url_text)) {
(...skipping 22 matching lines...) Expand all
131 prefs->FindPreference(prefs::kURLsToRestoreOnStartup); 149 prefs->FindPreference(prefs::kURLsToRestoreOnStartup);
132 DCHECK(pref_urls); 150 DCHECK(pref_urls);
133 return pref_urls->IsManaged(); 151 return pref_urls->IsManaged();
134 } 152 }
135 153
136 SessionStartupPref::SessionStartupPref() : type(DEFAULT) {} 154 SessionStartupPref::SessionStartupPref() : type(DEFAULT) {}
137 155
138 SessionStartupPref::SessionStartupPref(Type type) : type(type) {} 156 SessionStartupPref::SessionStartupPref(Type type) : type(type) {}
139 157
140 SessionStartupPref::~SessionStartupPref() {} 158 SessionStartupPref::~SessionStartupPref() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698