Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: chrome/browser/chromeos/login/screen_locker.cc

Issue 8664014: chromeos: move screen lock handling to power manager client (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 else 367 else
367 locker->Signout(); 368 locker->Signout();
368 #else 369 #else
369 locker->Init(); 370 locker->Init();
370 #endif 371 #endif
371 } else { 372 } else {
372 // PowerManager re-sends lock screen signal if it doesn't 373 // PowerManager re-sends lock screen signal if it doesn't
373 // receive the response within timeout. Just send complete 374 // receive the response within timeout. Just send complete
374 // signal. 375 // signal.
375 VLOG(1) << "Show: locker already exists. Just sending completion event."; 376 VLOG(1) << "Show: locker already exists. Just sending completion event.";
376 CrosLibrary::Get()->GetScreenLockLibrary()->NotifyScreenLockCompleted(); 377 DBusThreadManager::Get()->GetPowerManagerClient()->
378 NotifyScreenLockCompleted();
377 } 379 }
378 } 380 }
379 381
380 // static 382 // static
381 void ScreenLocker::Hide() { 383 void ScreenLocker::Hide() {
382 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); 384 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
383 DCHECK(screen_locker_); 385 DCHECK(screen_locker_);
384 VLOG(1) << "Hide: Deleting ScreenLocker: " << screen_locker_; 386 VLOG(1) << "Hide: Deleting ScreenLocker: " << screen_locker_;
385 MessageLoopForUI::current()->DeleteSoon(FROM_HERE, screen_locker_); 387 MessageLoopForUI::current()->DeleteSoon(FROM_HERE, screen_locker_);
386 } 388 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 ScreenLocker::~ScreenLocker() { 422 ScreenLocker::~ScreenLocker() {
421 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); 423 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
422 ClearErrors(); 424 ClearErrors();
423 425
424 screen_locker_ = NULL; 426 screen_locker_ = NULL;
425 bool state = false; 427 bool state = false;
426 content::NotificationService::current()->Notify( 428 content::NotificationService::current()->Notify(
427 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, 429 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
428 content::Source<ScreenLocker>(this), 430 content::Source<ScreenLocker>(this),
429 content::Details<bool>(&state)); 431 content::Details<bool>(&state));
430 CrosLibrary::Get()->GetScreenLockLibrary()->NotifyScreenUnlockCompleted(); 432 DBusThreadManager::Get()->GetPowerManagerClient()->
433 NotifyScreenUnlockCompleted();
431 } 434 }
432 435
433 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) { 436 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) {
434 authenticator_ = authenticator; 437 authenticator_ = authenticator;
435 } 438 }
436 439
437 void ScreenLocker::ScreenLockReady() { 440 void ScreenLocker::ScreenLockReady() {
438 VLOG(1) << "ScreenLockReady: sending completed signal to power manager."; 441 VLOG(1) << "ScreenLockReady: sending completed signal to power manager.";
439 locked_ = true; 442 locked_ = true;
440 base::TimeDelta delta = base::Time::Now() - start_time_; 443 base::TimeDelta delta = base::Time::Now() - start_time_;
441 VLOG(1) << "Screen lock time: " << delta.InSecondsF(); 444 VLOG(1) << "Screen lock time: " << delta.InSecondsF();
442 UMA_HISTOGRAM_TIMES("ScreenLocker.ScreenLockTime", delta); 445 UMA_HISTOGRAM_TIMES("ScreenLocker.ScreenLockTime", delta);
443 446
444 bool state = true; 447 bool state = true;
445 content::NotificationService::current()->Notify( 448 content::NotificationService::current()->Notify(
446 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, 449 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
447 content::Source<ScreenLocker>(this), 450 content::Source<ScreenLocker>(this),
448 content::Details<bool>(&state)); 451 content::Details<bool>(&state));
449 CrosLibrary::Get()->GetScreenLockLibrary()->NotifyScreenLockCompleted(); 452 DBusThreadManager::Get()->GetPowerManagerClient()->
453 NotifyScreenLockCompleted();
450 } 454 }
451 455
452 } // namespace chromeos 456 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698