| 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/chromeos/chromeos_version.h" | 10 #include "base/chromeos/chromeos_version.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "base/threading/worker_pool.h" | 28 #include "base/threading/worker_pool.h" |
| 29 #include "base/time/time.h" | 29 #include "base/time/time.h" |
| 30 #include "chrome/browser/about_flags.h" | 30 #include "chrome/browser/about_flags.h" |
| 31 #include "chrome/browser/app_mode/app_mode_utils.h" | 31 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 32 #include "chrome/browser/browser_process.h" | 32 #include "chrome/browser/browser_process.h" |
| 33 #include "chrome/browser/browser_shutdown.h" | 33 #include "chrome/browser/browser_shutdown.h" |
| 34 #include "chrome/browser/chrome_notification_types.h" | 34 #include "chrome/browser/chrome_notification_types.h" |
| 35 #include "chrome/browser/chromeos/boot_times_loader.h" | 35 #include "chrome/browser/chromeos/boot_times_loader.h" |
| 36 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 36 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 37 #include "chrome/browser/chromeos/login/chrome_restart_request.h" | 37 #include "chrome/browser/chromeos/login/chrome_restart_request.h" |
| 38 #include "chrome/browser/chromeos/login/language_switch_menu.h" | |
| 39 #include "chrome/browser/chromeos/login/login_display_host.h" | 38 #include "chrome/browser/chromeos/login/login_display_host.h" |
| 40 #include "chrome/browser/chromeos/login/oauth2_login_manager.h" | 39 #include "chrome/browser/chromeos/login/oauth2_login_manager.h" |
| 41 #include "chrome/browser/chromeos/login/oauth2_login_manager_factory.h" | 40 #include "chrome/browser/chromeos/login/oauth2_login_manager_factory.h" |
| 42 #include "chrome/browser/chromeos/login/parallel_authenticator.h" | 41 #include "chrome/browser/chromeos/login/parallel_authenticator.h" |
| 43 #include "chrome/browser/chromeos/login/profile_auth_data.h" | 42 #include "chrome/browser/chromeos/login/profile_auth_data.h" |
| 44 #include "chrome/browser/chromeos/login/screen_locker.h" | 43 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 45 #include "chrome/browser/chromeos/login/user_manager.h" | 44 #include "chrome/browser/chromeos/login/user_manager.h" |
| 46 #include "chrome/browser/chromeos/settings/cros_settings.h" | 45 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 47 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 46 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 48 #include "chrome/browser/extensions/extension_service.h" | 47 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 virtual void OnSessionAuthenticated(Profile* user_profile) OVERRIDE; | 139 virtual void OnSessionAuthenticated(Profile* user_profile) OVERRIDE; |
| 141 | 140 |
| 142 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. | 141 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. |
| 143 virtual void OnConnectionTypeChanged( | 142 virtual void OnConnectionTypeChanged( |
| 144 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 143 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 145 | 144 |
| 146 private: | 145 private: |
| 147 // Restarts OAuth session authentication check. | 146 // Restarts OAuth session authentication check. |
| 148 void KickStartAuthentication(Profile* profile); | 147 void KickStartAuthentication(Profile* profile); |
| 149 | 148 |
| 150 // Check user's profile for kApplicationLocale setting. | |
| 151 void RespectLocalePreference(Profile* pref); | |
| 152 | |
| 153 // Callback for Profile::CREATE_STATUS_CREATED profile state. | 149 // Callback for Profile::CREATE_STATUS_CREATED profile state. |
| 154 // Initializes basic preferences for newly created profile. Any other | 150 // Initializes basic preferences for newly created profile. Any other |
| 155 // early profile initialization that needs to happen before | 151 // early profile initialization that needs to happen before |
| 156 // ProfileManager::DoFinalInit() gets called is done here. | 152 // ProfileManager::DoFinalInit() gets called is done here. |
| 157 void InitProfilePreferences(Profile* user_profile, | 153 void InitProfilePreferences(Profile* user_profile, |
| 158 const std::string& email); | 154 const std::string& email); |
| 159 | 155 |
| 160 // Callback for asynchronous profile creation. | 156 // Callback for asynchronous profile creation. |
| 161 void OnProfileCreated(const std::string& email, | 157 void OnProfileCreated(const std::string& email, |
| 162 Profile* profile, | 158 Profile* profile, |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 } else { | 367 } else { |
| 372 // Make sure that the google service username is properly set (we do this | 368 // Make sure that the google service username is properly set (we do this |
| 373 // on every sign in, not just the first login, to deal with existing | 369 // on every sign in, not just the first login, to deal with existing |
| 374 // profiles that might not have it set yet). | 370 // profiles that might not have it set yet). |
| 375 StringPrefMember google_services_username; | 371 StringPrefMember google_services_username; |
| 376 google_services_username.Init(prefs::kGoogleServicesUsername, | 372 google_services_username.Init(prefs::kGoogleServicesUsername, |
| 377 user_profile->GetPrefs()); | 373 user_profile->GetPrefs()); |
| 378 const User* user = UserManager::Get()->FindUser(email); | 374 const User* user = UserManager::Get()->FindUser(email); |
| 379 google_services_username.SetValue(user ? user->display_email() : email); | 375 google_services_username.SetValue(user ? user->display_email() : email); |
| 380 } | 376 } |
| 381 | |
| 382 // For multi-profile case don't apply profile local because it is not safe. | |
| 383 if (UserManager::Get()->GetLoggedInUsers().size() == 1) | |
| 384 RespectLocalePreference(user_profile); | |
| 385 } | 377 } |
| 386 | 378 |
| 387 void LoginUtilsImpl::InitSessionRestoreStrategy() { | 379 void LoginUtilsImpl::InitSessionRestoreStrategy() { |
| 388 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 380 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 389 bool in_app_mode = chrome::IsRunningInForcedAppMode(); | 381 bool in_app_mode = chrome::IsRunningInForcedAppMode(); |
| 390 | 382 |
| 391 // Are we in kiosk app mode? | 383 // Are we in kiosk app mode? |
| 392 if (in_app_mode) { | 384 if (in_app_mode) { |
| 393 if (command_line->HasSwitch(::switches::kAppModeOAuth2Token)) { | 385 if (command_line->HasSwitch(::switches::kAppModeOAuth2Token)) { |
| 394 oauth2_refresh_token_ = command_line->GetSwitchValueASCII( | 386 oauth2_refresh_token_ = command_line->GetSwitchValueASCII( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 424 } | 416 } |
| 425 | 417 |
| 426 | 418 |
| 427 void LoginUtilsImpl::OnProfileCreated( | 419 void LoginUtilsImpl::OnProfileCreated( |
| 428 const std::string& email, | 420 const std::string& email, |
| 429 Profile* user_profile, | 421 Profile* user_profile, |
| 430 Profile::CreateStatus status) { | 422 Profile::CreateStatus status) { |
| 431 CHECK(user_profile); | 423 CHECK(user_profile); |
| 432 | 424 |
| 433 switch (status) { | 425 switch (status) { |
| 426 case Profile::CREATE_STATUS_CREATED: |
| 427 InitProfilePreferences(user_profile, email); |
| 428 break; |
| 434 case Profile::CREATE_STATUS_INITIALIZED: | 429 case Profile::CREATE_STATUS_INITIALIZED: |
| 435 UserProfileInitialized(user_profile); | 430 UserProfileInitialized(user_profile); |
| 436 break; | 431 break; |
| 437 case Profile::CREATE_STATUS_CREATED: | |
| 438 InitProfilePreferences(user_profile, email); | |
| 439 break; | |
| 440 case Profile::CREATE_STATUS_LOCAL_FAIL: | 432 case Profile::CREATE_STATUS_LOCAL_FAIL: |
| 441 case Profile::CREATE_STATUS_REMOTE_FAIL: | 433 case Profile::CREATE_STATUS_REMOTE_FAIL: |
| 442 case Profile::CREATE_STATUS_CANCELED: | 434 case Profile::CREATE_STATUS_CANCELED: |
| 443 case Profile::MAX_CREATE_STATUS: | 435 case Profile::MAX_CREATE_STATUS: |
| 444 NOTREACHED(); | 436 NOTREACHED(); |
| 445 break; | 437 break; |
| 446 } | 438 } |
| 447 } | 439 } |
| 448 | 440 |
| 449 void LoginUtilsImpl::UserProfileInitialized(Profile* user_profile) { | 441 void LoginUtilsImpl::UserProfileInitialized(Profile* user_profile) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 content::NotificationService::current()->Notify( | 597 content::NotificationService::current()->Notify( |
| 606 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | 598 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
| 607 content::Source<Profile>(user_profile), | 599 content::Source<Profile>(user_profile), |
| 608 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); | 600 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); |
| 609 } | 601 } |
| 610 } | 602 } |
| 611 user_context_.password.clear(); | 603 user_context_.password.clear(); |
| 612 user_context_.auth_code.clear(); | 604 user_context_.auth_code.clear(); |
| 613 } | 605 } |
| 614 | 606 |
| 615 void LoginUtilsImpl::RespectLocalePreference(Profile* profile) { | |
| 616 DCHECK(profile != NULL); | |
| 617 PrefService* prefs = profile->GetPrefs(); | |
| 618 DCHECK(prefs != NULL); | |
| 619 if (g_browser_process == NULL) | |
| 620 return; | |
| 621 | |
| 622 std::string pref_locale = prefs->GetString(prefs::kApplicationLocale); | |
| 623 if (pref_locale.empty()) | |
| 624 pref_locale = prefs->GetString(prefs::kApplicationLocaleBackup); | |
| 625 if (pref_locale.empty()) | |
| 626 pref_locale = g_browser_process->GetApplicationLocale(); | |
| 627 DCHECK(!pref_locale.empty()); | |
| 628 profile->ChangeAppLocale(pref_locale, Profile::APP_LOCALE_CHANGED_VIA_LOGIN); | |
| 629 // Here we don't enable keyboard layouts. Input methods are set up when | |
| 630 // the user first logs in. Then the user may customize the input methods. | |
| 631 // Hence changing input methods here, just because the user's UI language | |
| 632 // is different from the login screen UI language, is not desirable. Note | |
| 633 // that input method preferences are synced, so users can use their | |
| 634 // farovite input methods as soon as the preferences are synced. | |
| 635 LanguageSwitchMenu::SwitchLanguage(pref_locale); | |
| 636 } | |
| 637 | |
| 638 void LoginUtilsImpl::CompleteOffTheRecordLogin(const GURL& start_url) { | 607 void LoginUtilsImpl::CompleteOffTheRecordLogin(const GURL& start_url) { |
| 639 VLOG(1) << "Completing incognito login"; | 608 VLOG(1) << "Completing incognito login"; |
| 640 | 609 |
| 641 // For guest session we ask session manager to restart Chrome with --bwsi | 610 // For guest session we ask session manager to restart Chrome with --bwsi |
| 642 // flag. We keep only some of the arguments of this process. | 611 // flag. We keep only some of the arguments of this process. |
| 643 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 612 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 644 CommandLine command_line(browser_command_line.GetProgram()); | 613 CommandLine command_line(browser_command_line.GetProgram()); |
| 645 std::string cmd_line_str = GetOffTheRecordCommandLine(start_url, | 614 std::string cmd_line_str = GetOffTheRecordCommandLine(start_url, |
| 646 browser_command_line, | 615 browser_command_line, |
| 647 &command_line); | 616 &command_line); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 bool LoginUtils::IsWhitelisted(const std::string& username) { | 776 bool LoginUtils::IsWhitelisted(const std::string& username) { |
| 808 CrosSettings* cros_settings = CrosSettings::Get(); | 777 CrosSettings* cros_settings = CrosSettings::Get(); |
| 809 bool allow_new_user = false; | 778 bool allow_new_user = false; |
| 810 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 779 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
| 811 if (allow_new_user) | 780 if (allow_new_user) |
| 812 return true; | 781 return true; |
| 813 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); | 782 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); |
| 814 } | 783 } |
| 815 | 784 |
| 816 } // namespace chromeos | 785 } // namespace chromeos |
| OLD | NEW |