OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/chromeos/power/power_button_observer.h" | |
6 | |
7 #include "ash/shell.h" | |
8 #include "ash/wm/power_button_controller.h" | |
9 #include "base/logging.h" | |
10 #include "chrome/browser/chromeos/login/screen_locker.h" | |
11 #include "chrome/browser/chromeos/login/user.h" | |
12 #include "chrome/browser/chromeos/login/user_manager.h" | |
13 #include "chrome/browser/chromeos/power/power_button_controller_delegate_chromeo s.h" | |
14 #include "chrome/common/chrome_notification_types.h" | |
15 #include "content/public/browser/notification_service.h" | |
16 | |
17 namespace chromeos { | |
18 | |
19 PowerButtonObserver::PowerButtonObserver() { | |
20 ash::PowerButtonController* controller = | |
21 ash::Shell::GetInstance()->power_button_controller(); | |
22 controller->set_delegate(new PowerButtonControllerDelegateChromeos); | |
23 | |
24 registrar_.Add( | |
25 this, | |
26 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | |
27 content::NotificationService::AllSources()); | |
28 registrar_.Add( | |
29 this, | |
30 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | |
31 content::NotificationService::AllSources()); | |
32 | |
33 // Tell the controller about the initial state. | |
34 const UserManager* user_manager = UserManager::Get(); | |
35 bool logged_in = user_manager->user_is_logged_in(); | |
36 bool is_guest = | |
37 logged_in && | |
38 user_manager->logged_in_user().email() == UserManager::kGuestUser; | |
stevenjb
2012/01/03 17:05:41
nit: I think it might be worth adding User::IsGues
Daniel Erat
2012/01/03 19:12:12
Thanks, I agree. Done (by adding an is_guest_ fie
| |
39 controller->OnLoginStateChange(logged_in, is_guest); | |
40 | |
41 const ScreenLocker* locker = ScreenLocker::default_screen_locker(); | |
42 bool locked = locker && locker->locked(); | |
43 controller->OnLockStateChange(locked); | |
44 } | |
45 | |
46 PowerButtonObserver::~PowerButtonObserver() { | |
47 } | |
48 | |
49 void PowerButtonObserver::Observe(int type, | |
50 const content::NotificationSource& source, | |
51 const content::NotificationDetails& details) { | |
52 switch (type) { | |
53 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { | |
54 const User* user = content::Details<const User>(details).ptr(); | |
55 bool is_guest = user->email() == UserManager::kGuestUser; | |
56 ash::Shell::GetInstance()->power_button_controller()-> | |
57 OnLoginStateChange(true /* logged_in */, is_guest); | |
58 break; | |
59 } | |
60 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { | |
61 bool locked = *content::Details<bool>(details).ptr(); | |
62 ash::Shell::GetInstance()->power_button_controller()-> | |
63 OnLockStateChange(locked); | |
64 break; | |
65 } | |
66 default: | |
67 NOTREACHED() << "Unexpected notification " << type; | |
68 } | |
69 } | |
70 | |
71 void PowerButtonObserver::PowerButtonStateChanged( | |
72 bool down, const base::TimeTicks& timestamp) { | |
73 ash::Shell::GetInstance()->power_button_controller()-> | |
74 OnPowerButtonEvent(down, timestamp); | |
75 } | |
76 | |
77 void PowerButtonObserver::LockButtonStateChanged( | |
78 bool down, const base::TimeTicks& timestamp) { | |
79 ash::Shell::GetInstance()->power_button_controller()-> | |
80 OnLockButtonEvent(down, timestamp); | |
81 } | |
82 | |
83 void PowerButtonObserver::LockScreen() { | |
84 ash::Shell::GetInstance()->power_button_controller()->OnStartingLock(); | |
85 } | |
86 | |
87 } // namespace chromeos | |
OLD | NEW |