Chromium Code Reviews| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 const base::FilePath::CharType kRLZDisabledFlagName[] = | 98 const base::FilePath::CharType kRLZDisabledFlagName[] = |
| 99 FILE_PATH_LITERAL(".rlz_disabled"); | 99 FILE_PATH_LITERAL(".rlz_disabled"); |
| 100 | 100 |
| 101 base::FilePath GetRlzDisabledFlagPath() { | 101 base::FilePath GetRlzDisabledFlagPath() { |
| 102 base::FilePath homedir; | 102 base::FilePath homedir; |
| 103 PathService::Get(base::DIR_HOME, &homedir); | 103 PathService::Get(base::DIR_HOME, &homedir); |
| 104 return homedir.Append(kRLZDisabledFlagName); | 104 return homedir.Append(kRLZDisabledFlagName); |
| 105 } | 105 } |
| 106 #endif | 106 #endif |
| 107 | 107 |
| 108 CommandLine CreatePerSessionCommandLine(Profile* profile) { | |
| 109 CommandLine user_flags(CommandLine::NO_PROGRAM); | |
| 110 about_flags::PrefServiceFlagsStorage flags_storage_(profile->GetPrefs()); | |
| 111 about_flags::ConvertFlagsToSwitches( | |
| 112 &flags_storage_, &user_flags, about_flags::kAddSentinels); | |
| 113 return user_flags; | |
| 114 } | |
| 115 | |
| 116 bool NeedRestartToApplyPerSessionFlags(const CommandLine& user_flags) { | |
| 117 // Don't restart browser if it is not first profile in session. | |
| 118 if (UserManager::Get()->GetLoggedInUsers().size() != 1) | |
| 119 return false; | |
| 120 | |
| 121 // Only restart if needed and if not going into managed mode. | |
| 122 if (UserManager::Get()->IsLoggedInAsLocallyManagedUser()) | |
| 123 return false; | |
| 124 | |
| 125 if (about_flags::AreSwitchesIdenticalToCurrentCommandLine( | |
| 126 user_flags, *CommandLine::ForCurrentProcess())) { | |
| 127 return false; | |
| 128 } | |
| 129 | |
| 130 return true; | |
| 131 } | |
| 132 | |
| 108 } // namespace | 133 } // namespace |
| 109 | 134 |
| 110 struct DoBrowserLaunchOnLocaleLoadedData; | 135 struct DoBrowserLaunchOnLocaleLoadedData; |
| 111 | 136 |
| 112 class LoginUtilsImpl | 137 class LoginUtilsImpl |
| 113 : public LoginUtils, | 138 : public LoginUtils, |
| 114 public OAuth2LoginManager::Observer, | 139 public OAuth2LoginManager::Observer, |
| 115 public net::NetworkChangeNotifier::ConnectionTypeObserver, | 140 public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| 116 public base::SupportsWeakPtr<LoginUtilsImpl> { | 141 public base::SupportsWeakPtr<LoginUtilsImpl> { |
| 117 public: | 142 public: |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 148 // OAuth2LoginManager::Observer overrides. | 173 // OAuth2LoginManager::Observer overrides. |
| 149 virtual void OnSessionRestoreStateChanged( | 174 virtual void OnSessionRestoreStateChanged( |
| 150 Profile* user_profile, | 175 Profile* user_profile, |
| 151 OAuth2LoginManager::SessionRestoreState state) OVERRIDE; | 176 OAuth2LoginManager::SessionRestoreState state) OVERRIDE; |
| 152 virtual void OnNewRefreshTokenAvaiable(Profile* user_profile) OVERRIDE; | 177 virtual void OnNewRefreshTokenAvaiable(Profile* user_profile) OVERRIDE; |
| 153 | 178 |
| 154 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. | 179 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. |
| 155 virtual void OnConnectionTypeChanged( | 180 virtual void OnConnectionTypeChanged( |
| 156 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 181 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 157 | 182 |
| 183 // Attempts restarting the browser process and esures that this does | |
| 184 // not happen while we are still fetching new OAuth refresh tokens. | |
| 185 void AttemptRestart(Profile* profile); | |
| 186 | |
| 158 private: | 187 private: |
| 159 typedef std::set<std::string> SessionRestoreStateSet; | 188 typedef std::set<std::string> SessionRestoreStateSet; |
| 160 | 189 |
| 161 // DoBrowserLaunch is split into two parts. | 190 // DoBrowserLaunch is split into two parts. |
| 162 // This one is called after anynchronous locale switch. | 191 // This one is called after anynchronous locale switch. |
| 163 void DoBrowserLaunchOnLocaleLoadedImpl(Profile* profile, | 192 void DoBrowserLaunchOnLocaleLoadedImpl(Profile* profile, |
| 164 LoginDisplayHost* login_host); | 193 LoginDisplayHost* login_host); |
| 165 | 194 |
| 166 // Callback for locale_util::SwitchLanguage(). | 195 // Callback for locale_util::SwitchLanguage(). |
| 167 static void DoBrowserLaunchOnLocaleLoaded( | 196 static void DoBrowserLaunchOnLocaleLoaded( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 // OAuthLoginManager. | 238 // OAuthLoginManager. |
| 210 void InitSessionRestoreStrategy(); | 239 void InitSessionRestoreStrategy(); |
| 211 | 240 |
| 212 // Restores GAIA auth cookies for the created user profile from OAuth2 token. | 241 // Restores GAIA auth cookies for the created user profile from OAuth2 token. |
| 213 void RestoreAuthSession(Profile* user_profile, | 242 void RestoreAuthSession(Profile* user_profile, |
| 214 bool restore_from_auth_cookies); | 243 bool restore_from_auth_cookies); |
| 215 | 244 |
| 216 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled. | 245 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled. |
| 217 void InitRlz(Profile* user_profile, bool disabled); | 246 void InitRlz(Profile* user_profile, bool disabled); |
| 218 | 247 |
| 219 // Attempts restarting the browser process and esures that this does | |
| 220 // not happen while we are still fetching new OAuth refresh tokens. | |
| 221 void AttemptRestart(Profile* profile); | |
| 222 | |
| 223 UserContext user_context_; | 248 UserContext user_context_; |
| 224 | 249 |
| 225 // True if the authentication profile's cookie jar should contain | 250 // True if the authentication profile's cookie jar should contain |
| 226 // authentication cookies from the authentication extension log in flow. | 251 // authentication cookies from the authentication extension log in flow. |
| 227 bool has_web_auth_cookies_; | 252 bool has_web_auth_cookies_; |
| 228 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). | 253 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). |
| 229 scoped_refptr<Authenticator> authenticator_; | 254 scoped_refptr<Authenticator> authenticator_; |
| 230 | 255 |
| 231 // Delegate to be fired when the profile will be prepared. | 256 // Delegate to be fired when the profile will be prepared. |
| 232 LoginUtils::Delegate* delegate_; | 257 LoginUtils::Delegate* delegate_; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 // DoBrowserLaunchOnLocaleLoaded() depending on | 329 // DoBrowserLaunchOnLocaleLoaded() depending on |
| 305 // if locale switch was needed. | 330 // if locale switch was needed. |
| 306 void LoginUtilsImpl::DoBrowserLaunchOnLocaleLoadedImpl( | 331 void LoginUtilsImpl::DoBrowserLaunchOnLocaleLoadedImpl( |
| 307 Profile* profile, | 332 Profile* profile, |
| 308 LoginDisplayHost* login_host) { | 333 LoginDisplayHost* login_host) { |
| 309 if (!UserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) { | 334 if (!UserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) { |
| 310 UserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile); | 335 UserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile); |
| 311 return; | 336 return; |
| 312 } | 337 } |
| 313 | 338 |
| 314 CommandLine user_flags(CommandLine::NO_PROGRAM); | 339 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; | 340 return; |
| 332 } | |
| 333 | 341 |
| 334 if (login_host) { | 342 if (login_host) { |
| 335 login_host->SetStatusAreaVisible(true); | 343 login_host->SetStatusAreaVisible(true); |
| 336 login_host->BeforeSessionStart(); | 344 login_host->BeforeSessionStart(); |
| 337 } | 345 } |
| 338 | 346 |
| 339 BootTimesLoader::Get()->AddLoginTimeMarker("BrowserLaunched", false); | 347 BootTimesLoader::Get()->AddLoginTimeMarker("BrowserLaunched", false); |
| 340 | 348 |
| 341 VLOG(1) << "Launching browser..."; | 349 VLOG(1) << "Launching browser..."; |
| 350 TRACE_EVENT0("login", "LaunchBrowser"); | |
| 342 StartupBrowserCreator browser_creator; | 351 StartupBrowserCreator browser_creator; |
| 343 int return_code; | 352 int return_code; |
| 344 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? | 353 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? |
| 345 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | 354 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; |
| 346 | 355 |
| 347 browser_creator.LaunchBrowser(*CommandLine::ForCurrentProcess(), | 356 browser_creator.LaunchBrowser(*CommandLine::ForCurrentProcess(), |
| 348 profile, | 357 profile, |
| 349 base::FilePath(), | 358 base::FilePath(), |
| 350 chrome::startup::IS_PROCESS_STARTUP, | 359 chrome::startup::IS_PROCESS_STARTUP, |
| 351 first_run, | 360 first_run, |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 952 | 961 |
| 953 CrosSettings* cros_settings = CrosSettings::Get(); | 962 CrosSettings* cros_settings = CrosSettings::Get(); |
| 954 bool allow_new_user = false; | 963 bool allow_new_user = false; |
| 955 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 964 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
| 956 if (allow_new_user) | 965 if (allow_new_user) |
| 957 return true; | 966 return true; |
| 958 return cros_settings->FindEmailInList( | 967 return cros_settings->FindEmailInList( |
| 959 kAccountsPrefUsers, username, wildcard_match); | 968 kAccountsPrefUsers, username, wildcard_match); |
| 960 } | 969 } |
| 961 | 970 |
| 971 bool RestartToApplyPerSessionFlagsIfNeed(Profile* profile) { | |
| 972 const CommandLine user_flags(CreatePerSessionCommandLine(profile)); | |
| 973 if (!NeedRestartToApplyPerSessionFlags(user_flags)) | |
| 974 return false; | |
| 975 | |
| 976 CommandLine::StringVector flags; | |
| 977 // argv[0] is the program name |CommandLine::NO_PROGRAM|. | |
| 978 flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end()); | |
| 979 VLOG(1) << "Restarting to apply per-session flags..."; | |
| 980 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser( | |
| 981 UserManager::Get()->GetActiveUser()->email(), flags); | |
| 982 static_cast<LoginUtilsImpl*>(LoginUtilsImpl::Get())->AttemptRestart(profile); | |
|
Alexander Alekseev
2014/06/10 22:05:13
Need a way to call LoginUtilsImpl method here.
Sta
| |
| 983 return true; | |
| 984 } | |
| 985 | |
| 962 } // namespace chromeos | 986 } // namespace chromeos |
| OLD | NEW |