| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/system/chromeos/power/suspend_observer.h" | 5 #include "ash/system/chromeos/power/power_event_observer.h" |
| 6 | 6 |
| 7 #include "ash/session_state_delegate.h" | 7 #include "ash/session_state_delegate.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/system/tray/system_tray_notifier.h" |
| 10 #include "ash/wm/power_button_controller.h" |
| 9 #include "ash/wm/user_activity_detector.h" | 11 #include "ash/wm/user_activity_detector.h" |
| 10 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 11 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
| 12 #include "chromeos/display/output_configurator.h" | 14 #include "chromeos/display/output_configurator.h" |
| 13 | 15 |
| 14 namespace ash { | 16 namespace ash { |
| 15 namespace internal { | 17 namespace internal { |
| 16 | 18 |
| 17 SuspendObserver::SuspendObserver() | 19 PowerEventObserver::PowerEventObserver() { |
| 18 : power_client_( | 20 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 19 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()), | 21 AddObserver(this); |
| 20 session_client_( | 22 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> |
| 21 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()), | 23 AddObserver(this); |
| 22 screen_locked_(false) { | |
| 23 power_client_->AddObserver(this); | |
| 24 session_client_->AddObserver(this); | |
| 25 } | 24 } |
| 26 | 25 |
| 27 SuspendObserver::~SuspendObserver() { | 26 PowerEventObserver::~PowerEventObserver() { |
| 28 session_client_->RemoveObserver(this); | 27 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 29 session_client_ = NULL; | 28 RemoveObserver(this); |
| 30 power_client_->RemoveObserver(this); | 29 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> |
| 31 power_client_ = NULL; | 30 RemoveObserver(this); |
| 32 } | 31 } |
| 33 | 32 |
| 34 void SuspendObserver::SuspendImminent() { | 33 void PowerEventObserver::BrightnessChanged(int level, bool user_initiated) { |
| 34 Shell::GetInstance()->power_button_controller()->OnScreenBrightnessChanged( |
| 35 static_cast<double>(level)); |
| 36 } |
| 37 |
| 38 void PowerEventObserver::SuspendImminent() { |
| 35 Shell* shell = Shell::GetInstance(); | 39 Shell* shell = Shell::GetInstance(); |
| 36 SessionStateDelegate* delegate = shell->session_state_delegate(); | 40 SessionStateDelegate* delegate = shell->session_state_delegate(); |
| 37 | 41 |
| 38 // If the lock-before-suspending pref is set, get a callback to block | 42 // If the lock-before-suspending pref is set, get a callback to block |
| 39 // suspend and ask the session manager to lock the screen. | 43 // suspend and ask the session manager to lock the screen. |
| 40 if (!screen_locked_ && delegate->ShouldLockScreenBeforeSuspending() && | 44 if (!screen_locked_ && delegate->ShouldLockScreenBeforeSuspending() && |
| 41 delegate->CanLockScreen()) { | 45 delegate->CanLockScreen()) { |
| 42 screen_lock_callback_ = power_client_->GetSuspendReadinessCallback(); | 46 screen_lock_callback_ = chromeos::DBusThreadManager::Get()-> |
| 43 VLOG(1) << "Requesting screen lock from SuspendObserver"; | 47 GetPowerManagerClient()->GetSuspendReadinessCallback(); |
| 44 session_client_->RequestLockScreen(); | 48 VLOG(1) << "Requesting screen lock from PowerEventObserver"; |
| 49 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> |
| 50 RequestLockScreen(); |
| 45 } | 51 } |
| 46 | 52 |
| 47 shell->user_activity_detector()->OnDisplayPowerChanging(); | 53 shell->user_activity_detector()->OnDisplayPowerChanging(); |
| 48 shell->output_configurator()->SuspendDisplays(); | 54 shell->output_configurator()->SuspendDisplays(); |
| 49 } | 55 } |
| 50 | 56 |
| 51 void SuspendObserver::ScreenIsLocked() { | 57 void PowerEventObserver::SystemResumed(const base::TimeDelta& sleep_duration) { |
| 58 Shell::GetInstance()->output_configurator()->ResumeDisplays(); |
| 59 Shell::GetInstance()->system_tray_notifier()->NotifyRefreshClock(); |
| 60 } |
| 61 |
| 62 void PowerEventObserver::ScreenIsLocked() { |
| 52 screen_locked_ = true; | 63 screen_locked_ = true; |
| 53 | 64 |
| 54 // Stop blocking suspend after the screen is locked. | 65 // Stop blocking suspend after the screen is locked. |
| 55 if (!screen_lock_callback_.is_null()) { | 66 if (!screen_lock_callback_.is_null()) { |
| 56 VLOG(1) << "Screen locked due to suspend"; | 67 VLOG(1) << "Screen locked due to suspend"; |
| 57 // Run the callback asynchronously. ScreenIsLocked() is currently | 68 // Run the callback asynchronously. ScreenIsLocked() is currently |
| 58 // called asynchronously after RequestLockScreen(), but this guards | 69 // called asynchronously after RequestLockScreen(), but this guards |
| 59 // against it being made synchronous later. | 70 // against it being made synchronous later. |
| 60 base::MessageLoop::current()->PostTask(FROM_HERE, screen_lock_callback_); | 71 base::MessageLoop::current()->PostTask(FROM_HERE, screen_lock_callback_); |
| 61 screen_lock_callback_.Reset(); | 72 screen_lock_callback_.Reset(); |
| 62 } else { | 73 } else { |
| 63 VLOG(1) << "Screen locked without suspend"; | 74 VLOG(1) << "Screen locked without suspend"; |
| 64 } | 75 } |
| 65 } | 76 } |
| 66 | 77 |
| 67 void SuspendObserver::ScreenIsUnlocked() { | 78 void PowerEventObserver::ScreenIsUnlocked() { |
| 68 screen_locked_ = false; | 79 screen_locked_ = false; |
| 69 } | 80 } |
| 70 | 81 |
| 71 } // namespace internal | 82 } // namespace internal |
| 72 } // namespace ash | 83 } // namespace ash |
| OLD | NEW |