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

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: coding style fix 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
« no previous file with comments | « ash/wm/power_button_controller_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
21 namespace {
22
23 ash::user::LoginStatus GetCurrentLoginStatus() {
24 const UserManager* user_manager = UserManager::Get();
25 if (!user_manager->IsUserLoggedIn())
26 return ash::user::LOGGED_IN_NONE;
27
28 if (user_manager->GetLoggedInUser().is_guest())
29 return ash::user::LOGGED_IN_GUEST;
30
31 return ash::user::LOGGED_IN_USER;
32 }
33
34 } // namespace
35
20 PowerButtonObserver::PowerButtonObserver() { 36 PowerButtonObserver::PowerButtonObserver() {
21 ash::PowerButtonController* controller = 37 ash::Shell::GetInstance()->power_button_controller()->
22 ash::Shell::GetInstance()->power_button_controller(); 38 set_delegate(new PowerButtonControllerDelegateChromeos);
23 controller->set_delegate(new PowerButtonControllerDelegateChromeos);
24 39
25 registrar_.Add( 40 registrar_.Add(
26 this, 41 this,
27 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 42 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
28 content::NotificationService::AllSources()); 43 content::NotificationService::AllSources());
29 registrar_.Add( 44 registrar_.Add(
30 this, 45 this,
31 content::NOTIFICATION_APP_TERMINATING, 46 content::NOTIFICATION_APP_TERMINATING,
32 content::NotificationService::AllSources()); 47 content::NotificationService::AllSources());
33 registrar_.Add( 48 registrar_.Add(
34 this, 49 this,
35 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, 50 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
36 content::NotificationService::AllSources()); 51 content::NotificationService::AllSources());
37 52
38 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); 53 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
39 54
40 // Tell the controller about the initial state. 55 // Tell the controller about the initial state.
41 const UserManager* user_manager = UserManager::Get(); 56 ash::Shell::GetInstance()->OnLoginStateChanged(GetCurrentLoginStatus());
42 bool logged_in = user_manager->IsUserLoggedIn();
43 bool is_guest = logged_in && user_manager->GetLoggedInUser().is_guest();
44 controller->OnLoginStateChange(logged_in, is_guest);
45 57
46 const ScreenLocker* locker = ScreenLocker::default_screen_locker(); 58 const ScreenLocker* locker = ScreenLocker::default_screen_locker();
47 bool locked = locker && locker->locked(); 59 bool locked = locker && locker->locked();
48 controller->OnLockStateChange(locked); 60 ash::Shell::GetInstance()->OnLockStateChanged(locked);
49 } 61 }
50 62
51 PowerButtonObserver::~PowerButtonObserver() { 63 PowerButtonObserver::~PowerButtonObserver() {
52 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); 64 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
53 } 65 }
54 66
55 void PowerButtonObserver::Observe(int type, 67 void PowerButtonObserver::Observe(int type,
56 const content::NotificationSource& source, 68 const content::NotificationSource& source,
57 const content::NotificationDetails& details) { 69 const content::NotificationDetails& details) {
58 switch (type) { 70 switch (type) {
59 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { 71 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: {
60 const User* user = &UserManager::Get()->GetLoggedInUser(); 72 ash::Shell::GetInstance()->OnLoginStateChanged(GetCurrentLoginStatus());
61 ash::Shell::GetInstance()->power_button_controller()->
62 OnLoginStateChange(true /* logged_in */, user->is_guest());
63 break; 73 break;
64 } 74 }
65 case content::NOTIFICATION_APP_TERMINATING: 75 case content::NOTIFICATION_APP_TERMINATING:
66 ash::Shell::GetInstance()->power_button_controller()->OnExit(); 76 ash::Shell::GetInstance()->OnAppTerminating();
67 break; 77 break;
68 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { 78 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: {
69 bool locked = *content::Details<bool>(details).ptr(); 79 bool locked = *content::Details<bool>(details).ptr();
70 ash::Shell::GetInstance()->power_button_controller()-> 80 ash::Shell::GetInstance()->OnLockStateChanged(locked);
71 OnLockStateChange(locked);
72 break; 81 break;
73 } 82 }
74 default: 83 default:
75 NOTREACHED() << "Unexpected notification " << type; 84 NOTREACHED() << "Unexpected notification " << type;
76 } 85 }
77 } 86 }
78 87
79 void PowerButtonObserver::PowerButtonStateChanged( 88 void PowerButtonObserver::PowerButtonStateChanged(
80 bool down, const base::TimeTicks& timestamp) { 89 bool down, const base::TimeTicks& timestamp) {
81 ash::Shell::GetInstance()->power_button_controller()-> 90 ash::Shell::GetInstance()->power_button_controller()->
82 OnPowerButtonEvent(down, timestamp); 91 OnPowerButtonEvent(down, timestamp);
83 } 92 }
84 93
85 void PowerButtonObserver::LockButtonStateChanged( 94 void PowerButtonObserver::LockButtonStateChanged(
86 bool down, const base::TimeTicks& timestamp) { 95 bool down, const base::TimeTicks& timestamp) {
87 ash::Shell::GetInstance()->power_button_controller()-> 96 ash::Shell::GetInstance()->power_button_controller()->
88 OnLockButtonEvent(down, timestamp); 97 OnLockButtonEvent(down, timestamp);
89 } 98 }
90 99
91 void PowerButtonObserver::LockScreen() { 100 void PowerButtonObserver::LockScreen() {
92 ash::Shell::GetInstance()->power_button_controller()->OnStartingLock(); 101 ash::Shell::GetInstance()->power_button_controller()->OnStartingLock();
93 } 102 }
94 103
95 } // namespace chromeos 104 } // namespace chromeos
OLDNEW
« no previous file with comments | « 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