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

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

Issue 167663004: chromeos: Remove old LockScreen signal. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix ScreenLockObserver lifetime Created 6 years, 9 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 namespace chromeos { 63 namespace chromeos {
64 64
65 namespace { 65 namespace {
66 66
67 // Timeout for unlock animation guard - some animations may be required to run 67 // Timeout for unlock animation guard - some animations may be required to run
68 // on successful authentication before unlocking, but we want to be sure that 68 // on successful authentication before unlocking, but we want to be sure that
69 // unlock happens even if animations are broken. 69 // unlock happens even if animations are broken.
70 const int kUnlockGuardTimeoutMs = 400; 70 const int kUnlockGuardTimeoutMs = 400;
71 71
72 // Observer to start ScreenLocker when the screen lock 72 // Observer to start ScreenLocker when locking the screen is requested.
73 class ScreenLockObserver : public SessionManagerClient::Observer, 73 class ScreenLockObserver : public SessionManagerClient::StubDelegate,
74 public content::NotificationObserver, 74 public content::NotificationObserver,
75 public UserAddingScreen::Observer { 75 public UserAddingScreen::Observer {
76 public: 76 public:
77 ScreenLockObserver() : session_started_(false) { 77 ScreenLockObserver() : session_started_(false) {
78 registrar_.Add(this, 78 registrar_.Add(this,
79 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
80 content::NotificationService::AllSources());
81 registrar_.Add(this,
82 chrome::NOTIFICATION_SESSION_STARTED, 79 chrome::NOTIFICATION_SESSION_STARTED,
83 content::NotificationService::AllSources()); 80 content::NotificationService::AllSources());
81 DBusThreadManager::Get()->GetSessionManagerClient()->SetStubDelegate(this);
82 }
83
84 ~ScreenLockObserver() {
85 if (DBusThreadManager::IsInitialized()) {
86 DBusThreadManager::Get()->GetSessionManagerClient()->SetStubDelegate(
87 NULL);
88 }
84 } 89 }
85 90
86 bool session_started() const { return session_started_; } 91 bool session_started() const { return session_started_; }
87 92
93 // SessionManagerClient::StubDelegate overrides:
94 virtual void LockScreenForStub() OVERRIDE {
95 ScreenLocker::HandleLockScreenRequest();
96 }
97
88 // NotificationObserver overrides: 98 // NotificationObserver overrides:
89 virtual void Observe(int type, 99 virtual void Observe(int type,
90 const content::NotificationSource& source, 100 const content::NotificationSource& source,
91 const content::NotificationDetails& details) OVERRIDE { 101 const content::NotificationDetails& details) OVERRIDE {
92 switch (type) { 102 if (type == chrome::NOTIFICATION_SESSION_STARTED)
93 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { 103 session_started_ = true;
94 // Register Screen Lock only after a user has logged in. 104 else
95 SessionManagerClient* session_manager = 105 NOTREACHED() << "Unexpected notification " << type;
96 DBusThreadManager::Get()->GetSessionManagerClient();
97 if (!session_manager->HasObserver(this))
98 session_manager->AddObserver(this);
99 break;
100 }
101
102 case chrome::NOTIFICATION_SESSION_STARTED: {
103 session_started_ = true;
104 break;
105 }
106
107 default:
108 NOTREACHED();
109 }
110 } 106 }
111 107
112 // TODO(derat): Remove this once the session manager is calling the LockScreen 108 // UserAddingScreen::Observer overrides:
113 // method instead of emitting a signal. 109 virtual void OnUserAddingFinished() OVERRIDE {
114 virtual void LockScreen() OVERRIDE { 110 UserAddingScreen::Get()->RemoveObserver(this);
115 VLOG(1) << "Received LockScreen D-Bus signal from session manager";
116 ScreenLocker::HandleLockScreenRequest(); 111 ScreenLocker::HandleLockScreenRequest();
117 } 112 }
118 113
119 virtual void OnUserAddingFinished() OVERRIDE {
120 UserAddingScreen::Get()->RemoveObserver(this);
121 LockScreen();
122 }
123
124 private: 114 private:
125 bool session_started_; 115 bool session_started_;
126 content::NotificationRegistrar registrar_; 116 content::NotificationRegistrar registrar_;
127 117
128 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); 118 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver);
129 }; 119 };
130 120
131 static base::LazyInstance<ScreenLockObserver> g_screen_lock_observer = 121 ScreenLockObserver* g_screen_lock_observer = NULL;
132 LAZY_INSTANCE_INITIALIZER;
133 122
134 } // namespace 123 } // namespace
135 124
136 // static 125 // static
137 ScreenLocker* ScreenLocker::screen_locker_ = NULL; 126 ScreenLocker* ScreenLocker::screen_locker_ = NULL;
138 127
139 ////////////////////////////////////////////////////////////////////////////// 128 //////////////////////////////////////////////////////////////////////////////
140 // ScreenLocker, public: 129 // ScreenLocker, public:
141 130
142 ScreenLocker::ScreenLocker(const UserList& users) 131 ScreenLocker::ScreenLocker(const UserList& users)
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 delegate_->ShowErrorMessage(error_msg_id, help_topic_id); 357 delegate_->ShowErrorMessage(error_msg_id, help_topic_id);
369 } 358 }
370 359
371 void ScreenLocker::SetLoginStatusConsumer( 360 void ScreenLocker::SetLoginStatusConsumer(
372 chromeos::LoginStatusConsumer* consumer) { 361 chromeos::LoginStatusConsumer* consumer) {
373 login_status_consumer_ = consumer; 362 login_status_consumer_ = consumer;
374 } 363 }
375 364
376 // static 365 // static
377 void ScreenLocker::InitClass() { 366 void ScreenLocker::InitClass() {
378 g_screen_lock_observer.Get(); 367 DCHECK(!g_screen_lock_observer);
368 g_screen_lock_observer = new ScreenLockObserver;
369 }
370
371 // static
372 void ScreenLocker::ShutDownClass() {
373 DCHECK(g_screen_lock_observer);
374 delete g_screen_lock_observer;
375 g_screen_lock_observer = NULL;
379 } 376 }
380 377
381 // static 378 // static
382 void ScreenLocker::HandleLockScreenRequest() { 379 void ScreenLocker::HandleLockScreenRequest() {
383 VLOG(1) << "Received LockScreen request from session manager"; 380 VLOG(1) << "Received LockScreen request from session manager";
381 DCHECK(g_screen_lock_observer);
384 if (UserAddingScreen::Get()->IsRunning()) { 382 if (UserAddingScreen::Get()->IsRunning()) {
385 VLOG(1) << "Waiting for user adding screen to stop"; 383 VLOG(1) << "Waiting for user adding screen to stop";
386 UserAddingScreen::Get()->AddObserver(g_screen_lock_observer.Pointer()); 384 UserAddingScreen::Get()->AddObserver(g_screen_lock_observer);
387 UserAddingScreen::Get()->Cancel(); 385 UserAddingScreen::Get()->Cancel();
388 return; 386 return;
389 } 387 }
390 if (g_screen_lock_observer.Get().session_started() && 388 if (g_screen_lock_observer->session_started() &&
391 UserManager::Get()->CanCurrentUserLock()) { 389 UserManager::Get()->CanCurrentUserLock()) {
392 ScreenLocker::Show(); 390 ScreenLocker::Show();
391 ash::Shell::GetInstance()->lock_state_controller()->OnStartingLock();
Daniel Erat 2014/03/12 00:30:44 note that this was previously getting called uncon
393 } else { 392 } else {
394 // If the current user's session cannot be locked or the user has not 393 // If the current user's session cannot be locked or the user has not
395 // completed all sign-in steps yet, log out instead. The latter is done to 394 // completed all sign-in steps yet, log out instead. The latter is done to
396 // avoid complications with displaying the lock screen over the login 395 // avoid complications with displaying the lock screen over the login
397 // screen while remaining secure in the case the user walks away during 396 // screen while remaining secure in the case the user walks away during
398 // the sign-in steps. See crbug.com/112225 and crbug.com/110933. 397 // the sign-in steps. See crbug.com/112225 and crbug.com/110933.
399 VLOG(1) << "Calling session manager's StopSession D-Bus method"; 398 VLOG(1) << "Calling session manager's StopSession D-Bus method";
400 DBusThreadManager::Get()->GetSessionManagerClient()->StopSession(); 399 DBusThreadManager::Get()->GetSessionManagerClient()->StopSession();
401 } 400 }
402 } 401 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 desktop_background_controller()->MoveDesktopToUnlockedContainer(); 484 desktop_background_controller()->MoveDesktopToUnlockedContainer();
486 485
487 screen_locker_ = NULL; 486 screen_locker_ = NULL;
488 bool state = false; 487 bool state = false;
489 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; 488 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state;
490 content::NotificationService::current()->Notify( 489 content::NotificationService::current()->Notify(
491 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, 490 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
492 content::Source<ScreenLocker>(this), 491 content::Source<ScreenLocker>(this),
493 content::Details<bool>(&state)); 492 content::Details<bool>(&state));
494 VLOG(1) << "Calling session manager's HandleLockScreenDismissed D-Bus method"; 493 VLOG(1) << "Calling session manager's HandleLockScreenDismissed D-Bus method";
494
495 DBusThreadManager::Get()->GetSessionManagerClient()-> 495 DBusThreadManager::Get()->GetSessionManagerClient()->
496 NotifyLockScreenDismissed(); 496 NotifyLockScreenDismissed();
497 } 497 }
498 498
499 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) { 499 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) {
500 authenticator_ = authenticator; 500 authenticator_ = authenticator;
501 } 501 }
502 502
503 void ScreenLocker::ScreenLockReady() { 503 void ScreenLocker::ScreenLockReady() {
504 locked_ = true; 504 locked_ = true;
(...skipping 22 matching lines...) Expand all
527 527
528 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { 528 bool ScreenLocker::IsUserLoggedIn(const std::string& username) {
529 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { 529 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) {
530 if ((*it)->email() == username) 530 if ((*it)->email() == username)
531 return true; 531 return true;
532 } 532 }
533 return false; 533 return false;
534 } 534 }
535 535
536 } // namespace chromeos 536 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698