diff options
-rw-r--r-- | ash/shell.cc | 14 | ||||
-rw-r--r-- | ash/shell.h | 11 | ||||
-rw-r--r-- | ash/shell_observer.h | 11 | ||||
-rw-r--r-- | ash/wm/partial_screenshot_event_filter.cc | 19 | ||||
-rw-r--r-- | ash/wm/partial_screenshot_event_filter.h | 14 | ||||
-rw-r--r-- | ash/wm/power_button_controller.cc | 57 | ||||
-rw-r--r-- | ash/wm/power_button_controller.h | 33 | ||||
-rw-r--r-- | ash/wm/power_button_controller_unittest.cc | 66 | ||||
-rw-r--r-- | chrome/browser/chromeos/power/power_button_observer.cc | 37 |
9 files changed, 172 insertions, 90 deletions
diff --git a/ash/shell.cc b/ash/shell.cc index 3b0b0b8..8f4b072 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -657,6 +657,7 @@ void Shell::Init() { DCHECK_EQ(1U, GetRootWindowEventFilterCount()); partial_screenshot_filter_.reset(new internal::PartialScreenshotEventFilter); AddRootWindowEventFilter(partial_screenshot_filter_.get()); + AddShellObserver(partial_screenshot_filter_.get()); // Then AcceleratorFilter and InputMethodEventFilter must be added (in this // order) since they have the second highest priority. @@ -772,6 +773,7 @@ void Shell::Init() { drag_drop_controller_.reset(new internal::DragDropController); power_button_controller_.reset(new PowerButtonController); + AddShellObserver(power_button_controller_.get()); video_detector_.reset(new VideoDetector); window_cycle_controller_.reset(new WindowCycleController); monitor_controller_.reset(new internal::MonitorController); @@ -860,6 +862,18 @@ void Shell::SetMonitorWorkAreaInsets(Window* contains, OnMonitorWorkAreaInsetsChanged()); } +void Shell::OnLoginStateChanged(user::LoginStatus status) { + FOR_EACH_OBSERVER(ShellObserver, observers_, OnLoginStateChanged(status)); +} + +void Shell::OnAppTerminating() { + FOR_EACH_OBSERVER(ShellObserver, observers_, OnAppTerminating()); +} + +void Shell::OnLockStateChanged(bool locked) { + FOR_EACH_OBSERVER(ShellObserver, observers_, OnLockStateChanged(locked)); +} + void Shell::CreateLauncher() { if (launcher_.get()) return; diff --git a/ash/shell.h b/ash/shell.h index 690ae79..be8a058 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -10,6 +10,7 @@ #include <vector> #include "ash/ash_export.h" +#include "ash/system/user/login_status.h" #include "ash/wm/shelf_auto_hide_behavior.h" #include "base/basictypes.h" #include "base/compiler_specific.h" @@ -173,6 +174,16 @@ class ASH_EXPORT Shell { void SetMonitorWorkAreaInsets(aura::Window* window, const gfx::Insets& insets); + // Called when the user logs in. + void OnLoginStateChanged(user::LoginStatus status); + + // Called when the application is exiting. + void OnAppTerminating(); + + // Called when the screen is locked (after the lock window is visible) or + // unlocked. + void OnLockStateChanged(bool locked); + // Initializes |launcher_|. Does nothing if it's already initialized. void CreateLauncher(); diff --git a/ash/shell_observer.h b/ash/shell_observer.h index d9852bc..9c16668 100644 --- a/ash/shell_observer.h +++ b/ash/shell_observer.h @@ -7,6 +7,7 @@ #pragma once #include "ash/ash_export.h" +#include "ash/system/user/login_status.h" namespace ash { @@ -15,6 +16,16 @@ class ASH_EXPORT ShellObserver { // Invoked after the screen's work area insets changes. virtual void OnMonitorWorkAreaInsetsChanged() {} + // Invoked when the user logs in. + virtual void OnLoginStateChanged(user::LoginStatus status) {} + + // Invoked when the application is exiting. + virtual void OnAppTerminating() {} + + // Invoked when the screen is locked (after the lock window is visible) or + // unlocked. + virtual void OnLockStateChanged(bool locked) {} + protected: virtual ~ShellObserver() {} }; diff --git a/ash/wm/partial_screenshot_event_filter.cc b/ash/wm/partial_screenshot_event_filter.cc index ce21e00..02c202b 100644 --- a/ash/wm/partial_screenshot_event_filter.cc +++ b/ash/wm/partial_screenshot_event_filter.cc @@ -32,7 +32,7 @@ bool PartialScreenshotEventFilter::PreHandleKeyEvent( } if (event->key_code() == ui::VKEY_ESCAPE) - view_->Cancel(); + Cancel(); // Always handled: other windows shouldn't receive input while we're // taking a screenshot. @@ -54,6 +54,19 @@ ui::GestureStatus PartialScreenshotEventFilter::PreHandleGestureEvent( return ui::GESTURE_STATUS_UNKNOWN; // Not handled. } +void PartialScreenshotEventFilter::OnLoginStateChanged( + user::LoginStatus status) { + Cancel(); +} + +void PartialScreenshotEventFilter::OnAppTerminating() { + Cancel(); +} + +void PartialScreenshotEventFilter::OnLockStateChanged(bool locked) { + Cancel(); +} + void PartialScreenshotEventFilter::Activate(PartialScreenshotView* view) { view_ = view; } @@ -62,5 +75,9 @@ void PartialScreenshotEventFilter::Deactivate() { view_ = NULL; } +void PartialScreenshotEventFilter::Cancel() { + if (view_) + view_->Cancel(); +} } // namespace internal } // namespace ash diff --git a/ash/wm/partial_screenshot_event_filter.h b/ash/wm/partial_screenshot_event_filter.h index 5f045de..285d3e7 100644 --- a/ash/wm/partial_screenshot_event_filter.h +++ b/ash/wm/partial_screenshot_event_filter.h @@ -6,6 +6,7 @@ #define ASH_WM_PARTIAL_SCREENSHOT_EVENT_FILTER_H_ #pragma once +#include "ash/shell_observer.h" #include "base/compiler_specific.h" #include "ui/aura/event.h" #include "ui/aura/event_filter.h" @@ -20,7 +21,8 @@ namespace internal { // main task of this event filter is just to stop propagation of any // key events during activation, and also signal cancellation when Esc is // pressed. -class PartialScreenshotEventFilter : public aura::EventFilter { +class PartialScreenshotEventFilter : public aura::EventFilter, + public ShellObserver { public: PartialScreenshotEventFilter(); virtual ~PartialScreenshotEventFilter(); @@ -34,7 +36,10 @@ class PartialScreenshotEventFilter : public aura::EventFilter { // End the filtering of events. void Deactivate(); - // Overridden from aura::EventFilter: + // Cancels the partial screenshot UI. Do nothing if it's not activated. + void Cancel(); + + // aura::EventFilter overrides: virtual bool PreHandleKeyEvent( aura::Window* target, aura::KeyEvent* event) OVERRIDE; virtual bool PreHandleMouseEvent( @@ -44,6 +49,11 @@ class PartialScreenshotEventFilter : public aura::EventFilter { virtual ui::GestureStatus PreHandleGestureEvent( aura::Window* target, aura::GestureEvent* event) OVERRIDE; + // ShellObserver overrides: + virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; + virtual void OnAppTerminating() OVERRIDE; + virtual void OnLockStateChanged(bool locked) OVERRIDE; + private: PartialScreenshotView* view_; diff --git a/ash/wm/power_button_controller.cc b/ash/wm/power_button_controller.cc index aadedaa..885d3dd 100644 --- a/ash/wm/power_button_controller.cc +++ b/ash/wm/power_button_controller.cc @@ -276,9 +276,8 @@ bool PowerButtonController::TestApi::BackgroundLayerIsVisible() const { } PowerButtonController::PowerButtonController() - : logged_in_(false), - is_guest_(false), - locked_(false), + : login_status_(user::LOGGED_IN_NONE), + unlocked_login_status_(user::LOGGED_IN_NONE), power_button_down_(false), lock_button_down_(false), shutting_down_(false), @@ -290,12 +289,12 @@ PowerButtonController::PowerButtonController() PowerButtonController::~PowerButtonController() { } -void PowerButtonController::OnLoginStateChange(bool logged_in, bool is_guest) { - logged_in_ = logged_in; - is_guest_ = is_guest; +void PowerButtonController::OnLoginStateChanged(user::LoginStatus status) { + login_status_ = status; + unlocked_login_status_ = user::LOGGED_IN_NONE; } -void PowerButtonController::OnExit() { +void PowerButtonController::OnAppTerminating() { // If we hear that Chrome is exiting but didn't request it ourselves, all we // can really hope for is that we'll have time to clear the screen. if (!shutting_down_) { @@ -308,11 +307,18 @@ void PowerButtonController::OnExit() { } } -void PowerButtonController::OnLockStateChange(bool locked) { - if (shutting_down_ || locked_ == locked) +void PowerButtonController::OnLockStateChanged(bool locked) { + if (shutting_down_ || (login_status_ == user::LOGGED_IN_LOCKED) == locked) return; - locked_ = locked; + if (!locked && login_status_ == user::LOGGED_IN_LOCKED) { + login_status_ = unlocked_login_status_; + unlocked_login_status_ = user::LOGGED_IN_NONE; + } else { + unlocked_login_status_ = login_status_; + login_status_ = user::LOGGED_IN_LOCKED; + } + if (locked) { StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_FADE_IN); lock_timer_.Stop(); @@ -333,7 +339,7 @@ void PowerButtonController::OnLockStateChange(bool locked) { } void PowerButtonController::OnStartingLock() { - if (shutting_down_ || locked_) + if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED) return; // Ensure that the background layer is visible -- if the screen was locked via @@ -361,7 +367,7 @@ void PowerButtonController::OnPowerButtonEvent( // immediately. if (down) { ShowBackgroundLayer(); - if (logged_in_as_non_guest() && !locked_) { + if (LoggedInAsNonGuest() && login_status_ != user::LOGGED_IN_LOCKED) { StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, ANIMATION_SLOW_CLOSE); OnLockTimeout(); @@ -375,19 +381,20 @@ void PowerButtonController::OnPowerButtonEvent( if (lock_fail_timer_.IsRunning()) return; - if (logged_in_as_non_guest() && !locked_) + if (LoggedInAsNonGuest() && login_status_ != user::LOGGED_IN_LOCKED) StartLockTimer(); else StartShutdownTimer(); } else { // Button is up. if (lock_timer_.IsRunning() || shutdown_timer_.IsRunning()) StartAnimation( - locked_ ? SCREEN_LOCKER_AND_RELATED_CONTAINERS : ALL_CONTAINERS, + (login_status_ == user::LOGGED_IN_LOCKED) ? + SCREEN_LOCKER_AND_RELATED_CONTAINERS : ALL_CONTAINERS, ANIMATION_UNDO_SLOW_CLOSE); // Drop the background layer after the undo animation finishes. if (lock_timer_.IsRunning() || - (shutdown_timer_.IsRunning() && !logged_in_as_non_guest())) { + (shutdown_timer_.IsRunning() && !LoggedInAsNonGuest())) { hide_background_layer_timer_.Stop(); hide_background_layer_timer_.Start( FROM_HERE, @@ -406,14 +413,15 @@ void PowerButtonController::OnLockButtonEvent( bool down, const base::TimeTicks& timestamp) { lock_button_down_ = down; - if (shutting_down_ || !logged_in_as_non_guest()) + if (shutting_down_ || !LoggedInAsNonGuest()) return; // Bail if we're already locked or are in the process of locking. Also give // the power button precedence over the lock button (we don't expect both // buttons to be present, so this is just making sure that we don't do // something completely stupid if that assumption changes later). - if (locked_ || lock_fail_timer_.IsRunning() || power_button_down_) + if (login_status_ == user::LOGGED_IN_LOCKED || + lock_fail_timer_.IsRunning() || power_button_down_) return; if (down) { @@ -443,6 +451,15 @@ void PowerButtonController::OnRootWindowResized(const aura::RootWindow* root, background_layer_->SetBounds(gfx::Rect(root->bounds().size())); } +bool PowerButtonController::LoggedInAsNonGuest() const { + if (login_status_ == user::LOGGED_IN_NONE) + return false; + if (login_status_ == user::LOGGED_IN_GUEST) + return false; + // TODO(mukai): think about kiosk mode. + return true; +} + void PowerButtonController::OnLockTimeout() { delegate_->RequestLockScreen(); lock_fail_timer_.Start( @@ -452,7 +469,7 @@ void PowerButtonController::OnLockTimeout() { } void PowerButtonController::OnLockFailTimeout() { - DCHECK(!locked_); + DCHECK_NE(login_status_, user::LOGGED_IN_LOCKED); LOG(ERROR) << "Screen lock request timed out"; StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, ANIMATION_RESTORE); @@ -460,7 +477,7 @@ void PowerButtonController::OnLockFailTimeout() { } void PowerButtonController::OnLockToShutdownTimeout() { - DCHECK(locked_); + DCHECK_EQ(login_status_, user::LOGGED_IN_LOCKED); StartShutdownTimer(); } @@ -502,7 +519,7 @@ void PowerButtonController::StartShutdownAnimationAndRequestShutdown() { Shell::GetRootWindow()->ShowCursor(false); ShowBackgroundLayer(); - if (!logged_in_ || locked_) { + if (login_status_ != user::LOGGED_IN_NONE) { // Hide the other containers before starting the animation. // ANIMATION_FAST_CLOSE will make the screen locker windows partially // transparent, and we don't want the other windows to show through. diff --git a/ash/wm/power_button_controller.h b/ash/wm/power_button_controller.h index 19f26fe..27dd66f 100644 --- a/ash/wm/power_button_controller.h +++ b/ash/wm/power_button_controller.h @@ -7,6 +7,7 @@ #pragma once #include "ash/ash_export.h" +#include "ash/shell_observer.h" #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "base/time.h" @@ -38,7 +39,8 @@ class ASH_EXPORT PowerButtonControllerDelegate { // Displays onscreen animations and locks or suspends the system in response to // the power button being pressed or released. -class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver { +class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver, + public ShellObserver { public: // Animations that can be applied to groups of containers. // Exposed here for TestApi::ContainerGroupIsAnimated(). @@ -135,16 +137,6 @@ class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver { has_legacy_power_button_ = legacy; } - // Called when the user logs in. - void OnLoginStateChange(bool logged_in, bool is_guest); - - // Called when the application is exiting. - void OnExit(); - - // Called when the screen is locked (after the lock window is visible) or - // unlocked. - void OnLockStateChange(bool locked); - // Called when Chrome gets a request to display the lock screen. void OnStartingLock(); @@ -159,8 +151,13 @@ class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver { virtual void OnRootWindowResized(const aura::RootWindow* root, const gfx::Size& old_size) OVERRIDE; + // ShellObserver overrides: + virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; + virtual void OnAppTerminating() OVERRIDE; + virtual void OnLockStateChanged(bool locked) OVERRIDE; + private: - bool logged_in_as_non_guest() const { return logged_in_ && !is_guest_; } + bool LoggedInAsNonGuest() const; // Requests that the screen be locked and starts |lock_fail_timer_|. void OnLockTimeout(); @@ -191,15 +188,11 @@ class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver { scoped_ptr<PowerButtonControllerDelegate> delegate_; - // True if the user is currently logged in. - bool logged_in_; - - // True if a guest user is currently logged in. Unused if |logged_in_| is - // false. - bool is_guest_; + // The current login status. + user::LoginStatus login_status_; - // True if the screen is currently locked. - bool locked_; + // Original login status during locked. LOGGED_IN_NONE if it's not locked. + user::LoginStatus unlocked_login_status_; // Are the power or lock buttons currently held? bool power_button_down_; diff --git a/ash/wm/power_button_controller_unittest.cc b/ash/wm/power_button_controller_unittest.cc index 7558c65..ba6316c 100644 --- a/ash/wm/power_button_controller_unittest.cc +++ b/ash/wm/power_button_controller_unittest.cc @@ -67,8 +67,8 @@ class PowerButtonControllerTest : public AshTestBase { // state. TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { controller_->set_has_legacy_power_button_for_test(true); - controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); - controller_->OnLockStateChange(false); + controller_->OnLoginStateChanged(user::LOGGED_IN_USER); + controller_->OnLockStateChanged(false); // We should request that the screen be locked immediately after seeing the // power button get pressed. @@ -94,7 +94,7 @@ TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { PowerButtonController::ANIMATION_HIDE)); // Notify that the lock window is visible. We should make it fade in. - controller_->OnLockStateChange(true); + controller_->OnLockStateChanged(true); EXPECT_TRUE( test_api_->ContainerGroupIsAnimated( PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS, @@ -122,8 +122,8 @@ TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { // while we're not logged in on an unofficial system. TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) { controller_->set_has_legacy_power_button_for_test(true); - controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); - controller_->OnLockStateChange(false); + controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); + controller_->OnLockStateChanged(false); controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); } @@ -132,8 +132,8 @@ TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) { // while we're logged in as a guest on an unofficial system. TEST_F(PowerButtonControllerTest, LegacyGuest) { controller_->set_has_legacy_power_button_for_test(true); - controller_->OnLoginStateChange(true /*logged_in*/, true /*is_guest*/); - controller_->OnLockStateChange(false); + controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); + controller_->OnLockStateChanged(false); controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); } @@ -142,8 +142,8 @@ TEST_F(PowerButtonControllerTest, LegacyGuest) { // down the machine directly. TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) { controller_->set_has_legacy_power_button_for_test(false); - controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); - controller_->OnLockStateChange(false); + controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); + controller_->OnLockStateChanged(false); EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); // Press the power button and check that we start the shutdown timer. @@ -195,8 +195,8 @@ TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) { // Test that we lock the screen and deal with unlocking correctly. TEST_F(PowerButtonControllerTest, LockAndUnlock) { controller_->set_has_legacy_power_button_for_test(false); - controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); - controller_->OnLockStateChange(false); + controller_->OnLoginStateChanged(user::LOGGED_IN_USER); + controller_->OnLockStateChanged(false); EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); // We should initially be showing the screen locker containers, since they @@ -255,7 +255,7 @@ TEST_F(PowerButtonControllerTest, LockAndUnlock) { PowerButtonController::ANIMATION_HIDE)); // Notify that the lock window is visible. We should make it fade in. - controller_->OnLockStateChange(true); + controller_->OnLockStateChanged(true); EXPECT_TRUE( test_api_->ContainerGroupIsAnimated( PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS, @@ -269,7 +269,7 @@ TEST_F(PowerButtonControllerTest, LockAndUnlock) { // Notify that the screen has been unlocked. We should show the // non-screen-locker windows and hide the background layer. - controller_->OnLockStateChange(false); + controller_->OnLockStateChanged(false); EXPECT_TRUE( test_api_->ContainerGroupIsAnimated( PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, @@ -280,15 +280,15 @@ TEST_F(PowerButtonControllerTest, LockAndUnlock) { // Hold the power button down from the unlocked state to eventual shutdown. TEST_F(PowerButtonControllerTest, LockToShutdown) { controller_->set_has_legacy_power_button_for_test(false); - controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); - controller_->OnLockStateChange(false); + controller_->OnLoginStateChanged(user::LOGGED_IN_USER); + controller_->OnLockStateChanged(false); // Hold the power button and lock the screen. controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); EXPECT_TRUE(test_api_->lock_timer_is_running()); test_api_->trigger_lock_timeout(); controller_->OnStartingLock(); - controller_->OnLockStateChange(true); + controller_->OnLockStateChanged(true); EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); // When the lock-to-shutdown timeout fires, we should start the shutdown @@ -316,8 +316,8 @@ TEST_F(PowerButtonControllerTest, LockFail) { ui::LayerAnimator::set_disable_animations_for_test(false); controller_->set_has_legacy_power_button_for_test(false); - controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); - controller_->OnLockStateChange(false); + controller_->OnLoginStateChanged(user::LOGGED_IN_USER); + controller_->OnLockStateChanged(false); // Hold the power button and lock the screen. controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); @@ -349,8 +349,8 @@ TEST_F(PowerButtonControllerTest, LockFail) { // again before the timer has fired. TEST_F(PowerButtonControllerTest, CancelHideBackground) { controller_->set_has_legacy_power_button_for_test(false); - controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); - controller_->OnLockStateChange(false); + controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); + controller_->OnLockStateChanged(false); controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); @@ -365,15 +365,15 @@ TEST_F(PowerButtonControllerTest, CancelHideBackground) { TEST_F(PowerButtonControllerTest, LockButtonBasic) { controller_->set_has_legacy_power_button_for_test(false); // The lock button shouldn't do anything if we aren't logged in. - controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); - controller_->OnLockStateChange(false); + controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); + controller_->OnLockStateChanged(false); controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); EXPECT_FALSE(test_api_->lock_timer_is_running()); controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); EXPECT_EQ(0, delegate_->num_lock_requests()); // Ditto for when we're logged in as a guest. - controller_->OnLoginStateChange(true /*logged_in*/, true /*is_guest*/); + controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); EXPECT_FALSE(test_api_->lock_timer_is_running()); controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); @@ -381,7 +381,7 @@ TEST_F(PowerButtonControllerTest, LockButtonBasic) { // If we're logged in as a regular user, we should start the lock timer and // the pre-lock animation. - controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); + controller_->OnLoginStateChanged(user::LOGGED_IN_USER); controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); EXPECT_TRUE(test_api_->lock_timer_is_running()); EXPECT_TRUE( @@ -419,7 +419,7 @@ TEST_F(PowerButtonControllerTest, LockButtonBasic) { // Pressing the button also shouldn't do anything after the screen is locked. controller_->OnStartingLock(); - controller_->OnLockStateChange(true); + controller_->OnLockStateChanged(true); controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); EXPECT_FALSE(test_api_->lock_timer_is_running()); controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); @@ -428,8 +428,8 @@ TEST_F(PowerButtonControllerTest, LockButtonBasic) { // Test that the power button takes priority over the lock button. TEST_F(PowerButtonControllerTest, PowerButtonPreemptsLockButton) { controller_->set_has_legacy_power_button_for_test(false); - controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); - controller_->OnLockStateChange(false); + controller_->OnLoginStateChanged(user::LOGGED_IN_USER); + controller_->OnLockStateChanged(false); // While the lock button is down, hold the power button. controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); @@ -460,7 +460,7 @@ TEST_F(PowerButtonControllerTest, PowerButtonPreemptsLockButton) { // slow-close path (e.g. via the wrench menu), test that we still show the // fast-close animation and display the background layer. TEST_F(PowerButtonControllerTest, LockWithoutButton) { - controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); + controller_->OnLoginStateChanged(user::LOGGED_IN_USER); controller_->OnStartingLock(); EXPECT_TRUE( test_api_->ContainerGroupIsAnimated( @@ -472,8 +472,8 @@ TEST_F(PowerButtonControllerTest, LockWithoutButton) { // When we hear that the process is exiting but we haven't had a chance to // display an animation, we should just blank the screen. TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { - controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); - controller_->OnExit(); + controller_->OnLoginStateChanged(user::LOGGED_IN_USER); + controller_->OnAppTerminating(); EXPECT_TRUE( test_api_->ContainerGroupIsAnimated( PowerButtonController::ALL_CONTAINERS, @@ -485,7 +485,7 @@ TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { // Test that we display the fast-close animation and shut down when we get an // outside request to shut down (e.g. from the login or lock screen). TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { - controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); + controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); controller_->RequestShutdown(); EXPECT_TRUE( test_api_->ContainerGroupIsAnimated( @@ -505,8 +505,8 @@ TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { } TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { - controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); - controller_->OnLockStateChange(true); + controller_->OnLoginStateChanged(user::LOGGED_IN_USER); + controller_->OnLockStateChanged(true); controller_->RequestShutdown(); EXPECT_TRUE( test_api_->ContainerGroupIsAnimated( diff --git a/chrome/browser/chromeos/power/power_button_observer.cc b/chrome/browser/chromeos/power/power_button_observer.cc index b7c0707..a10e5b5 100644 --- a/chrome/browser/chromeos/power/power_button_observer.cc +++ b/chrome/browser/chromeos/power/power_button_observer.cc @@ -5,6 +5,7 @@ #include "chrome/browser/chromeos/power/power_button_observer.h" #include "ash/shell.h" +#include "ash/system/user/login_status.h" #include "ash/wm/power_button_controller.h" #include "base/logging.h" #include "chrome/browser/chromeos/login/screen_locker.h" @@ -17,10 +18,24 @@ namespace chromeos { +namespace { + +ash::user::LoginStatus GetCurrentLoginStatus() { + const UserManager* user_manager = UserManager::Get(); + if (!user_manager->IsUserLoggedIn()) + return ash::user::LOGGED_IN_NONE; + + if (user_manager->GetLoggedInUser().is_guest()) + return ash::user::LOGGED_IN_GUEST; + + return ash::user::LOGGED_IN_USER; +} + +} // namespace + PowerButtonObserver::PowerButtonObserver() { - ash::PowerButtonController* controller = - ash::Shell::GetInstance()->power_button_controller(); - controller->set_delegate(new PowerButtonControllerDelegateChromeos); + ash::Shell::GetInstance()->power_button_controller()-> + set_delegate(new PowerButtonControllerDelegateChromeos); registrar_.Add( this, @@ -38,14 +53,11 @@ PowerButtonObserver::PowerButtonObserver() { DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); // Tell the controller about the initial state. - const UserManager* user_manager = UserManager::Get(); - bool logged_in = user_manager->IsUserLoggedIn(); - bool is_guest = logged_in && user_manager->GetLoggedInUser().is_guest(); - controller->OnLoginStateChange(logged_in, is_guest); + ash::Shell::GetInstance()->OnLoginStateChanged(GetCurrentLoginStatus()); const ScreenLocker* locker = ScreenLocker::default_screen_locker(); bool locked = locker && locker->locked(); - controller->OnLockStateChange(locked); + ash::Shell::GetInstance()->OnLockStateChanged(locked); } PowerButtonObserver::~PowerButtonObserver() { @@ -57,18 +69,15 @@ void PowerButtonObserver::Observe(int type, const content::NotificationDetails& details) { switch (type) { case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { - const User* user = &UserManager::Get()->GetLoggedInUser(); - ash::Shell::GetInstance()->power_button_controller()-> - OnLoginStateChange(true /* logged_in */, user->is_guest()); + ash::Shell::GetInstance()->OnLoginStateChanged(GetCurrentLoginStatus()); break; } case content::NOTIFICATION_APP_TERMINATING: - ash::Shell::GetInstance()->power_button_controller()->OnExit(); + ash::Shell::GetInstance()->OnAppTerminating(); break; case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { bool locked = *content::Details<bool>(details).ptr(); - ash::Shell::GetInstance()->power_button_controller()-> - OnLockStateChange(locked); + ash::Shell::GetInstance()->OnLockStateChanged(locked); break; } default: |