| 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/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/wallpaper/wallpaper_controller.h" | 11 #include "ash/wallpaper/wallpaper_controller.h" |
| 12 #include "ash/wm/lock_state_controller.h" | |
| 13 #include "ash/wm/window_state.h" | 12 #include "ash/wm/window_state.h" |
| 14 #include "ash/wm/window_state_aura.h" | 13 #include "ash/wm/window_state_aura.h" |
| 15 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
| 16 #include "ash/wm/wm_event.h" | 15 #include "ash/wm/wm_event.h" |
| 17 #include "base/bind.h" | 16 #include "base/bind.h" |
| 18 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 19 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
| 20 #include "base/location.h" | 19 #include "base/location.h" |
| 21 #include "base/macros.h" | 20 #include "base/macros.h" |
| 22 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 weak_factory_(this) { | 149 weak_factory_(this) { |
| 151 DCHECK(!screen_locker_); | 150 DCHECK(!screen_locker_); |
| 152 screen_locker_ = this; | 151 screen_locker_ = this; |
| 153 | 152 |
| 154 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 153 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 155 media::SoundsManager* manager = media::SoundsManager::Get(); | 154 media::SoundsManager* manager = media::SoundsManager::Get(); |
| 156 manager->Initialize(SOUND_LOCK, | 155 manager->Initialize(SOUND_LOCK, |
| 157 bundle.GetRawDataResource(IDR_SOUND_LOCK_WAV)); | 156 bundle.GetRawDataResource(IDR_SOUND_LOCK_WAV)); |
| 158 manager->Initialize(SOUND_UNLOCK, | 157 manager->Initialize(SOUND_UNLOCK, |
| 159 bundle.GetRawDataResource(IDR_SOUND_UNLOCK_WAV)); | 158 bundle.GetRawDataResource(IDR_SOUND_UNLOCK_WAV)); |
| 160 | |
| 161 ash::Shell::Get()->lock_state_controller()->SetLockScreenDisplayedCallback( | |
| 162 base::Bind(base::IgnoreResult(&AccessibilityManager::PlayEarcon), | |
| 163 base::Unretained(AccessibilityManager::Get()), | |
| 164 chromeos::SOUND_LOCK, | |
| 165 PlaySoundOption::SPOKEN_FEEDBACK_ENABLED)); | |
| 166 } | 159 } |
| 167 | 160 |
| 168 void ScreenLocker::Init() { | 161 void ScreenLocker::Init() { |
| 169 input_method::InputMethodManager* imm = | 162 input_method::InputMethodManager* imm = |
| 170 input_method::InputMethodManager::Get(); | 163 input_method::InputMethodManager::Get(); |
| 171 saved_ime_state_ = imm->GetActiveIMEState(); | 164 saved_ime_state_ = imm->GetActiveIMEState(); |
| 172 imm->SetState(saved_ime_state_->Clone()); | 165 imm->SetState(saved_ime_state_->Clone()); |
| 173 | 166 |
| 174 authenticator_ = UserSessionManager::GetInstance()->CreateAuthenticator(this); | 167 authenticator_ = UserSessionManager::GetInstance()->CreateAuthenticator(this); |
| 175 extended_authenticator_ = ExtendedAuthenticator::Create(this); | 168 extended_authenticator_ = ExtendedAuthenticator::Create(this); |
| 176 web_ui_.reset(new WebUIScreenLocker(this)); | 169 web_ui_.reset(new WebUIScreenLocker(this)); |
| 177 web_ui()->LockScreen(); | 170 web_ui()->LockScreen(); |
| 178 | 171 |
| 179 // Ownership of |icon_image_source| is passed. | 172 // Ownership of |icon_image_source| is passed. |
| 180 screenlock_icon_provider_.reset(new ScreenlockIconProvider); | 173 screenlock_icon_provider_.reset(new ScreenlockIconProvider); |
| 181 ScreenlockIconSource* screenlock_icon_source = | 174 ScreenlockIconSource* screenlock_icon_source = |
| 182 new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr()); | 175 new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr()); |
| 183 content::URLDataSource::Add(web_ui()->GetWebContents()->GetBrowserContext(), | 176 content::URLDataSource::Add(web_ui()->GetWebContents()->GetBrowserContext(), |
| 184 screenlock_icon_source); | 177 screenlock_icon_source); |
| 178 |
| 179 // Start locking on ash side. |
| 180 SessionControllerClient::Get()->StartLock(base::Bind( |
| 181 &ScreenLocker::OnStartLockCallback, weak_factory_.GetWeakPtr())); |
| 185 } | 182 } |
| 186 | 183 |
| 187 void ScreenLocker::OnAuthFailure(const AuthFailure& error) { | 184 void ScreenLocker::OnAuthFailure(const AuthFailure& error) { |
| 188 base::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure")); | 185 base::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure")); |
| 189 if (authentication_start_time_.is_null()) { | 186 if (authentication_start_time_.is_null()) { |
| 190 LOG(ERROR) << "Start time is not set at authentication failure"; | 187 LOG(ERROR) << "Start time is not set at authentication failure"; |
| 191 } else { | 188 } else { |
| 192 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; | 189 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; |
| 193 VLOG(1) << "Authentication failure: " << delta.InSecondsF() << " second(s)"; | 190 VLOG(1) << "Authentication failure: " << delta.InSecondsF() << " second(s)"; |
| 194 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta); | 191 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 345 |
| 349 const user_manager::User* ScreenLocker::FindUnlockUser( | 346 const user_manager::User* ScreenLocker::FindUnlockUser( |
| 350 const AccountId& account_id) { | 347 const AccountId& account_id) { |
| 351 for (const user_manager::User* user : users_) { | 348 for (const user_manager::User* user : users_) { |
| 352 if (user->GetAccountId() == account_id) | 349 if (user->GetAccountId() == account_id) |
| 353 return user; | 350 return user; |
| 354 } | 351 } |
| 355 return nullptr; | 352 return nullptr; |
| 356 } | 353 } |
| 357 | 354 |
| 355 void ScreenLocker::OnStartLockCallback(bool locked) { |
| 356 // Happens in tests that exit with a pending lock. In real lock failure, |
| 357 // ash::LockStateController would cause the current user session to be |
| 358 // terminated. |
| 359 if (!locked) |
| 360 return; |
| 361 |
| 362 web_ui()->OnLockAnimationFinished(); |
| 363 |
| 364 AccessibilityManager::Get()->PlayEarcon( |
| 365 chromeos::SOUND_LOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED); |
| 366 } |
| 367 |
| 358 void ScreenLocker::ClearErrors() { | 368 void ScreenLocker::ClearErrors() { |
| 359 web_ui()->ClearErrors(); | 369 web_ui()->ClearErrors(); |
| 360 } | 370 } |
| 361 | 371 |
| 362 void ScreenLocker::Signout() { | 372 void ScreenLocker::Signout() { |
| 363 web_ui()->ClearErrors(); | 373 web_ui()->ClearErrors(); |
| 364 base::RecordAction(UserMetricsAction("ScreenLocker_Signout")); | 374 base::RecordAction(UserMetricsAction("ScreenLocker_Signout")); |
| 365 // We expect that this call will not wait for any user input. | 375 // We expect that this call will not wait for any user input. |
| 366 // If it changes at some point, we will need to force exit. | 376 // If it changes at some point, we will need to force exit. |
| 367 chrome::AttemptUserExit(); | 377 chrome::AttemptUserExit(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 DCHECK(g_screen_lock_observer); | 415 DCHECK(g_screen_lock_observer); |
| 406 if (UserAddingScreen::Get()->IsRunning()) { | 416 if (UserAddingScreen::Get()->IsRunning()) { |
| 407 VLOG(1) << "Waiting for user adding screen to stop"; | 417 VLOG(1) << "Waiting for user adding screen to stop"; |
| 408 UserAddingScreen::Get()->AddObserver(g_screen_lock_observer); | 418 UserAddingScreen::Get()->AddObserver(g_screen_lock_observer); |
| 409 UserAddingScreen::Get()->Cancel(); | 419 UserAddingScreen::Get()->Cancel(); |
| 410 return; | 420 return; |
| 411 } | 421 } |
| 412 if (g_screen_lock_observer->session_started() && | 422 if (g_screen_lock_observer->session_started() && |
| 413 user_manager::UserManager::Get()->CanCurrentUserLock()) { | 423 user_manager::UserManager::Get()->CanCurrentUserLock()) { |
| 414 ScreenLocker::Show(); | 424 ScreenLocker::Show(); |
| 415 ash::Shell::Get()->lock_state_controller()->OnStartingLock(); | |
| 416 } else { | 425 } else { |
| 417 // If the current user's session cannot be locked or the user has not | 426 // If the current user's session cannot be locked or the user has not |
| 418 // completed all sign-in steps yet, log out instead. The latter is done to | 427 // completed all sign-in steps yet, log out instead. The latter is done to |
| 419 // avoid complications with displaying the lock screen over the login | 428 // avoid complications with displaying the lock screen over the login |
| 420 // screen while remaining secure in the case the user walks away during | 429 // screen while remaining secure in the case the user walks away during |
| 421 // the sign-in steps. See crbug.com/112225 and crbug.com/110933. | 430 // the sign-in steps. See crbug.com/112225 and crbug.com/110933. |
| 422 VLOG(1) << "Calling session manager's StopSession D-Bus method"; | 431 VLOG(1) << "Calling session manager's StopSession D-Bus method"; |
| 423 DBusThreadManager::Get()->GetSessionManagerClient()->StopSession(); | 432 DBusThreadManager::Get()->GetSessionManagerClient()->StopSession(); |
| 424 } | 433 } |
| 425 // Close captive portal window and clear signin profile. | 434 // Close captive portal window and clear signin profile. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 | 566 |
| 558 bool ScreenLocker::IsUserLoggedIn(const AccountId& account_id) const { | 567 bool ScreenLocker::IsUserLoggedIn(const AccountId& account_id) const { |
| 559 for (user_manager::User* user : users_) { | 568 for (user_manager::User* user : users_) { |
| 560 if (user->GetAccountId() == account_id) | 569 if (user->GetAccountId() == account_id) |
| 561 return true; | 570 return true; |
| 562 } | 571 } |
| 563 return false; | 572 return false; |
| 564 } | 573 } |
| 565 | 574 |
| 566 } // namespace chromeos | 575 } // namespace chromeos |
| OLD | NEW |