OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/login/session/user_session_manager.h" | 5 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 namespace { | 112 namespace { |
113 | 113 |
114 // Milliseconds until we timeout our attempt to fetch flags from the child | 114 // Milliseconds until we timeout our attempt to fetch flags from the child |
115 // account service. | 115 // account service. |
116 static const int kFlagsFetchingLoginTimeoutMs = 1000; | 116 static const int kFlagsFetchingLoginTimeoutMs = 1000; |
117 | 117 |
118 // The maximum ammount of time that we are willing to delay a browser restart | 118 // The maximum ammount of time that we are willing to delay a browser restart |
119 // for, waiting for a session restore to finish. | 119 // for, waiting for a session restore to finish. |
120 static const int kMaxRestartDelaySeconds = 10; | 120 static const int kMaxRestartDelaySeconds = 10; |
121 | 121 |
122 // Max days after initial login that we're willing to show Goodies. | |
123 static const int kMaxDaysAfterOobeForGoodies = 14; | |
124 | |
122 // ChromeVox tutorial URL (used in place of "getting started" url when | 125 // ChromeVox tutorial URL (used in place of "getting started" url when |
123 // accessibility is enabled). | 126 // accessibility is enabled). |
124 const char kChromeVoxTutorialURLPattern[] = | 127 const char kChromeVoxTutorialURLPattern[] = |
125 "http://www.chromevox.com/tutorial/index.html?lang=%s"; | 128 "http://www.chromevox.com/tutorial/index.html?lang=%s"; |
126 | 129 |
127 void InitLocaleAndInputMethodsForNewUser( | 130 void InitLocaleAndInputMethodsForNewUser( |
128 UserSessionManager* session_manager, | 131 UserSessionManager* session_manager, |
129 Profile* profile, | 132 Profile* profile, |
130 const std::string& public_session_locale, | 133 const std::string& public_session_locale, |
131 const std::string& public_session_input_method) { | 134 const std::string& public_session_input_method) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 | 209 |
207 // Save the preferred languages in the user's preferences. | 210 // Save the preferred languages in the user's preferences. |
208 prefs->SetString(prefs::kLanguagePreferredLanguages, | 211 prefs->SetString(prefs::kLanguagePreferredLanguages, |
209 base::JoinString(language_codes, ",")); | 212 base::JoinString(language_codes, ",")); |
210 | 213 |
211 // Indicate that we need to merge the syncable input methods when we sync, | 214 // Indicate that we need to merge the syncable input methods when we sync, |
212 // since we have not applied the synced prefs before. | 215 // since we have not applied the synced prefs before. |
213 prefs->SetBoolean(prefs::kLanguageShouldMergeInputMethods, true); | 216 prefs->SetBoolean(prefs::kLanguageShouldMergeInputMethods, true); |
214 } | 217 } |
215 | 218 |
219 // We want to show Goodies page the first time a new browser window is opened | |
220 // on a new Chromebook. kCanShowOobeGoodiesPage defaults to |true|; we set it | |
221 // to |false| (return |false|) for any device over kMaxDaysAfterOobeForGoodies | |
222 // days old, to avoid showing it after update on older devices. | |
223 static bool CheckGoodiesPrefAgainstOobeTimestamp() { | |
224 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | |
225 const base::FilePath oobe_timestamp_file = | |
226 StartupUtils::GetOobeCompleteFlagPath(); | |
227 base::File::Info fileInfo; | |
228 if (base::GetFileInfo(oobe_timestamp_file, &fileInfo)) { | |
229 base::TimeDelta time_since_oobe = | |
230 base::Time::Now() - fileInfo.creation_time; | |
231 if (time_since_oobe > | |
232 base::TimeDelta::FromDays(kMaxDaysAfterOobeForGoodies)) | |
233 return false; | |
234 } | |
235 return true; | |
236 } | |
237 | |
238 // Callback into main thread to set pref to |false| if too long since oobe. | |
239 static void UpdateGoodiesPrefCantShow(bool can_show_goodies) { | |
240 if (can_show_goodies) | |
241 return; | |
242 PrefService* prefs = g_browser_process->local_state(); | |
243 prefs->SetBoolean(prefs::kCanShowOobeGoodiesPage, false); | |
244 } | |
245 | |
216 #if defined(ENABLE_RLZ) | 246 #if defined(ENABLE_RLZ) |
217 // Flag file that disables RLZ tracking, when present. | 247 // Flag file that disables RLZ tracking, when present. |
218 const base::FilePath::CharType kRLZDisabledFlagName[] = | 248 const base::FilePath::CharType kRLZDisabledFlagName[] = |
219 FILE_PATH_LITERAL(".rlz_disabled"); | 249 FILE_PATH_LITERAL(".rlz_disabled"); |
220 | 250 |
221 base::FilePath GetRlzDisabledFlagPath() { | 251 base::FilePath GetRlzDisabledFlagPath() { |
222 base::FilePath homedir; | 252 base::FilePath homedir; |
223 PathService::Get(base::DIR_HOME, &homedir); | 253 PathService::Get(base::DIR_HOME, &homedir); |
224 return homedir.Append(kRLZDisabledFlagName); | 254 return homedir.Append(kRLZDisabledFlagName); |
225 } | 255 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 true /* path is absolute */, | 373 true /* path is absolute */, |
344 false /* don't create */); | 374 false /* don't create */); |
345 } | 375 } |
346 } | 376 } |
347 } | 377 } |
348 | 378 |
349 // static | 379 // static |
350 void UserSessionManager::RegisterPrefs(PrefRegistrySimple* registry) { | 380 void UserSessionManager::RegisterPrefs(PrefRegistrySimple* registry) { |
351 registry->RegisterStringPref(prefs::kRLZBrand, std::string()); | 381 registry->RegisterStringPref(prefs::kRLZBrand, std::string()); |
352 registry->RegisterBooleanPref(prefs::kRLZDisabled, false); | 382 registry->RegisterBooleanPref(prefs::kRLZDisabled, false); |
383 registry->RegisterBooleanPref(prefs::kCanShowOobeGoodiesPage, true); | |
353 } | 384 } |
354 | 385 |
355 UserSessionManager::UserSessionManager() | 386 UserSessionManager::UserSessionManager() |
356 : delegate_(nullptr), | 387 : delegate_(nullptr), |
357 authenticator_(nullptr), | 388 authenticator_(nullptr), |
358 has_auth_cookies_(false), | 389 has_auth_cookies_(false), |
359 user_sessions_restored_(false), | 390 user_sessions_restored_(false), |
360 user_sessions_restore_in_progress_(false), | 391 user_sessions_restore_in_progress_(false), |
361 exit_after_session_restore_(false), | 392 exit_after_session_restore_(false), |
362 session_restore_strategy_( | 393 session_restore_strategy_( |
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1130 profile, base::Bind(&UserSessionManager::OnTokenHandleObtained, | 1161 profile, base::Bind(&UserSessionManager::OnTokenHandleObtained, |
1131 weak_factory_.GetWeakPtr())); | 1162 weak_factory_.GetWeakPtr())); |
1132 } | 1163 } |
1133 } | 1164 } |
1134 } | 1165 } |
1135 | 1166 |
1136 // Now that profile is ready, proceed to either alternative login flows or | 1167 // Now that profile is ready, proceed to either alternative login flows or |
1137 // launch browser. | 1168 // launch browser. |
1138 bool browser_launched = InitializeUserSession(profile); | 1169 bool browser_launched = InitializeUserSession(profile); |
1139 | 1170 |
1171 CheckCanShowGoodiesPref(); | |
Greg Levin
2015/09/09 23:20:33
My choice to put this here was a little arbitrary.
| |
1172 | |
1140 // TODO(nkostylev): This pointer should probably never be NULL, but it looks | 1173 // TODO(nkostylev): This pointer should probably never be NULL, but it looks |
1141 // like OnProfileCreated() may be getting called before | 1174 // like OnProfileCreated() may be getting called before |
1142 // UserSessionManager::PrepareProfile() has set |delegate_| when Chrome is | 1175 // UserSessionManager::PrepareProfile() has set |delegate_| when Chrome is |
1143 // killed during shutdown in tests -- see http://crosbug.com/18269. Replace | 1176 // killed during shutdown in tests -- see http://crosbug.com/18269. Replace |
1144 // this 'if' statement with a CHECK(delegate_) once the underlying issue is | 1177 // this 'if' statement with a CHECK(delegate_) once the underlying issue is |
1145 // resolved. | 1178 // resolved. |
1146 if (delegate_) | 1179 if (delegate_) |
1147 delegate_->OnProfilePrepared(profile, browser_launched); | 1180 delegate_->OnProfilePrepared(profile, browser_launched); |
1148 } | 1181 } |
1149 | 1182 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1218 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
1186 ::switches::kSilentLaunch); | 1219 ::switches::kSilentLaunch); |
1187 first_run::MaybeLaunchDialogAfterSessionStart(); | 1220 first_run::MaybeLaunchDialogAfterSessionStart(); |
1188 } else { | 1221 } else { |
1189 for (size_t i = 0; i < start_urls.size(); ++i) { | 1222 for (size_t i = 0; i < start_urls.size(); ++i) { |
1190 base::CommandLine::ForCurrentProcess()->AppendArg(start_urls[i]); | 1223 base::CommandLine::ForCurrentProcess()->AppendArg(start_urls[i]); |
1191 } | 1224 } |
1192 } | 1225 } |
1193 } | 1226 } |
1194 | 1227 |
1228 void UserSessionManager::CheckCanShowGoodiesPref() { | |
1229 PrefService* prefs = g_browser_process->local_state(); | |
1230 bool can_show_goodies = prefs->GetBoolean(prefs::kCanShowOobeGoodiesPage); | |
1231 if (can_show_goodies) | |
1232 content::BrowserThread::PostTaskAndReplyWithResult( | |
1233 content::BrowserThread::FILE, FROM_HERE, | |
1234 base::Bind(&CheckGoodiesPrefAgainstOobeTimestamp), | |
1235 base::Bind(&UpdateGoodiesPrefCantShow)); | |
1236 } | |
1237 | |
1195 bool UserSessionManager::InitializeUserSession(Profile* profile) { | 1238 bool UserSessionManager::InitializeUserSession(Profile* profile) { |
1196 ChildAccountService* child_service = | 1239 ChildAccountService* child_service = |
1197 ChildAccountServiceFactory::GetForProfile(profile); | 1240 ChildAccountServiceFactory::GetForProfile(profile); |
1198 child_service->AddChildStatusReceivedCallback( | 1241 child_service->AddChildStatusReceivedCallback( |
1199 base::Bind(&UserSessionManager::ChildAccountStatusReceivedCallback, | 1242 base::Bind(&UserSessionManager::ChildAccountStatusReceivedCallback, |
1200 weak_factory_.GetWeakPtr(), profile)); | 1243 weak_factory_.GetWeakPtr(), profile)); |
1201 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1244 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1202 FROM_HERE, base::Bind(&UserSessionManager::StopChildStatusObserving, | 1245 FROM_HERE, base::Bind(&UserSessionManager::StopChildStatusObserving, |
1203 weak_factory_.GetWeakPtr(), profile), | 1246 weak_factory_.GetWeakPtr(), profile), |
1204 base::TimeDelta::FromMilliseconds(kFlagsFetchingLoginTimeoutMs)); | 1247 base::TimeDelta::FromMilliseconds(kFlagsFetchingLoginTimeoutMs)); |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1756 token_handle_util_.reset(); | 1799 token_handle_util_.reset(); |
1757 } | 1800 } |
1758 | 1801 |
1759 void UserSessionManager::CreateTokenUtilIfMissing() { | 1802 void UserSessionManager::CreateTokenUtilIfMissing() { |
1760 if (!token_handle_util_.get()) | 1803 if (!token_handle_util_.get()) |
1761 token_handle_util_.reset( | 1804 token_handle_util_.reset( |
1762 new TokenHandleUtil(user_manager::UserManager::Get())); | 1805 new TokenHandleUtil(user_manager::UserManager::Get())); |
1763 } | 1806 } |
1764 | 1807 |
1765 } // namespace chromeos | 1808 } // namespace chromeos |
OLD | NEW |