OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/screen_locker.h" | 5 #include "chrome/browser/chromeos/login/screen_locker.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/timer.h" | 17 #include "base/timer.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 20 #include "chrome/browser/chromeos/cros/screen_lock_library.h" |
19 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 21 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
20 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | |
21 #include "chrome/browser/chromeos/dbus/session_manager_client.h" | 22 #include "chrome/browser/chromeos/dbus/session_manager_client.h" |
22 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 23 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
23 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 24 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
24 #include "chrome/browser/chromeos/input_method/xkeyboard.h" | 25 #include "chrome/browser/chromeos/input_method/xkeyboard.h" |
25 #include "chrome/browser/chromeos/language_preferences.h" | 26 #include "chrome/browser/chromeos/language_preferences.h" |
26 #include "chrome/browser/chromeos/login/authenticator.h" | 27 #include "chrome/browser/chromeos/login/authenticator.h" |
27 #include "chrome/browser/chromeos/login/login_performer.h" | 28 #include "chrome/browser/chromeos/login/login_performer.h" |
28 #include "chrome/browser/chromeos/login/login_utils.h" | 29 #include "chrome/browser/chromeos/login/login_utils.h" |
29 #include "chrome/browser/chromeos/login/screen_locker_views.h" | 30 #include "chrome/browser/chromeos/login/screen_locker_views.h" |
30 #include "chrome/browser/chromeos/login/user_manager.h" | 31 #include "chrome/browser/chromeos/login/user_manager.h" |
(...skipping 16 matching lines...) Expand all Loading... |
47 | 48 |
48 #if defined(TOOLKIT_USES_GTK) | 49 #if defined(TOOLKIT_USES_GTK) |
49 #include "chrome/browser/chromeos/legacy_window_manager/wm_ipc.h" | 50 #include "chrome/browser/chromeos/legacy_window_manager/wm_ipc.h" |
50 #endif | 51 #endif |
51 | 52 |
52 using content::BrowserThread; | 53 using content::BrowserThread; |
53 | 54 |
54 namespace { | 55 namespace { |
55 | 56 |
56 // Observer to start ScreenLocker when the screen lock | 57 // Observer to start ScreenLocker when the screen lock |
57 class ScreenLockObserver : public chromeos::PowerManagerClient::Observer, | 58 class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer, |
58 public content::NotificationObserver { | 59 public content::NotificationObserver { |
59 public: | 60 public: |
60 ScreenLockObserver() { | 61 ScreenLockObserver() { |
61 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 62 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
62 content::NotificationService::AllSources()); | 63 content::NotificationService::AllSources()); |
63 } | 64 } |
64 | 65 |
65 // NotificationObserver overrides: | 66 // NotificationObserver overrides: |
66 virtual void Observe(int type, | 67 virtual void Observe(int type, |
67 const content::NotificationSource& source, | 68 const content::NotificationSource& source, |
68 const content::NotificationDetails& details) OVERRIDE { | 69 const content::NotificationDetails& details) OVERRIDE { |
69 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { | 70 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { |
70 // Register Screen Lock after login screen to make sure | 71 // Register Screen Lock after login screen to make sure |
71 // we don't show the screen lock on top of the login screen by accident. | 72 // we don't show the screen lock on top of the login screen by accident. |
72 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 73 chromeos::CrosLibrary::Get()->GetScreenLockLibrary()->AddObserver(this); |
73 AddObserver(this); | |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 virtual void LockScreen() OVERRIDE { | 77 virtual void LockScreen(chromeos::ScreenLockLibrary* obj) OVERRIDE { |
78 VLOG(1) << "In: ScreenLockObserver::LockScreen"; | 78 VLOG(1) << "In: ScreenLockObserver::LockScreen"; |
79 SetupInputMethodsForScreenLocker(); | 79 SetupInputMethodsForScreenLocker(); |
80 chromeos::ScreenLocker::Show(); | 80 chromeos::ScreenLocker::Show(); |
81 } | 81 } |
82 | 82 |
83 virtual void UnlockScreen() OVERRIDE { | 83 virtual void UnlockScreen(chromeos::ScreenLockLibrary* obj) OVERRIDE { |
84 RestoreInputMethods(); | 84 RestoreInputMethods(); |
85 chromeos::ScreenLocker::Hide(); | 85 chromeos::ScreenLocker::Hide(); |
86 } | 86 } |
87 | 87 |
88 virtual void UnlockScreenFailed() OVERRIDE { | 88 virtual void UnlockScreenFailed(chromeos::ScreenLockLibrary* obj) OVERRIDE { |
89 chromeos::ScreenLocker::UnlockScreenFailed(); | 89 chromeos::ScreenLocker::UnlockScreenFailed(); |
90 } | 90 } |
91 | 91 |
92 private: | 92 private: |
93 // Temporarily deactivates all input methods (e.g. Chinese, Japanese, Arabic) | 93 // Temporarily deactivates all input methods (e.g. Chinese, Japanese, Arabic) |
94 // since they are not necessary to input a login password. Users are still | 94 // since they are not necessary to input a login password. Users are still |
95 // able to use/switch active keyboard layouts (e.g. US qwerty, US dvorak, | 95 // able to use/switch active keyboard layouts (e.g. US qwerty, US dvorak, |
96 // French). | 96 // French). |
97 void SetupInputMethodsForScreenLocker() { | 97 void SetupInputMethodsForScreenLocker() { |
98 if (// The LockScreen function is also called when the OS is suspended, and | 98 if (// The LockScreen function is also called when the OS is suspended, and |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 } | 264 } |
265 | 265 |
266 Profile* profile = ProfileManager::GetDefaultProfile(); | 266 Profile* profile = ProfileManager::GetDefaultProfile(); |
267 if (profile) { | 267 if (profile) { |
268 ProfileSyncService* service = profile->GetProfileSyncService(username); | 268 ProfileSyncService* service = profile->GetProfileSyncService(username); |
269 if (service && !service->HasSyncSetupCompleted()) { | 269 if (service && !service->HasSyncSetupCompleted()) { |
270 // If sync has failed somehow, try setting the sync passphrase here. | 270 // If sync has failed somehow, try setting the sync passphrase here. |
271 service->SetPassphrase(password, false); | 271 service->SetPassphrase(password, false); |
272 } | 272 } |
273 } | 273 } |
274 DBusThreadManager::Get()->GetPowerManagerClient()-> | 274 CrosLibrary::Get()->GetScreenLockLibrary()->NotifyScreenUnlockRequested(); |
275 NotifyScreenUnlockRequested(); | |
276 | 275 |
277 if (login_status_consumer_) | 276 if (login_status_consumer_) |
278 login_status_consumer_->OnLoginSuccess(username, password, | 277 login_status_consumer_->OnLoginSuccess(username, password, |
279 unused, pending_requests, | 278 unused, pending_requests, |
280 using_oauth); | 279 using_oauth); |
281 } | 280 } |
282 | 281 |
283 void ScreenLocker::Authenticate(const string16& password) { | 282 void ScreenLocker::Authenticate(const string16& password) { |
284 authentication_start_time_ = base::Time::Now(); | 283 authentication_start_time_ = base::Time::Now(); |
285 delegate_->SetInputEnabled(false); | 284 delegate_->SetInputEnabled(false); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 if (!screen_locker_) { | 355 if (!screen_locker_) { |
357 VLOG(1) << "Show: Locking screen"; | 356 VLOG(1) << "Show: Locking screen"; |
358 ScreenLocker* locker = | 357 ScreenLocker* locker = |
359 new ScreenLocker(UserManager::Get()->logged_in_user()); | 358 new ScreenLocker(UserManager::Get()->logged_in_user()); |
360 locker->Init(); | 359 locker->Init(); |
361 } else { | 360 } else { |
362 // PowerManager re-sends lock screen signal if it doesn't | 361 // PowerManager re-sends lock screen signal if it doesn't |
363 // receive the response within timeout. Just send complete | 362 // receive the response within timeout. Just send complete |
364 // signal. | 363 // signal. |
365 VLOG(1) << "Show: locker already exists. Just sending completion event."; | 364 VLOG(1) << "Show: locker already exists. Just sending completion event."; |
366 DBusThreadManager::Get()->GetPowerManagerClient()-> | 365 CrosLibrary::Get()->GetScreenLockLibrary()->NotifyScreenLockCompleted(); |
367 NotifyScreenLockCompleted(); | |
368 } | 366 } |
369 } | 367 } |
370 | 368 |
371 // static | 369 // static |
372 void ScreenLocker::Hide() { | 370 void ScreenLocker::Hide() { |
373 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); | 371 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); |
374 DCHECK(screen_locker_); | 372 DCHECK(screen_locker_); |
375 VLOG(1) << "Hide: Deleting ScreenLocker: " << screen_locker_; | 373 VLOG(1) << "Hide: Deleting ScreenLocker: " << screen_locker_; |
376 MessageLoopForUI::current()->DeleteSoon(FROM_HERE, screen_locker_); | 374 MessageLoopForUI::current()->DeleteSoon(FROM_HERE, screen_locker_); |
377 } | 375 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 ScreenLocker::~ScreenLocker() { | 409 ScreenLocker::~ScreenLocker() { |
412 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); | 410 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); |
413 ClearErrors(); | 411 ClearErrors(); |
414 | 412 |
415 screen_locker_ = NULL; | 413 screen_locker_ = NULL; |
416 bool state = false; | 414 bool state = false; |
417 content::NotificationService::current()->Notify( | 415 content::NotificationService::current()->Notify( |
418 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 416 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
419 content::Source<ScreenLocker>(this), | 417 content::Source<ScreenLocker>(this), |
420 content::Details<bool>(&state)); | 418 content::Details<bool>(&state)); |
421 DBusThreadManager::Get()->GetPowerManagerClient()-> | 419 CrosLibrary::Get()->GetScreenLockLibrary()->NotifyScreenUnlockCompleted(); |
422 NotifyScreenUnlockCompleted(); | |
423 } | 420 } |
424 | 421 |
425 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) { | 422 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) { |
426 authenticator_ = authenticator; | 423 authenticator_ = authenticator; |
427 } | 424 } |
428 | 425 |
429 void ScreenLocker::ScreenLockReady() { | 426 void ScreenLocker::ScreenLockReady() { |
430 VLOG(1) << "ScreenLockReady: sending completed signal to power manager."; | 427 VLOG(1) << "ScreenLockReady: sending completed signal to power manager."; |
431 locked_ = true; | 428 locked_ = true; |
432 base::TimeDelta delta = base::Time::Now() - start_time_; | 429 base::TimeDelta delta = base::Time::Now() - start_time_; |
433 VLOG(1) << "Screen lock time: " << delta.InSecondsF(); | 430 VLOG(1) << "Screen lock time: " << delta.InSecondsF(); |
434 UMA_HISTOGRAM_TIMES("ScreenLocker.ScreenLockTime", delta); | 431 UMA_HISTOGRAM_TIMES("ScreenLocker.ScreenLockTime", delta); |
435 | 432 |
436 bool state = true; | 433 bool state = true; |
437 content::NotificationService::current()->Notify( | 434 content::NotificationService::current()->Notify( |
438 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 435 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
439 content::Source<ScreenLocker>(this), | 436 content::Source<ScreenLocker>(this), |
440 content::Details<bool>(&state)); | 437 content::Details<bool>(&state)); |
441 DBusThreadManager::Get()->GetPowerManagerClient()-> | 438 CrosLibrary::Get()->GetScreenLockLibrary()->NotifyScreenLockCompleted(); |
442 NotifyScreenLockCompleted(); | |
443 } | 439 } |
444 | 440 |
445 } // namespace chromeos | 441 } // namespace chromeos |
OLD | NEW |