| 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/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 incorrect_passwords_count_ = 0; | 195 incorrect_passwords_count_ = 0; |
| 196 if (authentication_start_time_.is_null()) { | 196 if (authentication_start_time_.is_null()) { |
| 197 if (!user_context.GetUserID().empty()) | 197 if (!user_context.GetUserID().empty()) |
| 198 LOG(ERROR) << "Start time is not set at authentication success"; | 198 LOG(ERROR) << "Start time is not set at authentication success"; |
| 199 } else { | 199 } else { |
| 200 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; | 200 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; |
| 201 VLOG(1) << "Authentication success: " << delta.InSecondsF() << " second(s)"; | 201 VLOG(1) << "Authentication success: " << delta.InSecondsF() << " second(s)"; |
| 202 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationSuccessTime", delta); | 202 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationSuccessTime", delta); |
| 203 } | 203 } |
| 204 | 204 |
| 205 const User* user = UserManager::Get()->FindUser(user_context.GetUserID()); | 205 const User* user = GetUserManager()->FindUser(user_context.GetUserID()); |
| 206 if (user) { | 206 if (user) { |
| 207 if (!user->is_active()) | 207 if (!user->is_active()) |
| 208 UserManager::Get()->SwitchActiveUser(user_context.GetUserID()); | 208 GetUserManager()->SwitchActiveUser(user_context.GetUserID()); |
| 209 } else { | 209 } else { |
| 210 NOTREACHED() << "Logged in user not found."; | 210 NOTREACHED() << "Logged in user not found."; |
| 211 } | 211 } |
| 212 | 212 |
| 213 authentication_capture_.reset(new AuthenticationParametersCapture()); | 213 authentication_capture_.reset(new AuthenticationParametersCapture()); |
| 214 authentication_capture_->user_context = user_context; | 214 authentication_capture_->user_context = user_context; |
| 215 | 215 |
| 216 // Add guard for case when something get broken in call chain to unlock | 216 // Add guard for case when something get broken in call chain to unlock |
| 217 // for sure. | 217 // for sure. |
| 218 base::MessageLoop::current()->PostDelayedTask( | 218 base::MessageLoop::current()->PostDelayedTask( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 246 LOG_ASSERT(IsUserLoggedIn(user_context.GetUserID())) | 246 LOG_ASSERT(IsUserLoggedIn(user_context.GetUserID())) |
| 247 << "Invalid user trying to unlock."; | 247 << "Invalid user trying to unlock."; |
| 248 | 248 |
| 249 authentication_start_time_ = base::Time::Now(); | 249 authentication_start_time_ = base::Time::Now(); |
| 250 delegate_->SetInputEnabled(false); | 250 delegate_->SetInputEnabled(false); |
| 251 delegate_->OnAuthenticate(); | 251 delegate_->OnAuthenticate(); |
| 252 | 252 |
| 253 // Special case: supervised users. Use special authenticator. | 253 // Special case: supervised users. Use special authenticator. |
| 254 if (const User* user = FindUnlockUser(user_context.GetUserID())) { | 254 if (const User* user = FindUnlockUser(user_context.GetUserID())) { |
| 255 if (user->GetType() == user_manager::USER_TYPE_LOCALLY_MANAGED) { | 255 if (user->GetType() == user_manager::USER_TYPE_LOCALLY_MANAGED) { |
| 256 UserContext updated_context = UserManager::Get() | 256 UserContext updated_context = GetUserManager() |
| 257 ->GetSupervisedUserManager() | 257 ->GetSupervisedUserManager() |
| 258 ->GetAuthentication() | 258 ->GetAuthentication() |
| 259 ->TransformKey(user_context); | 259 ->TransformKey(user_context); |
| 260 // TODO(antrim) : replace empty closure with explicit method. | 260 // TODO(antrim) : replace empty closure with explicit method. |
| 261 // http://crbug.com/351268 | 261 // http://crbug.com/351268 |
| 262 BrowserThread::PostTask( | 262 BrowserThread::PostTask( |
| 263 BrowserThread::UI, | 263 BrowserThread::UI, |
| 264 FROM_HERE, | 264 FROM_HERE, |
| 265 base::Bind(&ExtendedAuthenticator::AuthenticateToCheck, | 265 base::Bind(&ExtendedAuthenticator::AuthenticateToCheck, |
| 266 extended_authenticator_.get(), | 266 extended_authenticator_.get(), |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 void ScreenLocker::HandleLockScreenRequest() { | 338 void ScreenLocker::HandleLockScreenRequest() { |
| 339 VLOG(1) << "Received LockScreen request from session manager"; | 339 VLOG(1) << "Received LockScreen request from session manager"; |
| 340 DCHECK(g_screen_lock_observer); | 340 DCHECK(g_screen_lock_observer); |
| 341 if (UserAddingScreen::Get()->IsRunning()) { | 341 if (UserAddingScreen::Get()->IsRunning()) { |
| 342 VLOG(1) << "Waiting for user adding screen to stop"; | 342 VLOG(1) << "Waiting for user adding screen to stop"; |
| 343 UserAddingScreen::Get()->AddObserver(g_screen_lock_observer); | 343 UserAddingScreen::Get()->AddObserver(g_screen_lock_observer); |
| 344 UserAddingScreen::Get()->Cancel(); | 344 UserAddingScreen::Get()->Cancel(); |
| 345 return; | 345 return; |
| 346 } | 346 } |
| 347 if (g_screen_lock_observer->session_started() && | 347 if (g_screen_lock_observer->session_started() && |
| 348 UserManager::Get()->CanCurrentUserLock()) { | 348 GetUserManager()->CanCurrentUserLock()) { |
| 349 ScreenLocker::Show(); | 349 ScreenLocker::Show(); |
| 350 ash::Shell::GetInstance()->lock_state_controller()->OnStartingLock(); | 350 ash::Shell::GetInstance()->lock_state_controller()->OnStartingLock(); |
| 351 } else { | 351 } else { |
| 352 // If the current user's session cannot be locked or the user has not | 352 // If the current user's session cannot be locked or the user has not |
| 353 // completed all sign-in steps yet, log out instead. The latter is done to | 353 // completed all sign-in steps yet, log out instead. The latter is done to |
| 354 // avoid complications with displaying the lock screen over the login | 354 // avoid complications with displaying the lock screen over the login |
| 355 // screen while remaining secure in the case the user walks away during | 355 // screen while remaining secure in the case the user walks away during |
| 356 // the sign-in steps. See crbug.com/112225 and crbug.com/110933. | 356 // the sign-in steps. See crbug.com/112225 and crbug.com/110933. |
| 357 VLOG(1) << "Calling session manager's StopSession D-Bus method"; | 357 VLOG(1) << "Calling session manager's StopSession D-Bus method"; |
| 358 DBusThreadManager::Get()->GetSessionManagerClient()->StopSession(); | 358 DBusThreadManager::Get()->GetSessionManagerClient()->StopSession(); |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 | 361 |
| 362 // static | 362 // static |
| 363 void ScreenLocker::Show() { | 363 void ScreenLocker::Show() { |
| 364 content::RecordAction(UserMetricsAction("ScreenLocker_Show")); | 364 content::RecordAction(UserMetricsAction("ScreenLocker_Show")); |
| 365 DCHECK(base::MessageLoopForUI::IsCurrent()); | 365 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 366 | 366 |
| 367 // Check whether the currently logged in user is a guest account and if so, | 367 // Check whether the currently logged in user is a guest account and if so, |
| 368 // refuse to lock the screen (crosbug.com/23764). | 368 // refuse to lock the screen (crosbug.com/23764). |
| 369 // For a demo user, we should never show the lock screen (crosbug.com/27647). | 369 // For a demo user, we should never show the lock screen (crosbug.com/27647). |
| 370 if (UserManager::Get()->IsLoggedInAsGuest() || | 370 if (GetUserManager()->IsLoggedInAsGuest() || |
| 371 UserManager::Get()->IsLoggedInAsDemoUser()) { | 371 GetUserManager()->IsLoggedInAsDemoUser()) { |
| 372 VLOG(1) << "Refusing to lock screen for guest/demo account"; | 372 VLOG(1) << "Refusing to lock screen for guest/demo account"; |
| 373 return; | 373 return; |
| 374 } | 374 } |
| 375 | 375 |
| 376 // If the active window is fullscreen, exit fullscreen to avoid the web page | 376 // If the active window is fullscreen, exit fullscreen to avoid the web page |
| 377 // or app mimicking the lock screen. Do not exit fullscreen if the shelf is | 377 // or app mimicking the lock screen. Do not exit fullscreen if the shelf is |
| 378 // visible while in fullscreen because the shelf makes it harder for a web | 378 // visible while in fullscreen because the shelf makes it harder for a web |
| 379 // page or app to mimick the lock screen. | 379 // page or app to mimick the lock screen. |
| 380 ash::wm::WindowState* active_window_state = ash::wm::GetActiveWindowState(); | 380 ash::wm::WindowState* active_window_state = ash::wm::GetActiveWindowState(); |
| 381 if (active_window_state && | 381 if (active_window_state && |
| 382 active_window_state->IsFullscreen() && | 382 active_window_state->IsFullscreen() && |
| 383 active_window_state->hide_shelf_when_fullscreen()) { | 383 active_window_state->hide_shelf_when_fullscreen()) { |
| 384 const ash::wm::WMEvent event(ash::wm::WM_EVENT_TOGGLE_FULLSCREEN); | 384 const ash::wm::WMEvent event(ash::wm::WM_EVENT_TOGGLE_FULLSCREEN); |
| 385 active_window_state->OnWMEvent(&event); | 385 active_window_state->OnWMEvent(&event); |
| 386 } | 386 } |
| 387 | 387 |
| 388 if (!screen_locker_) { | 388 if (!screen_locker_) { |
| 389 ScreenLocker* locker = | 389 ScreenLocker* locker = new ScreenLocker(GetUserManager()->GetUnlockUsers()); |
| 390 new ScreenLocker(UserManager::Get()->GetUnlockUsers()); | |
| 391 VLOG(1) << "Created ScreenLocker " << locker; | 390 VLOG(1) << "Created ScreenLocker " << locker; |
| 392 locker->Init(); | 391 locker->Init(); |
| 393 } else { | 392 } else { |
| 394 VLOG(1) << "ScreenLocker " << screen_locker_ << " already exists; " | 393 VLOG(1) << "ScreenLocker " << screen_locker_ << " already exists; " |
| 395 << " calling session manager's HandleLockScreenShown D-Bus method"; | 394 << " calling session manager's HandleLockScreenShown D-Bus method"; |
| 396 DBusThreadManager::Get()->GetSessionManagerClient()-> | 395 DBusThreadManager::Get()->GetSessionManagerClient()-> |
| 397 NotifyLockScreenShown(); | 396 NotifyLockScreenShown(); |
| 398 } | 397 } |
| 399 } | 398 } |
| 400 | 399 |
| 401 // static | 400 // static |
| 402 void ScreenLocker::Hide() { | 401 void ScreenLocker::Hide() { |
| 403 DCHECK(base::MessageLoopForUI::IsCurrent()); | 402 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 404 // For a guest/demo user, screen_locker_ would have never been initialized. | 403 // For a guest/demo user, screen_locker_ would have never been initialized. |
| 405 if (UserManager::Get()->IsLoggedInAsGuest() || | 404 if (GetUserManager()->IsLoggedInAsGuest() || |
| 406 UserManager::Get()->IsLoggedInAsDemoUser()) { | 405 GetUserManager()->IsLoggedInAsDemoUser()) { |
| 407 VLOG(1) << "Refusing to hide lock screen for guest/demo account"; | 406 VLOG(1) << "Refusing to hide lock screen for guest/demo account"; |
| 408 return; | 407 return; |
| 409 } | 408 } |
| 410 | 409 |
| 411 DCHECK(screen_locker_); | 410 DCHECK(screen_locker_); |
| 412 base::Callback<void(void)> callback = | 411 base::Callback<void(void)> callback = |
| 413 base::Bind(&ScreenLocker::ScheduleDeletion); | 412 base::Bind(&ScreenLocker::ScheduleDeletion); |
| 414 ash::Shell::GetInstance()->lock_state_controller()-> | 413 ash::Shell::GetInstance()->lock_state_controller()-> |
| 415 OnLockScreenHide(callback); | 414 OnLockScreenHide(callback); |
| 416 } | 415 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 | 485 |
| 487 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { | 486 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { |
| 488 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { | 487 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { |
| 489 if ((*it)->email() == username) | 488 if ((*it)->email() == username) |
| 490 return true; | 489 return true; |
| 491 } | 490 } |
| 492 return false; | 491 return false; |
| 493 } | 492 } |
| 494 | 493 |
| 495 } // namespace chromeos | 494 } // namespace chromeos |
| OLD | NEW |