| 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/existing_user_controller.h" | 5 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/stringprintf.h" | |
| 20 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/values.h" | 20 #include "base/values.h" |
| 22 #include "base/version.h" | 21 #include "base/version.h" |
| 23 #include "chrome/browser/accessibility/accessibility_events.h" | 22 #include "chrome/browser/accessibility/accessibility_events.h" |
| 24 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/browser_process_platform_part.h" | 24 #include "chrome/browser/browser_process_platform_part.h" |
| 26 #include "chrome/browser/chrome_notification_types.h" | 25 #include "chrome/browser/chrome_notification_types.h" |
| 27 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | |
| 28 #include "chrome/browser/chromeos/boot_times_loader.h" | 26 #include "chrome/browser/chromeos/boot_times_loader.h" |
| 29 #include "chrome/browser/chromeos/customization_document.h" | 27 #include "chrome/browser/chromeos/customization_document.h" |
| 30 #include "chrome/browser/chromeos/first_run/first_run.h" | |
| 31 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" | 28 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" |
| 32 #include "chrome/browser/chromeos/login/helper.h" | 29 #include "chrome/browser/chromeos/login/helper.h" |
| 33 #include "chrome/browser/chromeos/login/login_utils.h" | 30 #include "chrome/browser/chromeos/login/login_utils.h" |
| 34 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | 31 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
| 35 #include "chrome/browser/chromeos/login/startup_utils.h" | 32 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 36 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 33 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 37 #include "chrome/browser/chromeos/login/user_flow.h" | 34 #include "chrome/browser/chromeos/login/user_flow.h" |
| 38 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 35 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 39 #include "chrome/browser/chromeos/login/wizard_controller.h" | 36 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 40 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 37 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 41 #include "chrome/browser/chromeos/policy/device_local_account.h" | 38 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 42 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | 39 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
| 43 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 40 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 44 #include "chrome/browser/chromeos/settings/cros_settings.h" | 41 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 45 #include "chrome/browser/prefs/session_startup_pref.h" | |
| 46 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" | 42 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" |
| 47 #include "chrome/common/chrome_switches.h" | 43 #include "chrome/common/chrome_switches.h" |
| 48 #include "chrome/common/chrome_version_info.h" | 44 #include "chrome/common/chrome_version_info.h" |
| 49 #include "chrome/common/pref_names.h" | 45 #include "chrome/common/pref_names.h" |
| 50 #include "chrome/common/url_constants.h" | 46 #include "chrome/common/url_constants.h" |
| 51 #include "chrome/grit/generated_resources.h" | 47 #include "chrome/grit/generated_resources.h" |
| 52 #include "chromeos/chromeos_switches.h" | 48 #include "chromeos/chromeos_switches.h" |
| 53 #include "chromeos/dbus/dbus_thread_manager.h" | 49 #include "chromeos/dbus/dbus_thread_manager.h" |
| 54 #include "chromeos/dbus/power_manager_client.h" | 50 #include "chromeos/dbus/power_manager_client.h" |
| 55 #include "chromeos/dbus/session_manager_client.h" | 51 #include "chromeos/dbus/session_manager_client.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 81 #include "ui/views/widget/widget.h" | 77 #include "ui/views/widget/widget.h" |
| 82 | 78 |
| 83 namespace chromeos { | 79 namespace chromeos { |
| 84 | 80 |
| 85 namespace { | 81 namespace { |
| 86 | 82 |
| 87 // URL for account creation. | 83 // URL for account creation. |
| 88 const char kCreateAccountURL[] = | 84 const char kCreateAccountURL[] = |
| 89 "https://accounts.google.com/NewAccount?service=mail"; | 85 "https://accounts.google.com/NewAccount?service=mail"; |
| 90 | 86 |
| 91 // ChromeVox tutorial URL (used in place of "getting started" url when | |
| 92 // accessibility is enabled). | |
| 93 const char kChromeVoxTutorialURLPattern[] = | |
| 94 "http://www.chromevox.com/tutorial/index.html?lang=%s"; | |
| 95 | |
| 96 // Delay for transferring the auth cache to the system profile. | 87 // Delay for transferring the auth cache to the system profile. |
| 97 const long int kAuthCacheTransferDelayMs = 2000; | 88 const long int kAuthCacheTransferDelayMs = 2000; |
| 98 | 89 |
| 99 // Delay for restarting the ui if safe-mode login has failed. | 90 // Delay for restarting the ui if safe-mode login has failed. |
| 100 const long int kSafeModeRestartUiDelayMs = 30000; | 91 const long int kSafeModeRestartUiDelayMs = 30000; |
| 101 | 92 |
| 102 // Makes a call to the policy subsystem to reload the policy when we detect | 93 // Makes a call to the policy subsystem to reload the policy when we detect |
| 103 // authentication change. | 94 // authentication change. |
| 104 void RefreshPoliciesOnUIThread() { | 95 void RefreshPoliciesOnUIThread() { |
| 105 if (g_browser_process->policy_service()) | 96 if (g_browser_process->policy_service()) |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 offline_failed_ = false; | 431 offline_failed_ = false; |
| 441 online_succeeded_for_.clear(); | 432 online_succeeded_for_.clear(); |
| 442 } | 433 } |
| 443 num_login_attempts_++; | 434 num_login_attempts_++; |
| 444 PerformLogin(user_context, LoginPerformer::AUTH_MODE_INTERNAL); | 435 PerformLogin(user_context, LoginPerformer::AUTH_MODE_INTERNAL); |
| 445 } | 436 } |
| 446 | 437 |
| 447 void ExistingUserController::PerformLogin( | 438 void ExistingUserController::PerformLogin( |
| 448 const UserContext& user_context, | 439 const UserContext& user_context, |
| 449 LoginPerformer::AuthorizationMode auth_mode) { | 440 LoginPerformer::AuthorizationMode auth_mode) { |
| 450 ChromeUserManager::Get()->GetUserFlow(last_login_attempt_username_)->set_host( | 441 ChromeUserManager::Get()->GetUserFlow(user_context.GetUserID())->set_host( |
| 451 host_); | 442 host_); |
| 452 | 443 |
| 453 BootTimesLoader::Get()->RecordLoginAttempted(); | 444 BootTimesLoader::Get()->RecordLoginAttempted(); |
| 454 | 445 |
| 455 // Disable UI while loading user profile. | 446 // Disable UI while loading user profile. |
| 456 login_display_->SetUIEnabled(false); | 447 login_display_->SetUIEnabled(false); |
| 457 | 448 |
| 458 // Use the same LoginPerformer for subsequent login as it has state | 449 // Use the same LoginPerformer for subsequent login as it has state |
| 459 // such as Authenticator instance. | 450 // such as Authenticator instance. |
| 460 if (!login_performer_.get() || num_login_attempts_ <= 1) { | 451 if (!login_performer_.get() || num_login_attempts_ <= 1) { |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 this); | 859 this); |
| 869 | 860 |
| 870 // Update user's displayed email. | 861 // Update user's displayed email. |
| 871 if (!display_email_.empty()) { | 862 if (!display_email_.empty()) { |
| 872 user_manager::UserManager::Get()->SaveUserDisplayEmail( | 863 user_manager::UserManager::Get()->SaveUserDisplayEmail( |
| 873 user_context.GetUserID(), display_email_); | 864 user_context.GetUserID(), display_email_); |
| 874 display_email_.clear(); | 865 display_email_.clear(); |
| 875 } | 866 } |
| 876 } | 867 } |
| 877 | 868 |
| 878 void ExistingUserController::OnProfilePrepared(Profile* profile) { | 869 void ExistingUserController::OnProfilePrepared(Profile* profile, |
| 870 bool browser_launched) { |
| 879 // Reenable clicking on other windows and status area. | 871 // Reenable clicking on other windows and status area. |
| 880 login_display_->SetUIEnabled(true); | 872 login_display_->SetUIEnabled(true); |
| 881 | 873 |
| 882 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 874 if (browser_launched) |
| 883 if (user_manager->IsCurrentUserNew() && | 875 host_ = NULL; |
| 884 user_manager->IsLoggedInAsSupervisedUser()) { | 876 |
| 885 // Supervised users should launch into empty desktop on first run. | 877 // Inform |auth_status_consumer_| about successful login. |
| 886 CommandLine::ForCurrentProcess()->AppendSwitch(::switches::kSilentLaunch); | 878 // TODO(nkostylev): Pass UserContext back crbug.com/424550 |
| 879 if (auth_status_consumer_) { |
| 880 auth_status_consumer_-> |
| 881 OnAuthSuccess(UserContext(last_login_attempt_username_)); |
| 887 } | 882 } |
| 888 | |
| 889 if (user_manager->IsCurrentUserNew() && | |
| 890 !ChromeUserManager::Get() | |
| 891 ->GetCurrentUserFlow() | |
| 892 ->ShouldSkipPostLoginScreens() && | |
| 893 !WizardController::default_controller()->skip_post_login_screens()) { | |
| 894 // Don't specify start URLs if the administrator has configured the start | |
| 895 // URLs via policy. | |
| 896 if (!SessionStartupPref::TypeIsManaged(profile->GetPrefs())) | |
| 897 InitializeStartUrls(); | |
| 898 | |
| 899 // Mark the device as registered., i.e. the second part of OOBE as | |
| 900 // completed. | |
| 901 if (!StartupUtils::IsDeviceRegistered()) | |
| 902 StartupUtils::MarkDeviceRegistered(base::Closure()); | |
| 903 | |
| 904 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 905 chromeos::switches::kOobeSkipPostLogin)) { | |
| 906 LoginUtils::Get()->DoBrowserLaunch(profile, host_); | |
| 907 host_ = NULL; | |
| 908 } else { | |
| 909 ActivateWizard(WizardController::kTermsOfServiceScreenName); | |
| 910 } | |
| 911 } else { | |
| 912 LoginUtils::Get()->DoBrowserLaunch(profile, host_); | |
| 913 host_ = NULL; | |
| 914 } | |
| 915 // Inform |auth_status_consumer_| about successful login. | |
| 916 if (auth_status_consumer_) | |
| 917 auth_status_consumer_->OnAuthSuccess(UserContext()); | |
| 918 } | 883 } |
| 919 | 884 |
| 920 void ExistingUserController::OnOffTheRecordAuthSuccess() { | 885 void ExistingUserController::OnOffTheRecordAuthSuccess() { |
| 921 is_login_in_progress_ = false; | 886 is_login_in_progress_ = false; |
| 922 offline_failed_ = false; | 887 offline_failed_ = false; |
| 923 | 888 |
| 924 // Mark the device as registered., i.e. the second part of OOBE as completed. | 889 // Mark the device as registered., i.e. the second part of OOBE as completed. |
| 925 if (!StartupUtils::IsDeviceRegistered()) | 890 if (!StartupUtils::IsDeviceRegistered()) |
| 926 StartupUtils::MarkDeviceRegistered(base::Closure()); | 891 StartupUtils::MarkDeviceRegistered(base::Closure()); |
| 927 | 892 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 | 981 |
| 1017 void ExistingUserController::DeviceSettingsChanged() { | 982 void ExistingUserController::DeviceSettingsChanged() { |
| 1018 if (host_ != NULL) { | 983 if (host_ != NULL) { |
| 1019 // Signed settings or user list changed. Notify views and update them. | 984 // Signed settings or user list changed. Notify views and update them. |
| 1020 UpdateLoginDisplay(user_manager::UserManager::Get()->GetUsers()); | 985 UpdateLoginDisplay(user_manager::UserManager::Get()->GetUsers()); |
| 1021 ConfigurePublicSessionAutoLogin(); | 986 ConfigurePublicSessionAutoLogin(); |
| 1022 return; | 987 return; |
| 1023 } | 988 } |
| 1024 } | 989 } |
| 1025 | 990 |
| 1026 void ExistingUserController::ActivateWizard(const std::string& screen_name) { | |
| 1027 scoped_ptr<base::DictionaryValue> params; | |
| 1028 host_->StartWizard(screen_name, params.Pass()); | |
| 1029 } | |
| 1030 | |
| 1031 LoginPerformer::AuthorizationMode ExistingUserController::auth_mode() const { | 991 LoginPerformer::AuthorizationMode ExistingUserController::auth_mode() const { |
| 1032 if (login_performer_) | 992 if (login_performer_) |
| 1033 return login_performer_->auth_mode(); | 993 return login_performer_->auth_mode(); |
| 1034 | 994 |
| 1035 return auth_mode_; | 995 return auth_mode_; |
| 1036 } | 996 } |
| 1037 | 997 |
| 1038 bool ExistingUserController::password_changed() const { | 998 bool ExistingUserController::password_changed() const { |
| 1039 if (login_performer_) | 999 if (login_performer_) |
| 1040 return login_performer_->password_changed(); | 1000 return login_performer_->password_changed(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 public_session_auto_login_delay_), | 1075 public_session_auto_login_delay_), |
| 1116 base::Bind( | 1076 base::Bind( |
| 1117 &ExistingUserController::OnPublicSessionAutoLoginTimerFire, | 1077 &ExistingUserController::OnPublicSessionAutoLoginTimerFire, |
| 1118 weak_factory_.GetWeakPtr())); | 1078 weak_factory_.GetWeakPtr())); |
| 1119 } | 1079 } |
| 1120 | 1080 |
| 1121 gfx::NativeWindow ExistingUserController::GetNativeWindow() const { | 1081 gfx::NativeWindow ExistingUserController::GetNativeWindow() const { |
| 1122 return host_->GetNativeWindow(); | 1082 return host_->GetNativeWindow(); |
| 1123 } | 1083 } |
| 1124 | 1084 |
| 1125 void ExistingUserController::InitializeStartUrls() const { | |
| 1126 std::vector<std::string> start_urls; | |
| 1127 | |
| 1128 const base::ListValue *urls; | |
| 1129 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | |
| 1130 bool can_show_getstarted_guide = | |
| 1131 user_manager->GetActiveUser()->GetType() == | |
| 1132 user_manager::USER_TYPE_REGULAR && | |
| 1133 !user_manager->IsCurrentUserNonCryptohomeDataEphemeral(); | |
| 1134 if (user_manager->IsLoggedInAsDemoUser()) { | |
| 1135 if (CrosSettings::Get()->GetList(kStartUpUrls, &urls)) { | |
| 1136 // The retail mode user will get start URLs from a special policy if it is | |
| 1137 // set. | |
| 1138 for (base::ListValue::const_iterator it = urls->begin(); | |
| 1139 it != urls->end(); ++it) { | |
| 1140 std::string url; | |
| 1141 if ((*it)->GetAsString(&url)) | |
| 1142 start_urls.push_back(url); | |
| 1143 } | |
| 1144 } | |
| 1145 can_show_getstarted_guide = false; | |
| 1146 // Skip the default first-run behavior for public accounts. | |
| 1147 } else if (!user_manager->IsLoggedInAsPublicAccount()) { | |
| 1148 if (AccessibilityManager::Get()->IsSpokenFeedbackEnabled()) { | |
| 1149 const char* url = kChromeVoxTutorialURLPattern; | |
| 1150 PrefService* prefs = g_browser_process->local_state(); | |
| 1151 const std::string current_locale = | |
| 1152 base::StringToLowerASCII(prefs->GetString(prefs::kApplicationLocale)); | |
| 1153 std::string vox_url = base::StringPrintf(url, current_locale.c_str()); | |
| 1154 start_urls.push_back(vox_url); | |
| 1155 can_show_getstarted_guide = false; | |
| 1156 } | |
| 1157 } | |
| 1158 | |
| 1159 // Only show getting started guide for a new user. | |
| 1160 const bool should_show_getstarted_guide = user_manager->IsCurrentUserNew(); | |
| 1161 | |
| 1162 if (can_show_getstarted_guide && should_show_getstarted_guide) { | |
| 1163 // Don't open default Chrome window if we're going to launch the first-run | |
| 1164 // app. Because we dont' want the first-run app to be hidden in the | |
| 1165 // background. | |
| 1166 CommandLine::ForCurrentProcess()->AppendSwitch(::switches::kSilentLaunch); | |
| 1167 first_run::MaybeLaunchDialogAfterSessionStart(); | |
| 1168 } else { | |
| 1169 for (size_t i = 0; i < start_urls.size(); ++i) { | |
| 1170 CommandLine::ForCurrentProcess()->AppendArg(start_urls[i]); | |
| 1171 } | |
| 1172 } | |
| 1173 } | |
| 1174 | |
| 1175 void ExistingUserController::ShowError(int error_id, | 1085 void ExistingUserController::ShowError(int error_id, |
| 1176 const std::string& details) { | 1086 const std::string& details) { |
| 1177 // TODO(dpolukhin): show detailed error info. |details| string contains | 1087 // TODO(dpolukhin): show detailed error info. |details| string contains |
| 1178 // low level error info that is not localized and even is not user friendly. | 1088 // low level error info that is not localized and even is not user friendly. |
| 1179 // For now just ignore it because error_text contains all required information | 1089 // For now just ignore it because error_text contains all required information |
| 1180 // for end users, developers can see details string in Chrome logs. | 1090 // for end users, developers can see details string in Chrome logs. |
| 1181 VLOG(1) << details; | 1091 VLOG(1) << details; |
| 1182 HelpAppLauncher::HelpTopic help_topic_id; | 1092 HelpAppLauncher::HelpTopic help_topic_id; |
| 1183 bool is_offline = !network_state_helper_->IsConnected(); | 1093 bool is_offline = !network_state_helper_->IsConnected(); |
| 1184 switch (login_performer_->error().state()) { | 1094 switch (login_performer_->error().state()) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 // Only one instance of LoginPerformer should exist at a time. | 1165 // Only one instance of LoginPerformer should exist at a time. |
| 1256 login_performer_.reset(NULL); | 1166 login_performer_.reset(NULL); |
| 1257 login_performer_.reset(new LoginPerformer(this)); | 1167 login_performer_.reset(new LoginPerformer(this)); |
| 1258 is_login_in_progress_ = true; | 1168 is_login_in_progress_ = true; |
| 1259 login_performer_->LoginAsPublicSession(user_context); | 1169 login_performer_->LoginAsPublicSession(user_context); |
| 1260 SendAccessibilityAlert( | 1170 SendAccessibilityAlert( |
| 1261 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNIN_PUBLIC_ACCOUNT)); | 1171 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNIN_PUBLIC_ACCOUNT)); |
| 1262 } | 1172 } |
| 1263 | 1173 |
| 1264 } // namespace chromeos | 1174 } // namespace chromeos |
| OLD | NEW |