| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/lock/screen_locker.h" | 5 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/common/wallpaper/wallpaper_controller.h" | 10 #include "ash/common/wallpaper/wallpaper_controller.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 156 } |
| 157 | 157 |
| 158 void ScreenLocker::Init() { | 158 void ScreenLocker::Init() { |
| 159 input_method::InputMethodManager* imm = | 159 input_method::InputMethodManager* imm = |
| 160 input_method::InputMethodManager::Get(); | 160 input_method::InputMethodManager::Get(); |
| 161 saved_ime_state_ = imm->GetActiveIMEState(); | 161 saved_ime_state_ = imm->GetActiveIMEState(); |
| 162 imm->SetState(saved_ime_state_->Clone()); | 162 imm->SetState(saved_ime_state_->Clone()); |
| 163 | 163 |
| 164 authenticator_ = UserSessionManager::GetInstance()->CreateAuthenticator(this); | 164 authenticator_ = UserSessionManager::GetInstance()->CreateAuthenticator(this); |
| 165 extended_authenticator_ = ExtendedAuthenticator::Create(this); | 165 extended_authenticator_ = ExtendedAuthenticator::Create(this); |
| 166 delegate_.reset(new WebUIScreenLocker(this)); | 166 web_ui_.reset(new WebUIScreenLocker(this)); |
| 167 delegate_->LockScreen(); | 167 web_ui()->LockScreen(); |
| 168 | 168 |
| 169 // Ownership of |icon_image_source| is passed. | 169 // Ownership of |icon_image_source| is passed. |
| 170 screenlock_icon_provider_.reset(new ScreenlockIconProvider); | 170 screenlock_icon_provider_.reset(new ScreenlockIconProvider); |
| 171 ScreenlockIconSource* screenlock_icon_source = | 171 ScreenlockIconSource* screenlock_icon_source = |
| 172 new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr()); | 172 new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr()); |
| 173 content::URLDataSource::Add( | 173 content::URLDataSource::Add(web_ui()->GetWebContents()->GetBrowserContext(), |
| 174 GetAssociatedWebUI()->GetWebContents()->GetBrowserContext(), | 174 screenlock_icon_source); |
| 175 screenlock_icon_source); | |
| 176 } | 175 } |
| 177 | 176 |
| 178 void ScreenLocker::OnAuthFailure(const AuthFailure& error) { | 177 void ScreenLocker::OnAuthFailure(const AuthFailure& error) { |
| 179 content::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure")); | 178 content::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure")); |
| 180 if (authentication_start_time_.is_null()) { | 179 if (authentication_start_time_.is_null()) { |
| 181 LOG(ERROR) << "Start time is not set at authentication failure"; | 180 LOG(ERROR) << "Start time is not set at authentication failure"; |
| 182 } else { | 181 } else { |
| 183 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; | 182 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; |
| 184 VLOG(1) << "Authentication failure: " << delta.InSecondsF() << " second(s)"; | 183 VLOG(1) << "Authentication failure: " << delta.InSecondsF() << " second(s)"; |
| 185 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta); | 184 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta); |
| 186 } | 185 } |
| 187 | 186 |
| 188 UMA_HISTOGRAM_ENUMERATION( | 187 UMA_HISTOGRAM_ENUMERATION( |
| 189 "ScreenLocker.AuthenticationFailure", | 188 "ScreenLocker.AuthenticationFailure", |
| 190 is_pin_attempt_ ? UnlockType::AUTH_PIN : UnlockType::AUTH_PASSWORD, | 189 is_pin_attempt_ ? UnlockType::AUTH_PIN : UnlockType::AUTH_PASSWORD, |
| 191 UnlockType::AUTH_COUNT); | 190 UnlockType::AUTH_COUNT); |
| 192 | 191 |
| 193 EnableInput(); | 192 EnableInput(); |
| 194 // Don't enable signout button here as we're showing | 193 // Don't enable signout button here as we're showing |
| 195 // MessageBubble. | 194 // MessageBubble. |
| 196 | 195 |
| 197 delegate_->ShowErrorMessage(incorrect_passwords_count_++ ? | 196 web_ui()->ShowErrorMessage(incorrect_passwords_count_++ |
| 198 IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME : | 197 ? IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME |
| 199 IDS_LOGIN_ERROR_AUTHENTICATING, | 198 : IDS_LOGIN_ERROR_AUTHENTICATING, |
| 200 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); | 199 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); |
| 201 | 200 |
| 202 if (auth_status_consumer_) | 201 if (auth_status_consumer_) |
| 203 auth_status_consumer_->OnAuthFailure(error); | 202 auth_status_consumer_->OnAuthFailure(error); |
| 204 } | 203 } |
| 205 | 204 |
| 206 void ScreenLocker::OnAuthSuccess(const UserContext& user_context) { | 205 void ScreenLocker::OnAuthSuccess(const UserContext& user_context) { |
| 207 incorrect_passwords_count_ = 0; | 206 incorrect_passwords_count_ = 0; |
| 208 if (authentication_start_time_.is_null()) { | 207 if (authentication_start_time_.is_null()) { |
| 209 if (user_context.GetAccountId().is_valid()) | 208 if (user_context.GetAccountId().is_valid()) |
| 210 LOG(ERROR) << "Start time is not set at authentication success"; | 209 LOG(ERROR) << "Start time is not set at authentication success"; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 245 |
| 247 authentication_capture_.reset(new AuthenticationParametersCapture()); | 246 authentication_capture_.reset(new AuthenticationParametersCapture()); |
| 248 authentication_capture_->user_context = user_context; | 247 authentication_capture_->user_context = user_context; |
| 249 | 248 |
| 250 // Add guard for case when something get broken in call chain to unlock | 249 // Add guard for case when something get broken in call chain to unlock |
| 251 // for sure. | 250 // for sure. |
| 252 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 251 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 253 FROM_HERE, base::Bind(&ScreenLocker::UnlockOnLoginSuccess, | 252 FROM_HERE, base::Bind(&ScreenLocker::UnlockOnLoginSuccess, |
| 254 weak_factory_.GetWeakPtr()), | 253 weak_factory_.GetWeakPtr()), |
| 255 base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs)); | 254 base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs)); |
| 256 delegate_->AnimateAuthenticationSuccess(); | 255 web_ui()->AnimateAuthenticationSuccess(); |
| 257 } | 256 } |
| 258 | 257 |
| 259 void ScreenLocker::OnPasswordAuthSuccess(const UserContext& user_context) { | 258 void ScreenLocker::OnPasswordAuthSuccess(const UserContext& user_context) { |
| 260 // The user has signed in using their password, so reset the PIN timeout. | 259 // The user has signed in using their password, so reset the PIN timeout. |
| 261 PinStorage* pin_storage = | 260 PinStorage* pin_storage = |
| 262 PinStorageFactory::GetForAccountId(user_context.GetAccountId()); | 261 PinStorageFactory::GetForAccountId(user_context.GetAccountId()); |
| 263 if (pin_storage) | 262 if (pin_storage) |
| 264 pin_storage->MarkStrongAuth(); | 263 pin_storage->MarkStrongAuth(); |
| 265 } | 264 } |
| 266 | 265 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 280 | 279 |
| 281 VLOG(1) << "Hiding the lock screen."; | 280 VLOG(1) << "Hiding the lock screen."; |
| 282 chromeos::ScreenLocker::Hide(); | 281 chromeos::ScreenLocker::Hide(); |
| 283 } | 282 } |
| 284 | 283 |
| 285 void ScreenLocker::Authenticate(const UserContext& user_context) { | 284 void ScreenLocker::Authenticate(const UserContext& user_context) { |
| 286 LOG_ASSERT(IsUserLoggedIn(user_context.GetAccountId())) | 285 LOG_ASSERT(IsUserLoggedIn(user_context.GetAccountId())) |
| 287 << "Invalid user trying to unlock."; | 286 << "Invalid user trying to unlock."; |
| 288 | 287 |
| 289 authentication_start_time_ = base::Time::Now(); | 288 authentication_start_time_ = base::Time::Now(); |
| 290 delegate_->SetInputEnabled(false); | 289 web_ui()->SetInputEnabled(false); |
| 291 delegate_->OnAuthenticate(); | |
| 292 is_pin_attempt_ = user_context.IsUsingPin(); | 290 is_pin_attempt_ = user_context.IsUsingPin(); |
| 293 | 291 |
| 294 const user_manager::User* user = FindUnlockUser(user_context.GetAccountId()); | 292 const user_manager::User* user = FindUnlockUser(user_context.GetAccountId()); |
| 295 if (user) { | 293 if (user) { |
| 296 // Check to see if the user submitted a PIN and it is valid. | 294 // Check to see if the user submitted a PIN and it is valid. |
| 297 const std::string pin = user_context.GetKey()->GetSecret(); | 295 const std::string pin = user_context.GetKey()->GetSecret(); |
| 298 | 296 |
| 299 // We only want to try authenticating the pin if it is a number, | 297 // We only want to try authenticating the pin if it is a number, |
| 300 // otherwise we will timeout PIN if the user enters their account password | 298 // otherwise we will timeout PIN if the user enters their account password |
| 301 // incorrectly more than a few times. | 299 // incorrectly more than a few times. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 const user_manager::User* ScreenLocker::FindUnlockUser( | 334 const user_manager::User* ScreenLocker::FindUnlockUser( |
| 337 const AccountId& account_id) { | 335 const AccountId& account_id) { |
| 338 for (const user_manager::User* user : users_) { | 336 for (const user_manager::User* user : users_) { |
| 339 if (user->GetAccountId() == account_id) | 337 if (user->GetAccountId() == account_id) |
| 340 return user; | 338 return user; |
| 341 } | 339 } |
| 342 return nullptr; | 340 return nullptr; |
| 343 } | 341 } |
| 344 | 342 |
| 345 void ScreenLocker::ClearErrors() { | 343 void ScreenLocker::ClearErrors() { |
| 346 delegate_->ClearErrors(); | 344 web_ui()->ClearErrors(); |
| 347 } | 345 } |
| 348 | 346 |
| 349 void ScreenLocker::Signout() { | 347 void ScreenLocker::Signout() { |
| 350 delegate_->ClearErrors(); | 348 web_ui()->ClearErrors(); |
| 351 content::RecordAction(UserMetricsAction("ScreenLocker_Signout")); | 349 content::RecordAction(UserMetricsAction("ScreenLocker_Signout")); |
| 352 // We expect that this call will not wait for any user input. | 350 // We expect that this call will not wait for any user input. |
| 353 // If it changes at some point, we will need to force exit. | 351 // If it changes at some point, we will need to force exit. |
| 354 chrome::AttemptUserExit(); | 352 chrome::AttemptUserExit(); |
| 355 | 353 |
| 356 // Don't hide yet the locker because the chrome screen may become visible | 354 // Don't hide yet the locker because the chrome screen may become visible |
| 357 // briefly. | 355 // briefly. |
| 358 } | 356 } |
| 359 | 357 |
| 360 void ScreenLocker::EnableInput() { | 358 void ScreenLocker::EnableInput() { |
| 361 delegate_->SetInputEnabled(true); | 359 web_ui()->SetInputEnabled(true); |
| 362 } | 360 } |
| 363 | 361 |
| 364 void ScreenLocker::ShowErrorMessage(int error_msg_id, | 362 void ScreenLocker::ShowErrorMessage(int error_msg_id, |
| 365 HelpAppLauncher::HelpTopic help_topic_id, | 363 HelpAppLauncher::HelpTopic help_topic_id, |
| 366 bool sign_out_only) { | 364 bool sign_out_only) { |
| 367 delegate_->SetInputEnabled(!sign_out_only); | 365 web_ui()->SetInputEnabled(!sign_out_only); |
| 368 delegate_->ShowErrorMessage(error_msg_id, help_topic_id); | 366 web_ui()->ShowErrorMessage(error_msg_id, help_topic_id); |
| 369 } | 367 } |
| 370 | 368 |
| 371 void ScreenLocker::SetLoginStatusConsumer( | 369 void ScreenLocker::SetLoginStatusConsumer( |
| 372 chromeos::AuthStatusConsumer* consumer) { | 370 chromeos::AuthStatusConsumer* consumer) { |
| 373 auth_status_consumer_ = consumer; | 371 auth_status_consumer_ = consumer; |
| 374 } | 372 } |
| 375 | 373 |
| 376 // static | 374 // static |
| 377 void ScreenLocker::InitClass() { | 375 void ScreenLocker::InitClass() { |
| 378 DCHECK(!g_screen_lock_observer); | 376 DCHECK(!g_screen_lock_observer); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 content::Source<ScreenLocker>(this), | 528 content::Source<ScreenLocker>(this), |
| 531 content::Details<bool>(&state)); | 529 content::Details<bool>(&state)); |
| 532 VLOG(1) << "Calling session manager's HandleLockScreenShown D-Bus method"; | 530 VLOG(1) << "Calling session manager's HandleLockScreenShown D-Bus method"; |
| 533 DBusThreadManager::Get()->GetSessionManagerClient()->NotifyLockScreenShown(); | 531 DBusThreadManager::Get()->GetSessionManagerClient()->NotifyLockScreenShown(); |
| 534 | 532 |
| 535 input_method::InputMethodManager::Get() | 533 input_method::InputMethodManager::Get() |
| 536 ->GetActiveIMEState() | 534 ->GetActiveIMEState() |
| 537 ->EnableLockScreenLayouts(); | 535 ->EnableLockScreenLayouts(); |
| 538 } | 536 } |
| 539 | 537 |
| 540 content::WebUI* ScreenLocker::GetAssociatedWebUI() { | |
| 541 return delegate_->GetAssociatedWebUI(); | |
| 542 } | |
| 543 | |
| 544 bool ScreenLocker::IsUserLoggedIn(const AccountId& account_id) const { | 538 bool ScreenLocker::IsUserLoggedIn(const AccountId& account_id) const { |
| 545 for (user_manager::User* user : users_) { | 539 for (user_manager::User* user : users_) { |
| 546 if (user->GetAccountId() == account_id) | 540 if (user->GetAccountId() == account_id) |
| 547 return true; | 541 return true; |
| 548 } | 542 } |
| 549 return false; | 543 return false; |
| 550 } | 544 } |
| 551 | 545 |
| 552 } // namespace chromeos | 546 } // namespace chromeos |
| OLD | NEW |