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" | |
21 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 19 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| 20 #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
22 #include "chrome/browser/chromeos/dbus/session_manager_client.h" | 21 #include "chrome/browser/chromeos/dbus/session_manager_client.h" |
23 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 22 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
24 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 23 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
25 #include "chrome/browser/chromeos/input_method/xkeyboard.h" | 24 #include "chrome/browser/chromeos/input_method/xkeyboard.h" |
26 #include "chrome/browser/chromeos/language_preferences.h" | 25 #include "chrome/browser/chromeos/language_preferences.h" |
27 #include "chrome/browser/chromeos/login/authenticator.h" | 26 #include "chrome/browser/chromeos/login/authenticator.h" |
28 #include "chrome/browser/chromeos/login/login_performer.h" | 27 #include "chrome/browser/chromeos/login/login_performer.h" |
29 #include "chrome/browser/chromeos/login/login_utils.h" | 28 #include "chrome/browser/chromeos/login/login_utils.h" |
30 #include "chrome/browser/chromeos/login/screen_locker_views.h" | 29 #include "chrome/browser/chromeos/login/screen_locker_views.h" |
31 #include "chrome/browser/chromeos/login/user_manager.h" | 30 #include "chrome/browser/chromeos/login/user_manager.h" |
(...skipping 16 matching lines...) Expand all Loading... |
48 | 47 |
49 #if defined(TOOLKIT_USES_GTK) | 48 #if defined(TOOLKIT_USES_GTK) |
50 #include "chrome/browser/chromeos/legacy_window_manager/wm_ipc.h" | 49 #include "chrome/browser/chromeos/legacy_window_manager/wm_ipc.h" |
51 #endif | 50 #endif |
52 | 51 |
53 using content::BrowserThread; | 52 using content::BrowserThread; |
54 | 53 |
55 namespace { | 54 namespace { |
56 | 55 |
57 // Observer to start ScreenLocker when the screen lock | 56 // Observer to start ScreenLocker when the screen lock |
58 class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer, | 57 class ScreenLockObserver : public chromeos::PowerManagerClient::Observer, |
59 public content::NotificationObserver { | 58 public content::NotificationObserver { |
60 public: | 59 public: |
61 ScreenLockObserver() { | 60 ScreenLockObserver() { |
62 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 61 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
63 content::NotificationService::AllSources()); | 62 content::NotificationService::AllSources()); |
64 } | 63 } |
65 | 64 |
66 // NotificationObserver overrides: | 65 // NotificationObserver overrides: |
67 virtual void Observe(int type, | 66 virtual void Observe(int type, |
68 const content::NotificationSource& source, | 67 const content::NotificationSource& source, |
69 const content::NotificationDetails& details) OVERRIDE { | 68 const content::NotificationDetails& details) OVERRIDE { |
70 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { | 69 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { |
71 // Register Screen Lock after login screen to make sure | 70 // Register Screen Lock after login screen to make sure |
72 // we don't show the screen lock on top of the login screen by accident. | 71 // we don't show the screen lock on top of the login screen by accident. |
73 chromeos::CrosLibrary::Get()->GetScreenLockLibrary()->AddObserver(this); | 72 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 73 AddObserver(this); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 virtual void LockScreen(chromeos::ScreenLockLibrary* obj) OVERRIDE { | 77 virtual void LockScreen() 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(chromeos::ScreenLockLibrary* obj) OVERRIDE { | 83 virtual void UnlockScreen() OVERRIDE { |
84 RestoreInputMethods(); | 84 RestoreInputMethods(); |
85 chromeos::ScreenLocker::Hide(); | 85 chromeos::ScreenLocker::Hide(); |
86 } | 86 } |
87 | 87 |
88 virtual void UnlockScreenFailed(chromeos::ScreenLockLibrary* obj) OVERRIDE { | 88 virtual void UnlockScreenFailed() 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 CrosLibrary::Get()->GetScreenLockLibrary()->NotifyScreenUnlockRequested(); | 274 DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 275 NotifyScreenUnlockRequested(); |
275 | 276 |
276 if (login_status_consumer_) | 277 if (login_status_consumer_) |
277 login_status_consumer_->OnLoginSuccess(username, password, | 278 login_status_consumer_->OnLoginSuccess(username, password, |
278 unused, pending_requests, | 279 unused, pending_requests, |
279 using_oauth); | 280 using_oauth); |
280 } | 281 } |
281 | 282 |
282 void ScreenLocker::Authenticate(const string16& password) { | 283 void ScreenLocker::Authenticate(const string16& password) { |
283 authentication_start_time_ = base::Time::Now(); | 284 authentication_start_time_ = base::Time::Now(); |
284 delegate_->SetInputEnabled(false); | 285 delegate_->SetInputEnabled(false); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 if (!screen_locker_) { | 356 if (!screen_locker_) { |
356 VLOG(1) << "Show: Locking screen"; | 357 VLOG(1) << "Show: Locking screen"; |
357 ScreenLocker* locker = | 358 ScreenLocker* locker = |
358 new ScreenLocker(UserManager::Get()->logged_in_user()); | 359 new ScreenLocker(UserManager::Get()->logged_in_user()); |
359 locker->Init(); | 360 locker->Init(); |
360 } else { | 361 } else { |
361 // PowerManager re-sends lock screen signal if it doesn't | 362 // PowerManager re-sends lock screen signal if it doesn't |
362 // receive the response within timeout. Just send complete | 363 // receive the response within timeout. Just send complete |
363 // signal. | 364 // signal. |
364 VLOG(1) << "Show: locker already exists. Just sending completion event."; | 365 VLOG(1) << "Show: locker already exists. Just sending completion event."; |
365 CrosLibrary::Get()->GetScreenLockLibrary()->NotifyScreenLockCompleted(); | 366 DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 367 NotifyScreenLockCompleted(); |
366 } | 368 } |
367 } | 369 } |
368 | 370 |
369 // static | 371 // static |
370 void ScreenLocker::Hide() { | 372 void ScreenLocker::Hide() { |
371 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); | 373 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); |
372 DCHECK(screen_locker_); | 374 DCHECK(screen_locker_); |
373 VLOG(1) << "Hide: Deleting ScreenLocker: " << screen_locker_; | 375 VLOG(1) << "Hide: Deleting ScreenLocker: " << screen_locker_; |
374 MessageLoopForUI::current()->DeleteSoon(FROM_HERE, screen_locker_); | 376 MessageLoopForUI::current()->DeleteSoon(FROM_HERE, screen_locker_); |
375 } | 377 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 ScreenLocker::~ScreenLocker() { | 411 ScreenLocker::~ScreenLocker() { |
410 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); | 412 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); |
411 ClearErrors(); | 413 ClearErrors(); |
412 | 414 |
413 screen_locker_ = NULL; | 415 screen_locker_ = NULL; |
414 bool state = false; | 416 bool state = false; |
415 content::NotificationService::current()->Notify( | 417 content::NotificationService::current()->Notify( |
416 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 418 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
417 content::Source<ScreenLocker>(this), | 419 content::Source<ScreenLocker>(this), |
418 content::Details<bool>(&state)); | 420 content::Details<bool>(&state)); |
419 CrosLibrary::Get()->GetScreenLockLibrary()->NotifyScreenUnlockCompleted(); | 421 DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 422 NotifyScreenUnlockCompleted(); |
420 } | 423 } |
421 | 424 |
422 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) { | 425 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) { |
423 authenticator_ = authenticator; | 426 authenticator_ = authenticator; |
424 } | 427 } |
425 | 428 |
426 void ScreenLocker::ScreenLockReady() { | 429 void ScreenLocker::ScreenLockReady() { |
427 VLOG(1) << "ScreenLockReady: sending completed signal to power manager."; | 430 VLOG(1) << "ScreenLockReady: sending completed signal to power manager."; |
428 locked_ = true; | 431 locked_ = true; |
429 base::TimeDelta delta = base::Time::Now() - start_time_; | 432 base::TimeDelta delta = base::Time::Now() - start_time_; |
430 VLOG(1) << "Screen lock time: " << delta.InSecondsF(); | 433 VLOG(1) << "Screen lock time: " << delta.InSecondsF(); |
431 UMA_HISTOGRAM_TIMES("ScreenLocker.ScreenLockTime", delta); | 434 UMA_HISTOGRAM_TIMES("ScreenLocker.ScreenLockTime", delta); |
432 | 435 |
433 bool state = true; | 436 bool state = true; |
434 content::NotificationService::current()->Notify( | 437 content::NotificationService::current()->Notify( |
435 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 438 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
436 content::Source<ScreenLocker>(this), | 439 content::Source<ScreenLocker>(this), |
437 content::Details<bool>(&state)); | 440 content::Details<bool>(&state)); |
438 CrosLibrary::Get()->GetScreenLockLibrary()->NotifyScreenLockCompleted(); | 441 DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 442 NotifyScreenLockCompleted(); |
439 } | 443 } |
440 | 444 |
441 } // namespace chromeos | 445 } // namespace chromeos |
OLD | NEW |