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

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: 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/system/user/login_status.h"
8 #include "ash/wm/power_button_controller.h" 9 #include "ash/wm/power_button_controller.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "chrome/browser/chromeos/login/screen_locker.h" 11 #include "chrome/browser/chromeos/login/screen_locker.h"
11 #include "chrome/browser/chromeos/login/user.h" 12 #include "chrome/browser/chromeos/login/user.h"
12 #include "chrome/browser/chromeos/login/user_manager.h" 13 #include "chrome/browser/chromeos/login/user_manager.h"
13 #include "chrome/browser/chromeos/power/power_button_controller_delegate_chromeo s.h" 14 #include "chrome/browser/chromeos/power/power_button_controller_delegate_chromeo s.h"
14 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
15 #include "chromeos/dbus/dbus_thread_manager.h" 16 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
17 18
18 namespace chromeos { 19 namespace chromeos {
19 20
20 PowerButtonObserver::PowerButtonObserver() { 21 PowerButtonObserver::PowerButtonObserver() {
21 ash::PowerButtonController* controller = 22 ash::Shell::GetInstance()->power_button_controller()->
22 ash::Shell::GetInstance()->power_button_controller(); 23 set_delegate(new PowerButtonControllerDelegateChromeos);
23 controller->set_delegate(new PowerButtonControllerDelegateChromeos);
24 24
25 registrar_.Add( 25 registrar_.Add(
26 this, 26 this,
27 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 27 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
28 content::NotificationService::AllSources()); 28 content::NotificationService::AllSources());
29 registrar_.Add( 29 registrar_.Add(
30 this, 30 this,
31 content::NOTIFICATION_APP_TERMINATING, 31 content::NOTIFICATION_APP_TERMINATING,
32 content::NotificationService::AllSources()); 32 content::NotificationService::AllSources());
33 registrar_.Add( 33 registrar_.Add(
34 this, 34 this,
35 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, 35 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
36 content::NotificationService::AllSources()); 36 content::NotificationService::AllSources());
37 37
38 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); 38 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
39 39
40 // Tell the controller about the initial state. 40 // Tell the controller about the initial state.
41 const UserManager* user_manager = UserManager::Get(); 41 const UserManager* user_manager = UserManager::Get();
42 bool logged_in = user_manager->IsUserLoggedIn(); 42 ash::user::LoginStatus login_status = ash::user::LOGGED_IN_NONE;
43 bool is_guest = logged_in && user_manager->GetLoggedInUser().is_guest(); 43 if (user_manager->IsUserLoggedIn()) {
44 controller->OnLoginStateChange(logged_in, is_guest); 44 if (user_manager->GetLoggedInUser().is_guest())
45 login_status = ash::user::LOGGED_IN_GUEST;
46 else
47 login_status = ash::user::LOGGED_IN_USER;
48 }
49 ash::Shell::GetInstance()->OnLoginStateChanged(login_status);
45 50
46 const ScreenLocker* locker = ScreenLocker::default_screen_locker(); 51 const ScreenLocker* locker = ScreenLocker::default_screen_locker();
47 bool locked = locker && locker->locked(); 52 bool locked = locker && locker->locked();
48 controller->OnLockStateChange(locked); 53 ash::Shell::GetInstance()->OnLockStateChanged(locked);
49 } 54 }
50 55
51 PowerButtonObserver::~PowerButtonObserver() { 56 PowerButtonObserver::~PowerButtonObserver() {
52 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); 57 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
53 } 58 }
54 59
55 void PowerButtonObserver::Observe(int type, 60 void PowerButtonObserver::Observe(int type,
56 const content::NotificationSource& source, 61 const content::NotificationSource& source,
57 const content::NotificationDetails& details) { 62 const content::NotificationDetails& details) {
58 switch (type) { 63 switch (type) {
59 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { 64 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: {
60 const User* user = &UserManager::Get()->GetLoggedInUser(); 65 const User* user = &UserManager::Get()->GetLoggedInUser();
61 ash::Shell::GetInstance()->power_button_controller()-> 66 ash::user::LoginStatus login_status = user->is_guest() ?
sky 2012/04/19 15:43:29 this is nearly identical to 43-48. Refactor into a
Jun Mukai 2012/04/20 07:27:33 Done.
62 OnLoginStateChange(true /* logged_in */, user->is_guest()); 67 ash::user::LOGGED_IN_GUEST :
68 ash::user::LOGGED_IN_USER;
69 ash::Shell::GetInstance()->OnLoginStateChanged(login_status);
63 break; 70 break;
64 } 71 }
65 case content::NOTIFICATION_APP_TERMINATING: 72 case content::NOTIFICATION_APP_TERMINATING:
66 ash::Shell::GetInstance()->power_button_controller()->OnExit(); 73 ash::Shell::GetInstance()->OnAppTerminating();
67 break; 74 break;
68 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { 75 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: {
69 bool locked = *content::Details<bool>(details).ptr(); 76 bool locked = *content::Details<bool>(details).ptr();
70 ash::Shell::GetInstance()->power_button_controller()-> 77 ash::Shell::GetInstance()->OnLockStateChanged(locked);
71 OnLockStateChange(locked);
72 break; 78 break;
73 } 79 }
74 default: 80 default:
75 NOTREACHED() << "Unexpected notification " << type; 81 NOTREACHED() << "Unexpected notification " << type;
76 } 82 }
77 } 83 }
78 84
79 void PowerButtonObserver::PowerButtonStateChanged( 85 void PowerButtonObserver::PowerButtonStateChanged(
80 bool down, const base::TimeTicks& timestamp) { 86 bool down, const base::TimeTicks& timestamp) {
81 ash::Shell::GetInstance()->power_button_controller()-> 87 ash::Shell::GetInstance()->power_button_controller()->
82 OnPowerButtonEvent(down, timestamp); 88 OnPowerButtonEvent(down, timestamp);
83 } 89 }
84 90
85 void PowerButtonObserver::LockButtonStateChanged( 91 void PowerButtonObserver::LockButtonStateChanged(
86 bool down, const base::TimeTicks& timestamp) { 92 bool down, const base::TimeTicks& timestamp) {
87 ash::Shell::GetInstance()->power_button_controller()-> 93 ash::Shell::GetInstance()->power_button_controller()->
88 OnLockButtonEvent(down, timestamp); 94 OnLockButtonEvent(down, timestamp);
89 } 95 }
90 96
91 void PowerButtonObserver::LockScreen() { 97 void PowerButtonObserver::LockScreen() {
92 ash::Shell::GetInstance()->power_button_controller()->OnStartingLock(); 98 ash::Shell::GetInstance()->power_button_controller()->OnStartingLock();
93 } 99 }
94 100
95 } // namespace chromeos 101 } // 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