xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 5 | #include "ash/login/login_screen_controller.h" |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 6 | |
jdufault | eb4c9f1e | 2017-06-08 23:08:30 | [diff] [blame] | 7 | #include "ash/login/ui/lock_screen.h" |
Quan Nguyen | d09dd11 | 2018-06-19 19:20:32 | [diff] [blame^] | 8 | #include "ash/login/ui/lock_window.h" |
Jacob Dufault | 40623d5 | 2017-09-15 17:22:53 | [diff] [blame] | 9 | #include "ash/login/ui/login_data_dispatcher.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 10 | #include "ash/public/cpp/ash_pref_names.h" |
Aga Wronska | 16abb43 | 2018-01-11 23:49:59 | [diff] [blame] | 11 | #include "ash/root_window_controller.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 12 | #include "ash/session/session_controller.h" |
Quan Nguyen | d09dd11 | 2018-06-19 19:20:32 | [diff] [blame^] | 13 | #include "ash/shelf/shelf.h" |
| 14 | #include "ash/shelf/shelf_widget.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 15 | #include "ash/shell.h" |
Aga Wronska | 16abb43 | 2018-01-11 23:49:59 | [diff] [blame] | 16 | #include "ash/system/status_area_widget.h" |
Jacob Dufault | c06d6ca | 2018-04-24 23:49:17 | [diff] [blame] | 17 | #include "base/debug/alias.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 18 | #include "base/strings/string_number_conversions.h" |
Jialiu Lin | f99b788b | 2018-01-17 23:01:21 | [diff] [blame] | 19 | #include "base/strings/utf_string_conversions.h" |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 20 | #include "chromeos/cryptohome/system_salt_getter.h" |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 21 | #include "components/prefs/pref_registry_simple.h" |
Jacob Dufault | 957e092 | 2017-12-06 19:16:09 | [diff] [blame] | 22 | #include "components/session_manager/session_manager_types.h" |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 23 | |
| 24 | namespace ash { |
| 25 | |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 26 | namespace { |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 27 | |
Aga Wronska | a844cdcd1 | 2018-01-29 16:06:44 | [diff] [blame] | 28 | enum class SystemTrayVisibility { |
| 29 | kNone, // Tray not visible anywhere. |
| 30 | kPrimary, // Tray visible only on primary display. |
| 31 | kAll, // Tray visible on all displays. |
| 32 | }; |
| 33 | |
| 34 | void SetSystemTrayVisibility(SystemTrayVisibility visibility) { |
| 35 | RootWindowController* primary_window_controller = |
| 36 | Shell::GetPrimaryRootWindowController(); |
| 37 | for (RootWindowController* window_controller : |
| 38 | Shell::GetAllRootWindowControllers()) { |
| 39 | StatusAreaWidget* status_area = window_controller->GetStatusAreaWidget(); |
| 40 | if (!status_area) |
| 41 | continue; |
| 42 | if (window_controller == primary_window_controller) { |
| 43 | status_area->SetSystemTrayVisibility( |
| 44 | visibility == SystemTrayVisibility::kPrimary || |
| 45 | visibility == SystemTrayVisibility::kAll); |
| 46 | } else { |
| 47 | status_area->SetSystemTrayVisibility(visibility == |
| 48 | SystemTrayVisibility::kAll); |
| 49 | } |
| 50 | } |
Aga Wronska | 16abb43 | 2018-01-11 23:49:59 | [diff] [blame] | 51 | } |
| 52 | |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 53 | } // namespace |
| 54 | |
James Cook | ede316a | 2017-12-14 22:38:43 | [diff] [blame] | 55 | LoginScreenController::LoginScreenController() : weak_factory_(this) {} |
James Cook | 8f1e606 | 2017-11-13 23:40:59 | [diff] [blame] | 56 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 57 | LoginScreenController::~LoginScreenController() = default; |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 58 | |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 59 | // static |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 60 | void LoginScreenController::RegisterProfilePrefs(PrefRegistrySimple* registry, |
| 61 | bool for_test) { |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 62 | if (for_test) { |
| 63 | // There is no remote pref service, so pretend that ash owns the pref. |
| 64 | registry->RegisterStringPref(prefs::kQuickUnlockPinSalt, ""); |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | // Pref is owned by chrome and flagged as PUBLIC. |
| 69 | registry->RegisterForeignPref(prefs::kQuickUnlockPinSalt); |
| 70 | } |
| 71 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 72 | void LoginScreenController::BindRequest(mojom::LoginScreenRequest request) { |
James Cook | ede316a | 2017-12-14 22:38:43 | [diff] [blame] | 73 | bindings_.AddBinding(this, std::move(request)); |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 74 | } |
| 75 | |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 76 | void LoginScreenController::AuthenticateUser(const AccountId& account_id, |
| 77 | const std::string& password, |
| 78 | bool authenticated_by_pin, |
| 79 | OnAuthenticateCallback callback) { |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 80 | // It is an error to call this function while an authentication is in |
| 81 | // progress. |
Jacob Dufault | c06d6ca | 2018-04-24 23:49:17 | [diff] [blame] | 82 | LOG_IF(ERROR, authentication_stage_ != AuthenticationStage::kIdle) |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 83 | << "Authentication stage is " << static_cast<int>(authentication_stage_); |
| 84 | CHECK_EQ(authentication_stage_, AuthenticationStage::kIdle); |
| 85 | |
| 86 | if (!login_screen_client_) { |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 87 | std::move(callback).Run(base::nullopt); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 88 | return; |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 89 | } |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 90 | |
Jacob Dufault | eafc6fe | 2017-10-11 21:16:52 | [diff] [blame] | 91 | // If auth is disabled by the debug overlay bypass the mojo call entirely, as |
| 92 | // it will dismiss the lock screen if the password is correct. |
Jacob Dufault | 0fbed9c0 | 2017-11-14 19:22:24 | [diff] [blame] | 93 | switch (force_fail_auth_for_debug_overlay_) { |
| 94 | case ForceFailAuth::kOff: |
| 95 | break; |
| 96 | case ForceFailAuth::kImmediate: |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 97 | OnAuthenticateComplete(std::move(callback), false /*success*/); |
Jacob Dufault | 0fbed9c0 | 2017-11-14 19:22:24 | [diff] [blame] | 98 | return; |
| 99 | case ForceFailAuth::kDelayed: |
| 100 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 101 | FROM_HERE, |
| 102 | base::BindOnce(&LoginScreenController::OnAuthenticateComplete, |
| 103 | weak_factory_.GetWeakPtr(), base::Passed(&callback), |
| 104 | false), |
Jacob Dufault | 0fbed9c0 | 2017-11-14 19:22:24 | [diff] [blame] | 105 | base::TimeDelta::FromSeconds(1)); |
| 106 | return; |
Jacob Dufault | eafc6fe | 2017-10-11 21:16:52 | [diff] [blame] | 107 | } |
| 108 | |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 109 | // |DoAuthenticateUser| requires the system salt. |
| 110 | authentication_stage_ = AuthenticationStage::kGetSystemSalt; |
| 111 | chromeos::SystemSaltGetter::Get()->GetSystemSalt( |
| 112 | base::AdaptCallbackForRepeating( |
| 113 | base::BindOnce(&LoginScreenController::DoAuthenticateUser, |
| 114 | weak_factory_.GetWeakPtr(), account_id, password, |
| 115 | authenticated_by_pin, std::move(callback)))); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 116 | } |
| 117 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 118 | void LoginScreenController::AttemptUnlock(const AccountId& account_id) { |
| 119 | if (!login_screen_client_) |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 120 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 121 | login_screen_client_->AttemptUnlock(account_id); |
Sarah Hu | e0e01a5 | 2017-10-25 20:29:30 | [diff] [blame] | 122 | |
| 123 | Shell::Get()->metrics()->login_metrics_recorder()->SetAuthMethod( |
| 124 | LoginMetricsRecorder::AuthMethod::kSmartlock); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 125 | } |
| 126 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 127 | void LoginScreenController::HardlockPod(const AccountId& account_id) { |
| 128 | if (!login_screen_client_) |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 129 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 130 | login_screen_client_->HardlockPod(account_id); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 131 | } |
| 132 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 133 | void LoginScreenController::RecordClickOnLockIcon(const AccountId& account_id) { |
| 134 | if (!login_screen_client_) |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 135 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 136 | login_screen_client_->RecordClickOnLockIcon(account_id); |
xiaoyinh | 9f6fa0e | 2017-06-07 19:22:32 | [diff] [blame] | 137 | } |
| 138 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 139 | void LoginScreenController::OnFocusPod(const AccountId& account_id) { |
| 140 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 141 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 142 | login_screen_client_->OnFocusPod(account_id); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 143 | } |
| 144 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 145 | void LoginScreenController::OnNoPodFocused() { |
| 146 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 147 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 148 | login_screen_client_->OnNoPodFocused(); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 149 | } |
| 150 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 151 | void LoginScreenController::LoadWallpaper(const AccountId& account_id) { |
| 152 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 153 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 154 | login_screen_client_->LoadWallpaper(account_id); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 155 | } |
| 156 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 157 | void LoginScreenController::SignOutUser() { |
| 158 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 159 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 160 | login_screen_client_->SignOutUser(); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 161 | } |
| 162 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 163 | void LoginScreenController::CancelAddUser() { |
| 164 | if (!login_screen_client_) |
Wenzhao Zang | 16e7ea72 | 2017-09-16 01:27:30 | [diff] [blame] | 165 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 166 | login_screen_client_->CancelAddUser(); |
Wenzhao Zang | 16e7ea72 | 2017-09-16 01:27:30 | [diff] [blame] | 167 | } |
| 168 | |
Aga Wronska | 6a32f987 | 2018-01-06 00:16:10 | [diff] [blame] | 169 | void LoginScreenController::LoginAsGuest() { |
| 170 | if (!login_screen_client_) |
| 171 | return; |
| 172 | login_screen_client_->LoginAsGuest(); |
| 173 | } |
| 174 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 175 | void LoginScreenController::OnMaxIncorrectPasswordAttempted( |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 176 | const AccountId& account_id) { |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 177 | if (!login_screen_client_) |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 178 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 179 | login_screen_client_->OnMaxIncorrectPasswordAttempted(account_id); |
xiaoyinh | f534c4f | 2017-06-13 20:50:27 | [diff] [blame] | 180 | } |
| 181 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 182 | void LoginScreenController::FocusLockScreenApps(bool reverse) { |
| 183 | if (!login_screen_client_) |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 184 | return; |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 185 | login_screen_client_->FocusLockScreenApps(reverse); |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 186 | } |
| 187 | |
Wenzhao Zang | 767a9f3 | 2018-05-02 21:20:55 | [diff] [blame] | 188 | void LoginScreenController::ShowGaiaSignin( |
Jacob Dufault | fb72607d | 2018-06-12 19:50:33 | [diff] [blame] | 189 | bool can_close, |
| 190 | const base::Optional<AccountId>& prefilled_account) { |
Sarah Hu | 9fba0e75 | 2018-02-07 01:41:09 | [diff] [blame] | 191 | if (!login_screen_client_) |
| 192 | return; |
Jacob Dufault | fb72607d | 2018-06-12 19:50:33 | [diff] [blame] | 193 | login_screen_client_->ShowGaiaSignin(can_close, prefilled_account); |
Sarah Hu | 9fba0e75 | 2018-02-07 01:41:09 | [diff] [blame] | 194 | } |
| 195 | |
Jacob Dufault | fc31c74 | 2018-03-20 17:32:19 | [diff] [blame] | 196 | void LoginScreenController::OnRemoveUserWarningShown() { |
| 197 | if (!login_screen_client_) |
| 198 | return; |
| 199 | login_screen_client_->OnRemoveUserWarningShown(); |
| 200 | } |
| 201 | |
| 202 | void LoginScreenController::RemoveUser(const AccountId& account_id) { |
| 203 | if (!login_screen_client_) |
| 204 | return; |
| 205 | login_screen_client_->RemoveUser(account_id); |
| 206 | } |
| 207 | |
Sarah Hu | 3fcf9f8 | 2018-03-22 20:32:54 | [diff] [blame] | 208 | void LoginScreenController::LaunchPublicSession( |
| 209 | const AccountId& account_id, |
| 210 | const std::string& locale, |
| 211 | const std::string& input_method) { |
| 212 | if (!login_screen_client_) |
| 213 | return; |
| 214 | login_screen_client_->LaunchPublicSession(account_id, locale, input_method); |
| 215 | } |
| 216 | |
Sarah Hu | f9affb12 | 2018-04-27 21:36:36 | [diff] [blame] | 217 | void LoginScreenController::RequestPublicSessionKeyboardLayouts( |
| 218 | const AccountId& account_id, |
| 219 | const std::string& locale) { |
| 220 | if (!login_screen_client_) |
| 221 | return; |
| 222 | login_screen_client_->RequestPublicSessionKeyboardLayouts(account_id, locale); |
| 223 | } |
| 224 | |
Sarah Hu | 0007c93 | 2018-06-18 20:21:04 | [diff] [blame] | 225 | void LoginScreenController::ShowFeedback() { |
| 226 | if (!login_screen_client_) |
| 227 | return; |
| 228 | login_screen_client_->ShowFeedback(); |
| 229 | } |
| 230 | |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 231 | void LoginScreenController::AddObserver( |
| 232 | LoginScreenControllerObserver* observer) { |
| 233 | observers_.AddObserver(observer); |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 234 | } |
| 235 | |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 236 | void LoginScreenController::RemoveObserver( |
| 237 | LoginScreenControllerObserver* observer) { |
| 238 | observers_.RemoveObserver(observer); |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 239 | } |
| 240 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 241 | void LoginScreenController::FlushForTesting() { |
| 242 | login_screen_client_.FlushForTesting(); |
Toni Barzic | f61c445 | 2017-10-05 03:57:48 | [diff] [blame] | 243 | } |
| 244 | |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 245 | void LoginScreenController::SetClient(mojom::LoginScreenClientPtr client) { |
| 246 | login_screen_client_ = std::move(client); |
| 247 | } |
| 248 | |
| 249 | void LoginScreenController::ShowLockScreen(ShowLockScreenCallback on_shown) { |
| 250 | OnShow(); |
| 251 | ash::LockScreen::Show(ash::LockScreen::ScreenType::kLock); |
| 252 | std::move(on_shown).Run(true); |
| 253 | } |
| 254 | |
| 255 | void LoginScreenController::ShowLoginScreen(ShowLoginScreenCallback on_shown) { |
| 256 | // Login screen can only be used during login. |
| 257 | if (Shell::Get()->session_controller()->GetSessionState() != |
| 258 | session_manager::SessionState::LOGIN_PRIMARY) { |
| 259 | LOG(ERROR) << "Not showing login screen since session state is " |
| 260 | << static_cast<int>( |
| 261 | Shell::Get()->session_controller()->GetSessionState()); |
| 262 | std::move(on_shown).Run(false); |
| 263 | return; |
| 264 | } |
| 265 | |
| 266 | OnShow(); |
| 267 | // TODO(jdufault): rename ash::LockScreen to ash::LoginScreen. |
| 268 | ash::LockScreen::Show(ash::LockScreen::ScreenType::kLogin); |
| 269 | std::move(on_shown).Run(true); |
| 270 | } |
| 271 | |
| 272 | void LoginScreenController::ShowErrorMessage(int32_t login_attempts, |
| 273 | const std::string& error_text, |
| 274 | const std::string& help_link_text, |
| 275 | int32_t help_topic_id) { |
| 276 | NOTIMPLEMENTED(); |
| 277 | } |
| 278 | |
| 279 | void LoginScreenController::ClearErrors() { |
| 280 | NOTIMPLEMENTED(); |
| 281 | } |
| 282 | |
| 283 | void LoginScreenController::ShowUserPodCustomIcon( |
| 284 | const AccountId& account_id, |
| 285 | mojom::EasyUnlockIconOptionsPtr icon) { |
| 286 | DataDispatcher()->ShowEasyUnlockIcon(account_id, icon); |
| 287 | } |
| 288 | |
| 289 | void LoginScreenController::HideUserPodCustomIcon(const AccountId& account_id) { |
| 290 | auto icon_options = mojom::EasyUnlockIconOptions::New(); |
| 291 | icon_options->icon = mojom::EasyUnlockIconId::NONE; |
| 292 | DataDispatcher()->ShowEasyUnlockIcon(account_id, icon_options); |
| 293 | } |
| 294 | |
| 295 | void LoginScreenController::SetAuthType( |
| 296 | const AccountId& account_id, |
| 297 | proximity_auth::mojom::AuthType auth_type, |
| 298 | const base::string16& initial_value) { |
| 299 | if (auth_type == proximity_auth::mojom::AuthType::USER_CLICK) { |
| 300 | DataDispatcher()->SetClickToUnlockEnabledForUser(account_id, |
| 301 | true /*enabled*/); |
Wenzhao Zang | 767a9f3 | 2018-05-02 21:20:55 | [diff] [blame] | 302 | } else if (auth_type == proximity_auth::mojom::AuthType::ONLINE_SIGN_IN) { |
| 303 | DataDispatcher()->SetForceOnlineSignInForUser(account_id); |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 304 | } else { |
| 305 | NOTIMPLEMENTED(); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | void LoginScreenController::LoadUsers( |
| 310 | std::vector<mojom::LoginUserInfoPtr> users, |
| 311 | bool show_guest) { |
| 312 | DCHECK(DataDispatcher()); |
| 313 | |
| 314 | DataDispatcher()->NotifyUsers(users); |
| 315 | } |
| 316 | |
| 317 | void LoginScreenController::SetPinEnabledForUser(const AccountId& account_id, |
| 318 | bool is_enabled) { |
| 319 | // Chrome will update pin pod state every time user tries to authenticate. |
| 320 | // LockScreen is destroyed in the case of authentication success. |
| 321 | if (DataDispatcher()) |
| 322 | DataDispatcher()->SetPinEnabledForUser(account_id, is_enabled); |
| 323 | } |
| 324 | |
Jacob Dufault | 77d75ce9 | 2018-04-13 18:20:09 | [diff] [blame] | 325 | void LoginScreenController::SetAvatarForUser(const AccountId& account_id, |
| 326 | mojom::UserAvatarPtr avatar) { |
| 327 | for (auto& observer : observers_) |
| 328 | observer.SetAvatarForUser(account_id, avatar); |
| 329 | } |
| 330 | |
Wenzhao Zang | e0c2ab2 | 2018-05-23 17:43:46 | [diff] [blame] | 331 | void LoginScreenController::SetAuthEnabledForUser( |
| 332 | const AccountId& account_id, |
| 333 | bool is_enabled, |
| 334 | base::Optional<base::Time> auth_reenabled_time) { |
| 335 | if (DataDispatcher()) { |
| 336 | DataDispatcher()->SetAuthEnabledForUser(account_id, is_enabled, |
| 337 | auth_reenabled_time); |
| 338 | } |
| 339 | } |
| 340 | |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 341 | void LoginScreenController::HandleFocusLeavingLockScreenApps(bool reverse) { |
| 342 | for (auto& observer : observers_) |
| 343 | observer.OnFocusLeavingLockScreenApps(reverse); |
| 344 | } |
| 345 | |
| 346 | void LoginScreenController::SetDevChannelInfo( |
| 347 | const std::string& os_version_label_text, |
| 348 | const std::string& enterprise_info_text, |
| 349 | const std::string& bluetooth_name) { |
| 350 | if (DataDispatcher()) { |
| 351 | DataDispatcher()->SetDevChannelInfo(os_version_label_text, |
| 352 | enterprise_info_text, bluetooth_name); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | void LoginScreenController::IsReadyForPassword( |
| 357 | IsReadyForPasswordCallback callback) { |
Wenzhao Zang | 73349728 | 2018-06-12 16:53:10 | [diff] [blame] | 358 | std::move(callback).Run(LockScreen::HasInstance() && |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 359 | authentication_stage_ == AuthenticationStage::kIdle); |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | void LoginScreenController::SetPublicSessionDisplayName( |
| 363 | const AccountId& account_id, |
| 364 | const std::string& display_name) { |
| 365 | if (DataDispatcher()) |
| 366 | DataDispatcher()->SetPublicSessionDisplayName(account_id, display_name); |
| 367 | } |
| 368 | |
| 369 | void LoginScreenController::SetPublicSessionLocales( |
| 370 | const AccountId& account_id, |
Sarah Hu | e9cd613 | 2018-05-17 17:25:56 | [diff] [blame] | 371 | std::vector<mojom::LocaleItemPtr> locales, |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 372 | const std::string& default_locale, |
| 373 | bool show_advanced_view) { |
| 374 | if (DataDispatcher()) { |
| 375 | DataDispatcher()->SetPublicSessionLocales( |
Sarah Hu | e9cd613 | 2018-05-17 17:25:56 | [diff] [blame] | 376 | account_id, locales, default_locale, show_advanced_view); |
Jacob Dufault | 589d994 | 2018-03-27 20:28:47 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | |
Sarah Hu | f9affb12 | 2018-04-27 21:36:36 | [diff] [blame] | 380 | void LoginScreenController::SetPublicSessionKeyboardLayouts( |
| 381 | const AccountId& account_id, |
| 382 | const std::string& locale, |
| 383 | std::vector<mojom::InputMethodItemPtr> keyboard_layouts) { |
| 384 | if (DataDispatcher()) { |
| 385 | DataDispatcher()->SetPublicSessionKeyboardLayouts(account_id, locale, |
| 386 | keyboard_layouts); |
| 387 | } |
| 388 | } |
| 389 | |
Sarah Hu | 1a7de56 | 2018-05-14 17:18:22 | [diff] [blame] | 390 | void LoginScreenController::SetFingerprintUnlockState( |
| 391 | const AccountId& account_id, |
| 392 | mojom::FingerprintUnlockState state) { |
| 393 | if (DataDispatcher()) |
| 394 | DataDispatcher()->SetFingerprintUnlockState(account_id, state); |
| 395 | } |
| 396 | |
Quan Nguyen | d09dd11 | 2018-06-19 19:20:32 | [diff] [blame^] | 397 | void LoginScreenController::SetKioskApps( |
| 398 | std::vector<mojom::KioskAppInfoPtr> kiosk_apps) { |
| 399 | Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) |
| 400 | ->shelf_widget() |
| 401 | ->SetLoginKioskApps(std::move(kiosk_apps)); |
| 402 | } |
| 403 | |
| 404 | void LoginScreenController::LaunchKioskApp(const std::string& app_id) { |
| 405 | login_screen_client_->LaunchKioskApp(app_id); |
| 406 | } |
| 407 | |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 408 | void LoginScreenController::DoAuthenticateUser(const AccountId& account_id, |
| 409 | const std::string& password, |
| 410 | bool authenticated_by_pin, |
| 411 | OnAuthenticateCallback callback, |
| 412 | const std::string& system_salt) { |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 413 | authentication_stage_ = AuthenticationStage::kDoAuthenticate; |
| 414 | |
Sarah Hu | 069eea1 | 2017-09-08 01:28:40 | [diff] [blame] | 415 | int dummy_value; |
| 416 | bool is_pin = |
| 417 | authenticated_by_pin && base::StringToInt(password, &dummy_value); |
Roman Sorokin | c559001 | 2017-09-28 00:48:29 | [diff] [blame] | 418 | |
Sarah Hu | e0e01a5 | 2017-10-25 20:29:30 | [diff] [blame] | 419 | Shell::Get()->metrics()->login_metrics_recorder()->SetAuthMethod( |
| 420 | is_pin ? LoginMetricsRecorder::AuthMethod::kPin |
| 421 | : LoginMetricsRecorder::AuthMethod::kPassword); |
Jacob Dufault | 2be7100 | 2018-05-16 17:07:43 | [diff] [blame] | 422 | |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 423 | login_screen_client_->AuthenticateUser( |
Jacob Dufault | 2be7100 | 2018-05-16 17:07:43 | [diff] [blame] | 424 | account_id, password, is_pin, |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 425 | base::BindOnce(&LoginScreenController::OnAuthenticateComplete, |
| 426 | weak_factory_.GetWeakPtr(), base::Passed(&callback))); |
jdufault | eb4c9f1e | 2017-06-08 23:08:30 | [diff] [blame] | 427 | } |
| 428 | |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 429 | void LoginScreenController::OnAuthenticateComplete( |
| 430 | OnAuthenticateCallback callback, |
| 431 | bool success) { |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 432 | authentication_stage_ = AuthenticationStage::kUserCallback; |
Jacob Dufault | b7a2d84 | 2017-12-01 23:21:15 | [diff] [blame] | 433 | std::move(callback).Run(success); |
Jacob Dufault | 8876ba8 | 2018-03-27 22:55:43 | [diff] [blame] | 434 | authentication_stage_ = AuthenticationStage::kIdle; |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 435 | } |
| 436 | |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 437 | LoginDataDispatcher* LoginScreenController::DataDispatcher() const { |
Wenzhao Zang | 73349728 | 2018-06-12 16:53:10 | [diff] [blame] | 438 | if (!ash::LockScreen::HasInstance()) |
Jacob Dufault | 40623d5 | 2017-09-15 17:22:53 | [diff] [blame] | 439 | return nullptr; |
| 440 | return ash::LockScreen::Get()->data_dispatcher(); |
| 441 | } |
| 442 | |
Jacob Dufault | cbc1ee0 | 2018-02-28 18:38:54 | [diff] [blame] | 443 | void LoginScreenController::OnShow() { |
| 444 | SetSystemTrayVisibility(SystemTrayVisibility::kPrimary); |
Jacob Dufault | c06d6ca | 2018-04-24 23:49:17 | [diff] [blame] | 445 | if (authentication_stage_ != AuthenticationStage::kIdle) { |
| 446 | AuthenticationStage authentication_stage = authentication_stage_; |
| 447 | base::debug::Alias(&authentication_stage); |
| 448 | LOG(FATAL) << "Unexpected authentication stage " |
| 449 | << static_cast<int>(authentication_stage_); |
| 450 | } |
Jacob Dufault | cbc1ee0 | 2018-02-28 18:38:54 | [diff] [blame] | 451 | } |
| 452 | |
xiaoyinh | 2bbdd10 | 2017-05-18 23:29:42 | [diff] [blame] | 453 | } // namespace ash |