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

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 observers 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
« ash/shell_observer.h ('K') | « ash/wm/power_button_controller.h ('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/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 bool logged_in = user_manager->IsUserLoggedIn();
43 bool is_guest = logged_in && user_manager->GetLoggedInUser().is_guest(); 42 bool is_guest = logged_in && user_manager->GetLoggedInUser().is_guest();
44 controller->OnLoginStateChange(logged_in, is_guest); 43 ash::Shell::GetInstance()->OnLoginStateChange(logged_in, is_guest);
45 44
46 const ScreenLocker* locker = ScreenLocker::default_screen_locker(); 45 const ScreenLocker* locker = ScreenLocker::default_screen_locker();
47 bool locked = locker && locker->locked(); 46 bool locked = locker && locker->locked();
48 controller->OnLockStateChange(locked); 47 ash::Shell::GetInstance()->OnLockStateChange(locked);
49 } 48 }
50 49
51 PowerButtonObserver::~PowerButtonObserver() { 50 PowerButtonObserver::~PowerButtonObserver() {
52 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); 51 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
53 } 52 }
54 53
55 void PowerButtonObserver::Observe(int type, 54 void PowerButtonObserver::Observe(int type,
56 const content::NotificationSource& source, 55 const content::NotificationSource& source,
57 const content::NotificationDetails& details) { 56 const content::NotificationDetails& details) {
58 switch (type) { 57 switch (type) {
59 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { 58 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: {
60 const User* user = &UserManager::Get()->GetLoggedInUser(); 59 const User* user = &UserManager::Get()->GetLoggedInUser();
61 ash::Shell::GetInstance()->power_button_controller()-> 60 ash::Shell::GetInstance()->
62 OnLoginStateChange(true /* logged_in */, user->is_guest()); 61 OnLoginStateChange(true /* logged_in */, user->is_guest());
63 break; 62 break;
64 } 63 }
65 case content::NOTIFICATION_APP_TERMINATING: 64 case content::NOTIFICATION_APP_TERMINATING:
66 ash::Shell::GetInstance()->power_button_controller()->OnExit(); 65 ash::Shell::GetInstance()->OnExit();
67 break; 66 break;
68 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { 67 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: {
69 bool locked = *content::Details<bool>(details).ptr(); 68 bool locked = *content::Details<bool>(details).ptr();
70 ash::Shell::GetInstance()->power_button_controller()-> 69 ash::Shell::GetInstance()->OnLockStateChange(locked);
71 OnLockStateChange(locked);
72 break; 70 break;
73 } 71 }
74 default: 72 default:
75 NOTREACHED() << "Unexpected notification " << type; 73 NOTREACHED() << "Unexpected notification " << type;
76 } 74 }
77 } 75 }
78 76
79 void PowerButtonObserver::PowerButtonStateChanged( 77 void PowerButtonObserver::PowerButtonStateChanged(
80 bool down, const base::TimeTicks& timestamp) { 78 bool down, const base::TimeTicks& timestamp) {
81 ash::Shell::GetInstance()->power_button_controller()-> 79 ash::Shell::GetInstance()->power_button_controller()->
82 OnPowerButtonEvent(down, timestamp); 80 OnPowerButtonEvent(down, timestamp);
83 } 81 }
84 82
85 void PowerButtonObserver::LockButtonStateChanged( 83 void PowerButtonObserver::LockButtonStateChanged(
86 bool down, const base::TimeTicks& timestamp) { 84 bool down, const base::TimeTicks& timestamp) {
87 ash::Shell::GetInstance()->power_button_controller()-> 85 ash::Shell::GetInstance()->power_button_controller()->
88 OnLockButtonEvent(down, timestamp); 86 OnLockButtonEvent(down, timestamp);
89 } 87 }
90 88
91 void PowerButtonObserver::LockScreen() { 89 void PowerButtonObserver::LockScreen() {
92 ash::Shell::GetInstance()->power_button_controller()->OnStartingLock(); 90 ash::Shell::GetInstance()->power_button_controller()->OnStartingLock();
93 } 91 }
94 92
95 } // namespace chromeos 93 } // namespace chromeos
OLDNEW
« ash/shell_observer.h ('K') | « ash/wm/power_button_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698