| OLD | NEW |
| 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/power/login_lock_state_notifier.h" | 5 #include "chrome/browser/chromeos/power/login_lock_state_notifier.h" |
| 6 | 6 |
| 7 #include "ash/common/login_status.h" | |
| 8 #include "ash/common/system/tray/system_tray_delegate.h" | |
| 9 #include "ash/common/wm_shell.h" | |
| 10 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 11 #include "base/logging.h" | 8 #include "base/logging.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 10 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
| 14 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
| 15 | 12 |
| 16 namespace ash { | 13 namespace ash { |
| 17 class LockStateControllerDelegate; | 14 class LockStateControllerDelegate; |
| 18 } | 15 } |
| 19 | 16 |
| 20 namespace chromeos { | 17 namespace chromeos { |
| 21 | 18 |
| 22 namespace { | |
| 23 | |
| 24 ash::LoginStatus GetCurrentLoginStatus() { | |
| 25 if (ash::Shell::Get()->system_tray_delegate()) | |
| 26 return ash::Shell::Get()->system_tray_delegate()->GetUserLoginStatus(); | |
| 27 | |
| 28 return ash::LoginStatus::NOT_LOGGED_IN; | |
| 29 } | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 LoginLockStateNotifier::LoginLockStateNotifier() { | 19 LoginLockStateNotifier::LoginLockStateNotifier() { |
| 34 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, | |
| 35 content::NotificationService::AllSources()); | |
| 36 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 20 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| 37 content::NotificationService::AllSources()); | 21 content::NotificationService::AllSources()); |
| 38 registrar_.Add(this, chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 22 registrar_.Add(this, chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
| 39 content::NotificationService::AllSources()); | 23 content::NotificationService::AllSources()); |
| 40 | 24 |
| 41 // Tell the controller about the initial state. | |
| 42 ash::Shell::GetInstance()->OnLoginStateChanged(GetCurrentLoginStatus()); | |
| 43 | |
| 44 const ScreenLocker* locker = ScreenLocker::default_screen_locker(); | 25 const ScreenLocker* locker = ScreenLocker::default_screen_locker(); |
| 45 bool locked = locker && locker->locked(); | 26 bool locked = locker && locker->locked(); |
| 46 ash::Shell::GetInstance()->OnLockStateChanged(locked); | 27 ash::Shell::GetInstance()->OnLockStateChanged(locked); |
| 47 } | 28 } |
| 48 | 29 |
| 49 LoginLockStateNotifier::~LoginLockStateNotifier() {} | 30 LoginLockStateNotifier::~LoginLockStateNotifier() {} |
| 50 | 31 |
| 51 void LoginLockStateNotifier::Observe( | 32 void LoginLockStateNotifier::Observe( |
| 52 int type, | 33 int type, |
| 53 const content::NotificationSource& source, | 34 const content::NotificationSource& source, |
| 54 const content::NotificationDetails& details) { | 35 const content::NotificationDetails& details) { |
| 55 switch (type) { | 36 switch (type) { |
| 56 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { | |
| 57 ash::Shell::GetInstance()->OnLoginStateChanged(GetCurrentLoginStatus()); | |
| 58 break; | |
| 59 } | |
| 60 case chrome::NOTIFICATION_APP_TERMINATING: | 37 case chrome::NOTIFICATION_APP_TERMINATING: |
| 61 ash::Shell::GetInstance()->OnAppTerminating(); | 38 ash::Shell::GetInstance()->OnAppTerminating(); |
| 62 break; | 39 break; |
| 63 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { | 40 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { |
| 64 bool locked = *content::Details<bool>(details).ptr(); | 41 bool locked = *content::Details<bool>(details).ptr(); |
| 65 ash::Shell::GetInstance()->OnLockStateChanged(locked); | 42 ash::Shell::GetInstance()->OnLockStateChanged(locked); |
| 66 break; | 43 break; |
| 67 } | 44 } |
| 68 default: | 45 default: |
| 69 NOTREACHED() << "Unexpected notification " << type; | 46 NOTREACHED() << "Unexpected notification " << type; |
| 70 } | 47 } |
| 71 } | 48 } |
| 72 | 49 |
| 73 } // namespace chromeos | 50 } // namespace chromeos |
| OLD | NEW |