OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/chromeos/login/screen_locker.h" | |
6 | |
7 #include <string> | |
8 #include <vector> | |
9 | |
10 #include "ash/ash_switches.h" | |
11 #include "ash/audio/sounds.h" | |
12 #include "ash/desktop_background/desktop_background_controller.h" | |
13 #include "ash/shell.h" | |
14 #include "ash/wm/lock_state_controller.h" | |
15 #include "ash/wm/window_state.h" | |
16 #include "ash/wm/window_util.h" | |
17 #include "ash/wm/wm_event.h" | |
18 #include "base/bind.h" | |
19 #include "base/command_line.h" | |
20 #include "base/lazy_instance.h" | |
21 #include "base/memory/weak_ptr.h" | |
22 #include "base/message_loop/message_loop.h" | |
23 #include "base/metrics/histogram.h" | |
24 #include "base/strings/string_number_conversions.h" | |
25 #include "base/strings/string_util.h" | |
26 #include "base/timer/timer.h" | |
27 #include "chrome/browser/chrome_notification_types.h" | |
28 #include "chrome/browser/chromeos/login/authenticator.h" | |
29 #include "chrome/browser/chromeos/login/extended_authenticator.h" | |
30 #include "chrome/browser/chromeos/login/login_performer.h" | |
31 #include "chrome/browser/chromeos/login/login_utils.h" | |
32 #include "chrome/browser/chromeos/login/managed/supervised_user_authentication.h
" | |
33 #include "chrome/browser/chromeos/login/supervised_user_manager.h" | |
34 #include "chrome/browser/chromeos/login/user_adding_screen.h" | |
35 #include "chrome/browser/chromeos/login/user_manager.h" | |
36 #include "chrome/browser/chromeos/login/webui_screen_locker.h" | |
37 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap
i.h" | |
38 #include "chrome/browser/lifetime/application_lifetime.h" | |
39 #include "chrome/browser/profiles/profile.h" | |
40 #include "chrome/browser/profiles/profile_manager.h" | |
41 #include "chrome/browser/signin/signin_manager_factory.h" | |
42 #include "chrome/browser/sync/profile_sync_service.h" | |
43 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
44 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.h" | |
45 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h" | |
46 #include "chrome/common/chrome_switches.h" | |
47 #include "chromeos/audio/chromeos_sounds.h" | |
48 #include "chromeos/dbus/dbus_thread_manager.h" | |
49 #include "chromeos/dbus/session_manager_client.h" | |
50 #include "components/signin/core/browser/signin_manager.h" | |
51 #include "content/public/browser/browser_thread.h" | |
52 #include "content/public/browser/notification_service.h" | |
53 #include "content/public/browser/url_data_source.h" | |
54 #include "content/public/browser/user_metrics.h" | |
55 #include "grit/browser_resources.h" | |
56 #include "grit/generated_resources.h" | |
57 #include "media/audio/sounds/sounds_manager.h" | |
58 #include "ui/base/l10n/l10n_util.h" | |
59 #include "ui/base/resource/resource_bundle.h" | |
60 #include "ui/gfx/image/image.h" | |
61 #include "url/gurl.h" | |
62 | |
63 using base::UserMetricsAction; | |
64 using content::BrowserThread; | |
65 | |
66 namespace chromeos { | |
67 | |
68 namespace { | |
69 | |
70 // Timeout for unlock animation guard - some animations may be required to run | |
71 // on successful authentication before unlocking, but we want to be sure that | |
72 // unlock happens even if animations are broken. | |
73 const int kUnlockGuardTimeoutMs = 400; | |
74 | |
75 // Observer to start ScreenLocker when locking the screen is requested. | |
76 class ScreenLockObserver : public SessionManagerClient::StubDelegate, | |
77 public content::NotificationObserver, | |
78 public UserAddingScreen::Observer { | |
79 public: | |
80 ScreenLockObserver() : session_started_(false) { | |
81 registrar_.Add(this, | |
82 chrome::NOTIFICATION_SESSION_STARTED, | |
83 content::NotificationService::AllSources()); | |
84 DBusThreadManager::Get()->GetSessionManagerClient()->SetStubDelegate(this); | |
85 } | |
86 | |
87 virtual ~ScreenLockObserver() { | |
88 if (DBusThreadManager::IsInitialized()) { | |
89 DBusThreadManager::Get()->GetSessionManagerClient()->SetStubDelegate( | |
90 NULL); | |
91 } | |
92 } | |
93 | |
94 bool session_started() const { return session_started_; } | |
95 | |
96 // SessionManagerClient::StubDelegate overrides: | |
97 virtual void LockScreenForStub() OVERRIDE { | |
98 ScreenLocker::HandleLockScreenRequest(); | |
99 } | |
100 | |
101 // NotificationObserver overrides: | |
102 virtual void Observe(int type, | |
103 const content::NotificationSource& source, | |
104 const content::NotificationDetails& details) OVERRIDE { | |
105 if (type == chrome::NOTIFICATION_SESSION_STARTED) | |
106 session_started_ = true; | |
107 else | |
108 NOTREACHED() << "Unexpected notification " << type; | |
109 } | |
110 | |
111 // UserAddingScreen::Observer overrides: | |
112 virtual void OnUserAddingFinished() OVERRIDE { | |
113 UserAddingScreen::Get()->RemoveObserver(this); | |
114 ScreenLocker::HandleLockScreenRequest(); | |
115 } | |
116 | |
117 private: | |
118 bool session_started_; | |
119 content::NotificationRegistrar registrar_; | |
120 | |
121 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); | |
122 }; | |
123 | |
124 ScreenLockObserver* g_screen_lock_observer = NULL; | |
125 | |
126 // TODO(xiyuan): Get rid of LoginDisplay::AuthType and the mappers below. | |
127 ScreenlockBridge::LockHandler::AuthType ToLockHandlerAuthType( | |
128 LoginDisplay::AuthType auth_type) { | |
129 switch (auth_type) { | |
130 case LoginDisplay::OFFLINE_PASSWORD: | |
131 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; | |
132 case LoginDisplay::ONLINE_SIGN_IN: | |
133 return ScreenlockBridge::LockHandler::ONLINE_SIGN_IN; | |
134 case LoginDisplay::NUMERIC_PIN: | |
135 return ScreenlockBridge::LockHandler::NUMERIC_PIN; | |
136 case LoginDisplay::USER_CLICK: | |
137 return ScreenlockBridge::LockHandler::USER_CLICK; | |
138 } | |
139 NOTREACHED(); | |
140 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; | |
141 } | |
142 | |
143 LoginDisplay::AuthType FromLockHandlerAuthType( | |
144 ScreenlockBridge::LockHandler::AuthType auth_type) { | |
145 switch (auth_type) { | |
146 case ScreenlockBridge::LockHandler::OFFLINE_PASSWORD: | |
147 return LoginDisplay::OFFLINE_PASSWORD; | |
148 case ScreenlockBridge::LockHandler::ONLINE_SIGN_IN: | |
149 return LoginDisplay::ONLINE_SIGN_IN; | |
150 case ScreenlockBridge::LockHandler::NUMERIC_PIN: | |
151 return LoginDisplay::NUMERIC_PIN; | |
152 case ScreenlockBridge::LockHandler::USER_CLICK: | |
153 return LoginDisplay::USER_CLICK; | |
154 } | |
155 NOTREACHED(); | |
156 return LoginDisplay::OFFLINE_PASSWORD; | |
157 } | |
158 | |
159 } // namespace | |
160 | |
161 // static | |
162 ScreenLocker* ScreenLocker::screen_locker_ = NULL; | |
163 | |
164 ////////////////////////////////////////////////////////////////////////////// | |
165 // ScreenLocker, public: | |
166 | |
167 ScreenLocker::ScreenLocker(const UserList& users) | |
168 : users_(users), | |
169 locked_(false), | |
170 start_time_(base::Time::Now()), | |
171 login_status_consumer_(NULL), | |
172 incorrect_passwords_count_(0), | |
173 weak_factory_(this) { | |
174 DCHECK(!screen_locker_); | |
175 screen_locker_ = this; | |
176 | |
177 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
178 media::SoundsManager* manager = media::SoundsManager::Get(); | |
179 manager->Initialize(SOUND_LOCK, | |
180 bundle.GetRawDataResource(IDR_SOUND_LOCK_WAV)); | |
181 manager->Initialize(SOUND_UNLOCK, | |
182 bundle.GetRawDataResource(IDR_SOUND_UNLOCK_WAV)); | |
183 | |
184 ash::Shell::GetInstance()-> | |
185 lock_state_controller()->SetLockScreenDisplayedCallback( | |
186 base::Bind(base::IgnoreResult(&ash::PlaySystemSoundIfSpokenFeedback), | |
187 static_cast<media::SoundsManager::SoundKey>( | |
188 chromeos::SOUND_LOCK))); | |
189 } | |
190 | |
191 void ScreenLocker::Init() { | |
192 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); | |
193 extended_authenticator_ = new ExtendedAuthenticator(this); | |
194 delegate_.reset(new WebUIScreenLocker(this)); | |
195 delegate_->LockScreen(); | |
196 | |
197 // Ownership of |icon_image_source| is passed. | |
198 screenlock_icon_provider_.reset(new ScreenlockIconProvider); | |
199 ScreenlockIconSource* screenlock_icon_source = | |
200 new ScreenlockIconSource(screenlock_icon_provider_->AsWeakPtr()); | |
201 content::URLDataSource::Add( | |
202 Profile::FromWebUI(GetAssociatedWebUI()), | |
203 screenlock_icon_source); | |
204 } | |
205 | |
206 void ScreenLocker::OnLoginFailure(const LoginFailure& error) { | |
207 content::RecordAction(UserMetricsAction("ScreenLocker_OnLoginFailure")); | |
208 if (authentication_start_time_.is_null()) { | |
209 LOG(ERROR) << "Start time is not set at authentication failure"; | |
210 } else { | |
211 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; | |
212 VLOG(1) << "Authentication failure: " << delta.InSecondsF() << " second(s)"; | |
213 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta); | |
214 } | |
215 | |
216 EnableInput(); | |
217 // Don't enable signout button here as we're showing | |
218 // MessageBubble. | |
219 | |
220 delegate_->ShowErrorMessage(incorrect_passwords_count_++ ? | |
221 IDS_LOGIN_ERROR_AUTHENTICATING_2ND_TIME : | |
222 IDS_LOGIN_ERROR_AUTHENTICATING, | |
223 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); | |
224 | |
225 if (login_status_consumer_) | |
226 login_status_consumer_->OnLoginFailure(error); | |
227 } | |
228 | |
229 void ScreenLocker::OnLoginSuccess(const UserContext& user_context) { | |
230 incorrect_passwords_count_ = 0; | |
231 if (authentication_start_time_.is_null()) { | |
232 if (!user_context.GetUserID().empty()) | |
233 LOG(ERROR) << "Start time is not set at authentication success"; | |
234 } else { | |
235 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; | |
236 VLOG(1) << "Authentication success: " << delta.InSecondsF() << " second(s)"; | |
237 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationSuccessTime", delta); | |
238 } | |
239 | |
240 const User* user = UserManager::Get()->FindUser(user_context.GetUserID()); | |
241 if (user) { | |
242 if (!user->is_active()) | |
243 UserManager::Get()->SwitchActiveUser(user_context.GetUserID()); | |
244 } else { | |
245 NOTREACHED() << "Logged in user not found."; | |
246 } | |
247 | |
248 authentication_capture_.reset(new AuthenticationParametersCapture()); | |
249 authentication_capture_->user_context = user_context; | |
250 | |
251 // Add guard for case when something get broken in call chain to unlock | |
252 // for sure. | |
253 base::MessageLoop::current()->PostDelayedTask( | |
254 FROM_HERE, | |
255 base::Bind(&ScreenLocker::UnlockOnLoginSuccess, | |
256 weak_factory_.GetWeakPtr()), | |
257 base::TimeDelta::FromMilliseconds(kUnlockGuardTimeoutMs)); | |
258 delegate_->AnimateAuthenticationSuccess(); | |
259 } | |
260 | |
261 void ScreenLocker::UnlockOnLoginSuccess() { | |
262 DCHECK(base::MessageLoopForUI::IsCurrent()); | |
263 if (!authentication_capture_.get()) { | |
264 LOG(WARNING) << "Call to UnlockOnLoginSuccess without previous " << | |
265 "authentication success."; | |
266 return; | |
267 } | |
268 | |
269 if (login_status_consumer_) { | |
270 login_status_consumer_->OnLoginSuccess( | |
271 UserContext(authentication_capture_->user_context.GetUserID(), | |
272 authentication_capture_->user_context.GetPassword(), | |
273 authentication_capture_->user_context.GetAuthCode(), | |
274 authentication_capture_->user_context.GetUserIDHash(), | |
275 authentication_capture_->user_context.IsUsingOAuth(), | |
276 authentication_capture_->user_context.GetAuthFlow())); | |
277 } | |
278 authentication_capture_.reset(); | |
279 weak_factory_.InvalidateWeakPtrs(); | |
280 | |
281 VLOG(1) << "Hiding the lock screen."; | |
282 chromeos::ScreenLocker::Hide(); | |
283 } | |
284 | |
285 void ScreenLocker::Authenticate(const UserContext& user_context) { | |
286 LOG_ASSERT(IsUserLoggedIn(user_context.GetUserID())) | |
287 << "Invalid user trying to unlock."; | |
288 | |
289 authentication_start_time_ = base::Time::Now(); | |
290 delegate_->SetInputEnabled(false); | |
291 delegate_->OnAuthenticate(); | |
292 | |
293 // Send authentication request to chrome.screenlockPrivate API event router | |
294 // if the authentication type is not the system password. | |
295 LoginDisplay::AuthType auth_type = | |
296 FromLockHandlerAuthType(GetAuthType(user_context.GetUserID())); | |
297 if (auth_type != LoginDisplay::OFFLINE_PASSWORD) { | |
298 const User* unlock_user = FindUnlockUser(user_context.GetUserID()); | |
299 LOG_ASSERT(unlock_user); | |
300 | |
301 Profile* profile = UserManager::Get()->GetProfileByUser(unlock_user); | |
302 extensions::ScreenlockPrivateEventRouter* router = | |
303 extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( | |
304 profile); | |
305 router->OnAuthAttempted(ToLockHandlerAuthType(auth_type), | |
306 user_context.GetPassword()); | |
307 return; | |
308 } | |
309 | |
310 // Special case: supervised users. Use special authenticator. | |
311 if (const User* user = FindUnlockUser(user_context.GetUserID())) { | |
312 if (user->GetType() == User::USER_TYPE_LOCALLY_MANAGED) { | |
313 UserContext updated_context = | |
314 UserManager::Get() | |
315 ->GetSupervisedUserManager() | |
316 ->GetAuthentication() | |
317 ->TransformPasswordInContext(user_context); | |
318 // TODO(antrim) : replace empty closure with explicit method. | |
319 // http://crbug.com/351268 | |
320 BrowserThread::PostTask( | |
321 BrowserThread::UI, | |
322 FROM_HERE, | |
323 base::Bind(&ExtendedAuthenticator::AuthenticateToCheck, | |
324 extended_authenticator_.get(), | |
325 updated_context, | |
326 base::Closure())); | |
327 return; | |
328 } | |
329 } | |
330 | |
331 // TODO(antrim) : migrate to new authenticator for all types of users. | |
332 // http://crbug.com/351268 | |
333 BrowserThread::PostTask( | |
334 BrowserThread::UI, FROM_HERE, | |
335 base::Bind(&Authenticator::AuthenticateToUnlock, | |
336 authenticator_.get(), | |
337 user_context)); | |
338 } | |
339 | |
340 const User* ScreenLocker::FindUnlockUser(const std::string& user_id) { | |
341 const User* unlock_user = NULL; | |
342 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { | |
343 if ((*it)->email() == user_id) { | |
344 unlock_user = *it; | |
345 break; | |
346 } | |
347 } | |
348 return unlock_user; | |
349 } | |
350 | |
351 void ScreenLocker::ClearErrors() { | |
352 delegate_->ClearErrors(); | |
353 } | |
354 | |
355 void ScreenLocker::Signout() { | |
356 delegate_->ClearErrors(); | |
357 content::RecordAction(UserMetricsAction("ScreenLocker_Signout")); | |
358 // We expect that this call will not wait for any user input. | |
359 // If it changes at some point, we will need to force exit. | |
360 chrome::AttemptUserExit(); | |
361 | |
362 // Don't hide yet the locker because the chrome screen may become visible | |
363 // briefly. | |
364 } | |
365 | |
366 void ScreenLocker::ShowBannerMessage(const std::string& message) { | |
367 delegate_->ShowBannerMessage(message); | |
368 } | |
369 | |
370 void ScreenLocker::ShowUserPodButton(const std::string& username, | |
371 const gfx::Image& icon, | |
372 const base::Closure& click_callback) { | |
373 if (!locked_) | |
374 return; | |
375 | |
376 screenlock_icon_provider_->AddIcon(username, icon); | |
377 | |
378 if (!username.empty()) { | |
379 // Append the current time to the URL so the image will not be cached. | |
380 std::string icon_url = | |
381 ScreenlockIconSource::GetIconURLForUser(username) + "?uniq=" + | |
382 base::Int64ToString(base::Time::Now().ToInternalValue()); | |
383 delegate_->ShowUserPodButton(username, icon_url, click_callback); | |
384 } | |
385 } | |
386 | |
387 void ScreenLocker::HideUserPodButton(const std::string& username) { | |
388 if (!locked_) | |
389 return; | |
390 screenlock_icon_provider_->RemoveIcon(username); | |
391 delegate_->HideUserPodButton(username); | |
392 } | |
393 | |
394 void ScreenLocker::EnableInput() { | |
395 delegate_->SetInputEnabled(true); | |
396 } | |
397 | |
398 void ScreenLocker::SetAuthType( | |
399 const std::string& username, | |
400 ScreenlockBridge::LockHandler::AuthType auth_type, | |
401 const std::string& initial_value) { | |
402 if (!locked_) | |
403 return; | |
404 delegate_->SetAuthType( | |
405 username, FromLockHandlerAuthType(auth_type), initial_value); | |
406 } | |
407 | |
408 ScreenlockBridge::LockHandler::AuthType ScreenLocker::GetAuthType( | |
409 const std::string& username) const { | |
410 // Return default authentication type when not locked. | |
411 if (!locked_) | |
412 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; | |
413 return ToLockHandlerAuthType(delegate_->GetAuthType(username)); | |
414 } | |
415 | |
416 void ScreenLocker::Unlock(const std::string& user_email) { | |
417 chromeos::ScreenLocker::Hide(); | |
418 } | |
419 | |
420 void ScreenLocker::ShowErrorMessage(int error_msg_id, | |
421 HelpAppLauncher::HelpTopic help_topic_id, | |
422 bool sign_out_only) { | |
423 delegate_->SetInputEnabled(!sign_out_only); | |
424 delegate_->ShowErrorMessage(error_msg_id, help_topic_id); | |
425 } | |
426 | |
427 void ScreenLocker::SetLoginStatusConsumer( | |
428 chromeos::LoginStatusConsumer* consumer) { | |
429 login_status_consumer_ = consumer; | |
430 } | |
431 | |
432 // static | |
433 void ScreenLocker::InitClass() { | |
434 DCHECK(!g_screen_lock_observer); | |
435 g_screen_lock_observer = new ScreenLockObserver; | |
436 } | |
437 | |
438 // static | |
439 void ScreenLocker::ShutDownClass() { | |
440 DCHECK(g_screen_lock_observer); | |
441 delete g_screen_lock_observer; | |
442 g_screen_lock_observer = NULL; | |
443 } | |
444 | |
445 // static | |
446 void ScreenLocker::HandleLockScreenRequest() { | |
447 VLOG(1) << "Received LockScreen request from session manager"; | |
448 DCHECK(g_screen_lock_observer); | |
449 if (UserAddingScreen::Get()->IsRunning()) { | |
450 VLOG(1) << "Waiting for user adding screen to stop"; | |
451 UserAddingScreen::Get()->AddObserver(g_screen_lock_observer); | |
452 UserAddingScreen::Get()->Cancel(); | |
453 return; | |
454 } | |
455 if (g_screen_lock_observer->session_started() && | |
456 UserManager::Get()->CanCurrentUserLock()) { | |
457 ScreenLocker::Show(); | |
458 ash::Shell::GetInstance()->lock_state_controller()->OnStartingLock(); | |
459 } else { | |
460 // If the current user's session cannot be locked or the user has not | |
461 // completed all sign-in steps yet, log out instead. The latter is done to | |
462 // avoid complications with displaying the lock screen over the login | |
463 // screen while remaining secure in the case the user walks away during | |
464 // the sign-in steps. See crbug.com/112225 and crbug.com/110933. | |
465 VLOG(1) << "Calling session manager's StopSession D-Bus method"; | |
466 DBusThreadManager::Get()->GetSessionManagerClient()->StopSession(); | |
467 } | |
468 } | |
469 | |
470 // static | |
471 void ScreenLocker::Show() { | |
472 content::RecordAction(UserMetricsAction("ScreenLocker_Show")); | |
473 DCHECK(base::MessageLoopForUI::IsCurrent()); | |
474 | |
475 // Check whether the currently logged in user is a guest account and if so, | |
476 // refuse to lock the screen (crosbug.com/23764). | |
477 // For a demo user, we should never show the lock screen (crosbug.com/27647). | |
478 if (UserManager::Get()->IsLoggedInAsGuest() || | |
479 UserManager::Get()->IsLoggedInAsDemoUser()) { | |
480 VLOG(1) << "Refusing to lock screen for guest/demo account"; | |
481 return; | |
482 } | |
483 | |
484 // If the active window is fullscreen, exit fullscreen to avoid the web page | |
485 // or app mimicking the lock screen. Do not exit fullscreen if the shelf is | |
486 // visible while in fullscreen because the shelf makes it harder for a web | |
487 // page or app to mimick the lock screen. | |
488 ash::wm::WindowState* active_window_state = ash::wm::GetActiveWindowState(); | |
489 if (active_window_state && | |
490 active_window_state->IsFullscreen() && | |
491 active_window_state->hide_shelf_when_fullscreen()) { | |
492 const ash::wm::WMEvent event(ash::wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
493 active_window_state->OnWMEvent(&event); | |
494 } | |
495 | |
496 if (!screen_locker_) { | |
497 ScreenLocker* locker = | |
498 new ScreenLocker(UserManager::Get()->GetUnlockUsers()); | |
499 VLOG(1) << "Created ScreenLocker " << locker; | |
500 locker->Init(); | |
501 } else { | |
502 VLOG(1) << "ScreenLocker " << screen_locker_ << " already exists; " | |
503 << " calling session manager's HandleLockScreenShown D-Bus method"; | |
504 DBusThreadManager::Get()->GetSessionManagerClient()-> | |
505 NotifyLockScreenShown(); | |
506 } | |
507 } | |
508 | |
509 // static | |
510 void ScreenLocker::Hide() { | |
511 DCHECK(base::MessageLoopForUI::IsCurrent()); | |
512 // For a guest/demo user, screen_locker_ would have never been initialized. | |
513 if (UserManager::Get()->IsLoggedInAsGuest() || | |
514 UserManager::Get()->IsLoggedInAsDemoUser()) { | |
515 VLOG(1) << "Refusing to hide lock screen for guest/demo account"; | |
516 return; | |
517 } | |
518 | |
519 DCHECK(screen_locker_); | |
520 base::Callback<void(void)> callback = | |
521 base::Bind(&ScreenLocker::ScheduleDeletion); | |
522 ash::Shell::GetInstance()->lock_state_controller()-> | |
523 OnLockScreenHide(callback); | |
524 } | |
525 | |
526 void ScreenLocker::ScheduleDeletion() { | |
527 // Avoid possible multiple calls. | |
528 if (screen_locker_ == NULL) | |
529 return; | |
530 VLOG(1) << "Deleting ScreenLocker " << screen_locker_; | |
531 | |
532 ash::PlaySystemSoundIfSpokenFeedback(SOUND_UNLOCK); | |
533 | |
534 delete screen_locker_; | |
535 screen_locker_ = NULL; | |
536 } | |
537 | |
538 //////////////////////////////////////////////////////////////////////////////// | |
539 // ScreenLocker, private: | |
540 | |
541 ScreenLocker::~ScreenLocker() { | |
542 VLOG(1) << "Destroying ScreenLocker " << this; | |
543 DCHECK(base::MessageLoopForUI::IsCurrent()); | |
544 | |
545 if (authenticator_.get()) | |
546 authenticator_->SetConsumer(NULL); | |
547 ClearErrors(); | |
548 | |
549 VLOG(1) << "Moving desktop background to unlocked container"; | |
550 ash::Shell::GetInstance()-> | |
551 desktop_background_controller()->MoveDesktopToUnlockedContainer(); | |
552 | |
553 screen_locker_ = NULL; | |
554 bool state = false; | |
555 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; | |
556 content::NotificationService::current()->Notify( | |
557 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | |
558 content::Source<ScreenLocker>(this), | |
559 content::Details<bool>(&state)); | |
560 | |
561 VLOG(1) << "Calling session manager's HandleLockScreenDismissed D-Bus method"; | |
562 DBusThreadManager::Get()->GetSessionManagerClient()-> | |
563 NotifyLockScreenDismissed(); | |
564 | |
565 ScreenlockBridge::Get()->SetLockHandler(NULL); | |
566 } | |
567 | |
568 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) { | |
569 authenticator_ = authenticator; | |
570 } | |
571 | |
572 void ScreenLocker::ScreenLockReady() { | |
573 locked_ = true; | |
574 base::TimeDelta delta = base::Time::Now() - start_time_; | |
575 VLOG(1) << "ScreenLocker " << this << " is ready after " | |
576 << delta.InSecondsF() << " second(s)"; | |
577 UMA_HISTOGRAM_TIMES("ScreenLocker.ScreenLockTime", delta); | |
578 | |
579 VLOG(1) << "Moving desktop background to locked container"; | |
580 ash::Shell::GetInstance()-> | |
581 desktop_background_controller()->MoveDesktopToLockedContainer(); | |
582 | |
583 bool state = true; | |
584 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; | |
585 content::NotificationService::current()->Notify( | |
586 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | |
587 content::Source<ScreenLocker>(this), | |
588 content::Details<bool>(&state)); | |
589 VLOG(1) << "Calling session manager's HandleLockScreenShown D-Bus method"; | |
590 DBusThreadManager::Get()->GetSessionManagerClient()->NotifyLockScreenShown(); | |
591 | |
592 ScreenlockBridge::Get()->SetLockHandler(this); | |
593 } | |
594 | |
595 content::WebUI* ScreenLocker::GetAssociatedWebUI() { | |
596 return delegate_->GetAssociatedWebUI(); | |
597 } | |
598 | |
599 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { | |
600 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { | |
601 if ((*it)->email() == username) | |
602 return true; | |
603 } | |
604 return false; | |
605 } | |
606 | |
607 } // namespace chromeos | |
OLD | NEW |