OLD | NEW |
---|---|
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/chromeos/login/login_utils.h" | 5 #include "chrome/browser/chromeos/login/login_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 bool has_cookies, | 137 bool has_cookies, |
138 bool has_active_session, | 138 bool has_active_session, |
139 LoginUtils::Delegate* delegate) OVERRIDE; | 139 LoginUtils::Delegate* delegate) OVERRIDE; |
140 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; | 140 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; |
141 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; | 141 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; |
142 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; | 142 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; |
143 virtual scoped_refptr<Authenticator> CreateAuthenticator( | 143 virtual scoped_refptr<Authenticator> CreateAuthenticator( |
144 LoginStatusConsumer* consumer) OVERRIDE; | 144 LoginStatusConsumer* consumer) OVERRIDE; |
145 virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE; | 145 virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE; |
146 virtual void InitRlzDelayed(Profile* user_profile) OVERRIDE; | 146 virtual void InitRlzDelayed(Profile* user_profile) OVERRIDE; |
147 virtual bool RestartToApplyPerSessionFlagsIfNeed(Profile* profile) OVERRIDE; | |
147 | 148 |
148 // OAuth2LoginManager::Observer overrides. | 149 // OAuth2LoginManager::Observer overrides. |
149 virtual void OnSessionRestoreStateChanged( | 150 virtual void OnSessionRestoreStateChanged( |
150 Profile* user_profile, | 151 Profile* user_profile, |
151 OAuth2LoginManager::SessionRestoreState state) OVERRIDE; | 152 OAuth2LoginManager::SessionRestoreState state) OVERRIDE; |
152 virtual void OnNewRefreshTokenAvaiable(Profile* user_profile) OVERRIDE; | 153 virtual void OnNewRefreshTokenAvaiable(Profile* user_profile) OVERRIDE; |
153 | 154 |
154 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. | 155 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. |
155 virtual void OnConnectionTypeChanged( | 156 virtual void OnConnectionTypeChanged( |
156 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 157 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 void RestoreAuthSession(Profile* user_profile, | 214 void RestoreAuthSession(Profile* user_profile, |
214 bool restore_from_auth_cookies); | 215 bool restore_from_auth_cookies); |
215 | 216 |
216 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled. | 217 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled. |
217 void InitRlz(Profile* user_profile, bool disabled); | 218 void InitRlz(Profile* user_profile, bool disabled); |
218 | 219 |
219 // Attempts restarting the browser process and esures that this does | 220 // Attempts restarting the browser process and esures that this does |
220 // not happen while we are still fetching new OAuth refresh tokens. | 221 // not happen while we are still fetching new OAuth refresh tokens. |
221 void AttemptRestart(Profile* profile); | 222 void AttemptRestart(Profile* profile); |
222 | 223 |
224 // Returns new CommandLine with per-user flags. | |
225 CommandLine CreatePerSessionCommandLine(Profile* profile); | |
226 | |
227 // Returns true if restart is needed to apply per-session flags. | |
228 bool NeedRestartToApplyPerSessionFlags(const CommandLine& user_flags); | |
229 | |
223 UserContext user_context_; | 230 UserContext user_context_; |
224 | 231 |
225 // True if the authentication profile's cookie jar should contain | 232 // True if the authentication profile's cookie jar should contain |
226 // authentication cookies from the authentication extension log in flow. | 233 // authentication cookies from the authentication extension log in flow. |
227 bool has_web_auth_cookies_; | 234 bool has_web_auth_cookies_; |
228 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). | 235 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). |
229 scoped_refptr<Authenticator> authenticator_; | 236 scoped_refptr<Authenticator> authenticator_; |
230 | 237 |
231 // Delegate to be fired when the profile will be prepared. | 238 // Delegate to be fired when the profile will be prepared. |
232 LoginUtils::Delegate* delegate_; | 239 LoginUtils::Delegate* delegate_; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 // DoBrowserLaunchOnLocaleLoaded() depending on | 311 // DoBrowserLaunchOnLocaleLoaded() depending on |
305 // if locale switch was needed. | 312 // if locale switch was needed. |
306 void LoginUtilsImpl::DoBrowserLaunchOnLocaleLoadedImpl( | 313 void LoginUtilsImpl::DoBrowserLaunchOnLocaleLoadedImpl( |
307 Profile* profile, | 314 Profile* profile, |
308 LoginDisplayHost* login_host) { | 315 LoginDisplayHost* login_host) { |
309 if (!UserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) { | 316 if (!UserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) { |
310 UserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile); | 317 UserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile); |
311 return; | 318 return; |
312 } | 319 } |
313 | 320 |
314 CommandLine user_flags(CommandLine::NO_PROGRAM); | 321 if (RestartToApplyPerSessionFlagsIfNeed(profile)) |
315 about_flags::PrefServiceFlagsStorage flags_storage_(profile->GetPrefs()); | |
316 about_flags::ConvertFlagsToSwitches(&flags_storage_, &user_flags, | |
317 about_flags::kAddSentinels); | |
318 // Only restart if needed and if not going into managed mode. | |
319 // Don't restart browser if it is not first profile in session. | |
320 if (UserManager::Get()->GetLoggedInUsers().size() == 1 && | |
321 !UserManager::Get()->IsLoggedInAsLocallyManagedUser() && | |
322 !about_flags::AreSwitchesIdenticalToCurrentCommandLine( | |
323 user_flags, *CommandLine::ForCurrentProcess())) { | |
324 CommandLine::StringVector flags; | |
325 // argv[0] is the program name |CommandLine::NO_PROGRAM|. | |
326 flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end()); | |
327 VLOG(1) << "Restarting to apply per-session flags..."; | |
328 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser( | |
329 UserManager::Get()->GetActiveUser()->email(), flags); | |
330 AttemptRestart(profile); | |
331 return; | 322 return; |
332 } | |
333 | 323 |
334 if (login_host) { | 324 if (login_host) { |
335 login_host->SetStatusAreaVisible(true); | 325 login_host->SetStatusAreaVisible(true); |
336 login_host->BeforeSessionStart(); | 326 login_host->BeforeSessionStart(); |
337 } | 327 } |
338 | 328 |
339 BootTimesLoader::Get()->AddLoginTimeMarker("BrowserLaunched", false); | 329 BootTimesLoader::Get()->AddLoginTimeMarker("BrowserLaunched", false); |
340 | 330 |
341 VLOG(1) << "Launching browser..."; | 331 VLOG(1) << "Launching browser..."; |
332 TRACE_EVENT0("login", "LaunchBrowser"); | |
342 StartupBrowserCreator browser_creator; | 333 StartupBrowserCreator browser_creator; |
343 int return_code; | 334 int return_code; |
344 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? | 335 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? |
345 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | 336 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; |
346 | 337 |
347 browser_creator.LaunchBrowser(*CommandLine::ForCurrentProcess(), | 338 browser_creator.LaunchBrowser(*CommandLine::ForCurrentProcess(), |
348 profile, | 339 profile, |
349 base::FilePath(), | 340 base::FilePath(), |
350 chrome::startup::IS_PROCESS_STARTUP, | 341 chrome::startup::IS_PROCESS_STARTUP, |
351 first_run, | 342 first_run, |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 return; | 669 return; |
679 } | 670 } |
680 base::PostTaskAndReplyWithResult( | 671 base::PostTaskAndReplyWithResult( |
681 base::WorkerPool::GetTaskRunner(false), | 672 base::WorkerPool::GetTaskRunner(false), |
682 FROM_HERE, | 673 FROM_HERE, |
683 base::Bind(&base::PathExists, GetRlzDisabledFlagPath()), | 674 base::Bind(&base::PathExists, GetRlzDisabledFlagPath()), |
684 base::Bind(&LoginUtilsImpl::InitRlz, AsWeakPtr(), user_profile)); | 675 base::Bind(&LoginUtilsImpl::InitRlz, AsWeakPtr(), user_profile)); |
685 #endif | 676 #endif |
686 } | 677 } |
687 | 678 |
679 bool LoginUtilsImpl::RestartToApplyPerSessionFlagsIfNeed(Profile* profile) { | |
Nikita (slow)
2014/06/10 14:21:00
nit: Move this to unnamed namespace.
Alexander Alekseev
2014/06/10 22:05:13
It's called from profile_impl.cc .
I've moved it
Nikita (slow)
2014/06/11 12:42:51
Sorry, since this one is called from ProfileImpl y
Alexander Alekseev
2014/06/11 15:15:50
Done.
| |
680 const CommandLine user_flags(CreatePerSessionCommandLine(profile)); | |
681 if (!NeedRestartToApplyPerSessionFlags(user_flags)) | |
682 return false; | |
683 | |
684 CommandLine::StringVector flags; | |
685 // argv[0] is the program name |CommandLine::NO_PROGRAM|. | |
686 flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end()); | |
687 VLOG(1) << "Restarting to apply per-session flags..."; | |
688 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser( | |
689 UserManager::Get()->GetActiveUser()->email(), flags); | |
690 AttemptRestart(profile); | |
691 return true; | |
692 } | |
693 | |
688 void LoginUtilsImpl::InitRlz(Profile* user_profile, bool disabled) { | 694 void LoginUtilsImpl::InitRlz(Profile* user_profile, bool disabled) { |
689 #if defined(ENABLE_RLZ) | 695 #if defined(ENABLE_RLZ) |
690 PrefService* local_state = g_browser_process->local_state(); | 696 PrefService* local_state = g_browser_process->local_state(); |
691 if (disabled) { | 697 if (disabled) { |
692 // Empty brand code means an organic install (no RLZ pings are sent). | 698 // Empty brand code means an organic install (no RLZ pings are sent). |
693 google_util::chromeos::ClearBrandForCurrentSession(); | 699 google_util::chromeos::ClearBrandForCurrentSession(); |
694 } | 700 } |
695 if (disabled != local_state->GetBoolean(prefs::kRLZDisabled)) { | 701 if (disabled != local_state->GetBoolean(prefs::kRLZDisabled)) { |
696 // When switching to RLZ enabled/disabled state, clear all recorded events. | 702 // When switching to RLZ enabled/disabled state, clear all recorded events. |
697 RLZTracker::ClearRlzState(); | 703 RLZTracker::ClearRlzState(); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
916 login_manager->state() != | 922 login_manager->state() != |
917 OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS) { | 923 OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS) { |
918 chrome::AttemptRestart(); | 924 chrome::AttemptRestart(); |
919 return; | 925 return; |
920 } | 926 } |
921 | 927 |
922 LOG(WARNING) << "Attempting browser restart during session restore."; | 928 LOG(WARNING) << "Attempting browser restart during session restore."; |
923 exit_after_session_restore_ = true; | 929 exit_after_session_restore_ = true; |
924 } | 930 } |
925 | 931 |
932 CommandLine LoginUtilsImpl::CreatePerSessionCommandLine(Profile* profile) { | |
Nikita (slow)
2014/06/10 14:21:00
nit: Please move to unnamed namespace.
| |
933 CommandLine user_flags(CommandLine::NO_PROGRAM); | |
934 about_flags::PrefServiceFlagsStorage flags_storage_(profile->GetPrefs()); | |
935 about_flags::ConvertFlagsToSwitches( | |
936 &flags_storage_, &user_flags, about_flags::kAddSentinels); | |
937 return user_flags; | |
938 } | |
939 | |
940 bool LoginUtilsImpl::NeedRestartToApplyPerSessionFlags( | |
Nikita (slow)
2014/06/10 14:21:00
nit: Same here.
| |
941 const CommandLine& user_flags) { | |
942 // Don't restart browser if it is not first profile in session. | |
943 if (UserManager::Get()->GetLoggedInUsers().size() != 1) | |
944 return false; | |
945 | |
946 // Only restart if needed and if not going into managed mode. | |
947 if (UserManager::Get()->IsLoggedInAsLocallyManagedUser()) | |
948 return false; | |
949 | |
950 if (about_flags::AreSwitchesIdenticalToCurrentCommandLine( | |
Nikita (slow)
2014/06/10 14:21:00
nit: rewrite this as
return !about_flags::AreSwi
| |
951 user_flags, *CommandLine::ForCurrentProcess())) { | |
952 return false; | |
953 } | |
954 | |
955 return true; | |
956 } | |
957 | |
926 // static | 958 // static |
927 void LoginUtils::RegisterPrefs(PrefRegistrySimple* registry) { | 959 void LoginUtils::RegisterPrefs(PrefRegistrySimple* registry) { |
928 registry->RegisterBooleanPref(prefs::kFactoryResetRequested, false); | 960 registry->RegisterBooleanPref(prefs::kFactoryResetRequested, false); |
929 registry->RegisterBooleanPref(prefs::kRollbackRequested, false); | 961 registry->RegisterBooleanPref(prefs::kRollbackRequested, false); |
930 registry->RegisterStringPref(prefs::kRLZBrand, std::string()); | 962 registry->RegisterStringPref(prefs::kRLZBrand, std::string()); |
931 registry->RegisterBooleanPref(prefs::kRLZDisabled, false); | 963 registry->RegisterBooleanPref(prefs::kRLZDisabled, false); |
932 } | 964 } |
933 | 965 |
934 // static | 966 // static |
935 LoginUtils* LoginUtils::Get() { | 967 LoginUtils* LoginUtils::Get() { |
(...skipping 17 matching lines...) Expand all Loading... | |
953 CrosSettings* cros_settings = CrosSettings::Get(); | 985 CrosSettings* cros_settings = CrosSettings::Get(); |
954 bool allow_new_user = false; | 986 bool allow_new_user = false; |
955 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 987 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
956 if (allow_new_user) | 988 if (allow_new_user) |
957 return true; | 989 return true; |
958 return cros_settings->FindEmailInList( | 990 return cros_settings->FindEmailInList( |
959 kAccountsPrefUsers, username, wildcard_match); | 991 kAccountsPrefUsers, username, wildcard_match); |
960 } | 992 } |
961 | 993 |
962 } // namespace chromeos | 994 } // namespace chromeos |
OLD | NEW |