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

Side by Side Diff: ash/wm/power_button_controller.cc

Issue 14295008: Add ash SessionStateDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 7 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
« no previous file with comments | « ash/wm/gestures/shelf_gesture_handler.cc ('k') | ash/wm/power_button_controller_unittest.cc » ('j') | 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 "ash/wm/power_button_controller.h" 5 #include "ash/wm/power_button_controller.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/session_state_delegate.h"
8 #include "ash/shell.h" 9 #include "ash/shell.h"
9 #include "ash/shell_delegate.h"
10 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
11 #include "ash/wm/session_state_animator.h" 11 #include "ash/wm/session_state_animator.h"
12 #include "ash/wm/session_state_controller.h" 12 #include "ash/wm/session_state_controller.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "ui/aura/root_window.h" 14 #include "ui/aura/root_window.h"
15 #include "ui/views/corewm/compound_event_filter.h" 15 #include "ui/views/corewm/compound_event_filter.h"
16 16
17 namespace ash { 17 namespace ash {
18 18
19 PowerButtonController::PowerButtonController(SessionStateController* controller) 19 PowerButtonController::PowerButtonController(SessionStateController* controller)
(...skipping 18 matching lines...) Expand all
38 power_button_down_ = down; 38 power_button_down_ = down;
39 39
40 if (controller_->ShutdownRequested()) 40 if (controller_->ShutdownRequested())
41 return; 41 return;
42 42
43 // Avoid starting the lock/shutdown sequence if the power button is pressed 43 // Avoid starting the lock/shutdown sequence if the power button is pressed
44 // while the screen is off (http://crbug.com/128451). 44 // while the screen is off (http://crbug.com/128451).
45 if (screen_is_off_) 45 if (screen_is_off_)
46 return; 46 return;
47 47
48 Shell* shell = Shell::GetInstance(); 48 const SessionStateDelegate* session_state_delegate =
49 Shell::GetInstance()->session_state_delegate();
49 if (has_legacy_power_button_) { 50 if (has_legacy_power_button_) {
50 // If power button releases won't get reported correctly because we're not 51 // If power button releases won't get reported correctly because we're not
51 // running on official hardware, just lock the screen or shut down 52 // running on official hardware, just lock the screen or shut down
52 // immediately. 53 // immediately.
53 if (down) { 54 if (down) {
54 if (shell->CanLockScreen() && !shell->IsScreenLocked() && 55 if (session_state_delegate->CanLockScreen() &&
56 !session_state_delegate->IsScreenLocked() &&
55 !controller_->LockRequested()) { 57 !controller_->LockRequested()) {
56 controller_->StartLockAnimationAndLockImmediately(); 58 controller_->StartLockAnimationAndLockImmediately();
57 } else { 59 } else {
58 controller_->RequestShutdown(); 60 controller_->RequestShutdown();
59 } 61 }
60 } 62 }
61 } else { // !has_legacy_power_button_ 63 } else { // !has_legacy_power_button_
62 if (down) { 64 if (down) {
63 // If we already have a pending request to lock the screen, wait. 65 // If we already have a pending request to lock the screen, wait.
64 if (controller_->LockRequested()) 66 if (controller_->LockRequested())
65 return; 67 return;
66 68
67 if (shell->CanLockScreen() && !shell->IsScreenLocked()) 69 if (session_state_delegate->CanLockScreen() &&
70 !session_state_delegate->IsScreenLocked()) {
68 controller_->StartLockAnimation(true); 71 controller_->StartLockAnimation(true);
69 else 72 } else {
70 controller_->StartShutdownAnimation(); 73 controller_->StartShutdownAnimation();
74 }
71 } else { // Button is up. 75 } else { // Button is up.
72 if (controller_->CanCancelLockAnimation()) 76 if (controller_->CanCancelLockAnimation())
73 controller_->CancelLockAnimation(); 77 controller_->CancelLockAnimation();
74 else if (controller_->CanCancelShutdownAnimation()) 78 else if (controller_->CanCancelShutdownAnimation())
75 controller_->CancelShutdownAnimation(); 79 controller_->CancelShutdownAnimation();
76 } 80 }
77 } 81 }
78 } 82 }
79 83
80 void PowerButtonController::OnLockButtonEvent( 84 void PowerButtonController::OnLockButtonEvent(
81 bool down, const base::TimeTicks& timestamp) { 85 bool down, const base::TimeTicks& timestamp) {
82 lock_button_down_ = down; 86 lock_button_down_ = down;
83 87
84 Shell* shell = Shell::GetInstance(); 88 const SessionStateDelegate* session_state_delegate =
85 if (!shell->CanLockScreen() || shell->IsScreenLocked() || 89 Shell::GetInstance()->session_state_delegate();
86 controller_->LockRequested() || controller_->ShutdownRequested()) { 90 if (!session_state_delegate->CanLockScreen() ||
91 session_state_delegate->IsScreenLocked() ||
92 controller_->LockRequested() ||
93 controller_->ShutdownRequested()) {
87 return; 94 return;
88 } 95 }
89 96
90 // Give the power button precedence over the lock button (we don't expect both 97 // Give the power button precedence over the lock button (we don't expect both
91 // buttons to be present, so this is just making sure that we don't do 98 // buttons to be present, so this is just making sure that we don't do
92 // something completely stupid if that assumption changes later). 99 // something completely stupid if that assumption changes later).
93 if (power_button_down_) 100 if (power_button_down_)
94 return; 101 return;
95 102
96 if (down) 103 if (down)
97 controller_->StartLockAnimation(false); 104 controller_->StartLockAnimation(false);
98 else 105 else
99 controller_->CancelLockAnimation(); 106 controller_->CancelLockAnimation();
100 } 107 }
101 108
102 } // namespace ash 109 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/gestures/shelf_gesture_handler.cc ('k') | ash/wm/power_button_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698