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

Side by Side Diff: chrome/browser/chromeos/power/power_button_observer.cc

Issue 10008074: Cancel partial screenshot UI when lock happens. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use enum Created 8 years, 8 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/power/power_button_observer.h" 5 #include "chrome/browser/chromeos/power/power_button_observer.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/wm/power_button_controller.h" 8 #include "ash/wm/power_button_controller.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "chrome/browser/chromeos/login/screen_locker.h" 10 #include "chrome/browser/chromeos/login/screen_locker.h"
11 #include "chrome/browser/chromeos/login/user.h" 11 #include "chrome/browser/chromeos/login/user.h"
12 #include "chrome/browser/chromeos/login/user_manager.h" 12 #include "chrome/browser/chromeos/login/user_manager.h"
13 #include "chrome/browser/chromeos/power/power_button_controller_delegate_chromeo s.h" 13 #include "chrome/browser/chromeos/power/power_button_controller_delegate_chromeo s.h"
14 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
15 #include "chromeos/dbus/dbus_thread_manager.h" 15 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
17 17
18 namespace chromeos { 18 namespace chromeos {
19 19
20 PowerButtonObserver::PowerButtonObserver() { 20 PowerButtonObserver::PowerButtonObserver() {
21 ash::PowerButtonController* controller = 21 ash::Shell::GetInstance()->power_button_controller()->
22 ash::Shell::GetInstance()->power_button_controller(); 22 set_delegate(new PowerButtonControllerDelegateChromeos);
23 controller->set_delegate(new PowerButtonControllerDelegateChromeos);
24 23
25 registrar_.Add( 24 registrar_.Add(
26 this, 25 this,
27 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 26 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
28 content::NotificationService::AllSources()); 27 content::NotificationService::AllSources());
29 registrar_.Add( 28 registrar_.Add(
30 this, 29 this,
31 content::NOTIFICATION_APP_TERMINATING, 30 content::NOTIFICATION_APP_TERMINATING,
32 content::NotificationService::AllSources()); 31 content::NotificationService::AllSources());
33 registrar_.Add( 32 registrar_.Add(
34 this, 33 this,
35 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, 34 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
36 content::NotificationService::AllSources()); 35 content::NotificationService::AllSources());
37 36
38 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); 37 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
39 38
40 // Tell the controller about the initial state. 39 // Tell the controller about the initial state.
41 const UserManager* user_manager = UserManager::Get(); 40 const UserManager* user_manager = UserManager::Get();
42 bool logged_in = user_manager->IsUserLoggedIn(); 41 ash::Shell::LoginStatus login_status = ash::Shell::NOT_LOGGED_IN;
43 bool is_guest = logged_in && user_manager->GetLoggedInUser().is_guest(); 42 if (user_manager->IsUserLoggedIn()) {
44 controller->OnLoginStateChange(logged_in, is_guest); 43 if (user_manager->GetLoggedInUser().is_guest())
44 login_status = ash::Shell::LOGGED_IN_AS_GUEST;
45 else
46 login_status = ash::Shell::LOGGED_IN;
47 }
48 ash::Shell::GetInstance()->OnLoginStateChanged(login_status);
45 49
46 const ScreenLocker* locker = ScreenLocker::default_screen_locker(); 50 const ScreenLocker* locker = ScreenLocker::default_screen_locker();
47 bool locked = locker && locker->locked(); 51 bool locked = locker && locker->locked();
48 controller->OnLockStateChange(locked); 52 ash::Shell::GetInstance()->OnLockStateChanged(locked);
49 } 53 }
50 54
51 PowerButtonObserver::~PowerButtonObserver() { 55 PowerButtonObserver::~PowerButtonObserver() {
52 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); 56 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
53 } 57 }
54 58
55 void PowerButtonObserver::Observe(int type, 59 void PowerButtonObserver::Observe(int type,
56 const content::NotificationSource& source, 60 const content::NotificationSource& source,
57 const content::NotificationDetails& details) { 61 const content::NotificationDetails& details) {
58 switch (type) { 62 switch (type) {
59 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { 63 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: {
60 const User* user = &UserManager::Get()->GetLoggedInUser(); 64 const User* user = &UserManager::Get()->GetLoggedInUser();
61 ash::Shell::GetInstance()->power_button_controller()-> 65 ash::Shell::LoginStatus login_status = user->is_guest() ?
62 OnLoginStateChange(true /* logged_in */, user->is_guest()); 66 ash::Shell::LOGGED_IN_AS_GUEST :
67 ash::Shell::LOGGED_IN;
68 ash::Shell::GetInstance()->OnLoginStateChanged(login_status);
63 break; 69 break;
64 } 70 }
65 case content::NOTIFICATION_APP_TERMINATING: 71 case content::NOTIFICATION_APP_TERMINATING:
66 ash::Shell::GetInstance()->power_button_controller()->OnExit(); 72 ash::Shell::GetInstance()->OnAppTerminating();
67 break; 73 break;
68 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { 74 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: {
69 bool locked = *content::Details<bool>(details).ptr(); 75 bool locked = *content::Details<bool>(details).ptr();
70 ash::Shell::GetInstance()->power_button_controller()-> 76 ash::Shell::GetInstance()->OnLockStateChanged(locked);
71 OnLockStateChange(locked);
72 break; 77 break;
73 } 78 }
74 default: 79 default:
75 NOTREACHED() << "Unexpected notification " << type; 80 NOTREACHED() << "Unexpected notification " << type;
76 } 81 }
77 } 82 }
78 83
79 void PowerButtonObserver::PowerButtonStateChanged( 84 void PowerButtonObserver::PowerButtonStateChanged(
80 bool down, const base::TimeTicks& timestamp) { 85 bool down, const base::TimeTicks& timestamp) {
81 ash::Shell::GetInstance()->power_button_controller()-> 86 ash::Shell::GetInstance()->power_button_controller()->
82 OnPowerButtonEvent(down, timestamp); 87 OnPowerButtonEvent(down, timestamp);
83 } 88 }
84 89
85 void PowerButtonObserver::LockButtonStateChanged( 90 void PowerButtonObserver::LockButtonStateChanged(
86 bool down, const base::TimeTicks& timestamp) { 91 bool down, const base::TimeTicks& timestamp) {
87 ash::Shell::GetInstance()->power_button_controller()-> 92 ash::Shell::GetInstance()->power_button_controller()->
88 OnLockButtonEvent(down, timestamp); 93 OnLockButtonEvent(down, timestamp);
89 } 94 }
90 95
91 void PowerButtonObserver::LockScreen() { 96 void PowerButtonObserver::LockScreen() {
92 ash::Shell::GetInstance()->power_button_controller()->OnStartingLock(); 97 ash::Shell::GetInstance()->power_button_controller()->OnStartingLock();
93 } 98 }
94 99
95 } // namespace chromeos 100 } // namespace chromeos
OLDNEW
« ash/wm/power_button_controller.cc ('K') | « ash/wm/power_button_controller_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698