This source file includes following definitions.
- BrightnessChanged
- SuspendImminent
- SystemResumed
- ScreenIsLocked
- ScreenIsUnlocked
#include "ash/system/chromeos/power/power_event_observer.h"
#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/wm/power_button_controller.h"
#include "base/prefs/pref_service.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "ui/display/chromeos/output_configurator.h"
#include "ui/wm/core/user_activity_detector.h"
namespace ash {
PowerEventObserver::PowerEventObserver()
: screen_locked_(false) {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
AddObserver(this);
chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->
AddObserver(this);
}
PowerEventObserver::~PowerEventObserver() {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
RemoveObserver(this);
chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->
RemoveObserver(this);
}
void PowerEventObserver::BrightnessChanged(int level, bool user_initiated) {
Shell::GetInstance()->power_button_controller()->OnScreenBrightnessChanged(
static_cast<double>(level));
}
void PowerEventObserver::SuspendImminent() {
Shell* shell = Shell::GetInstance();
SessionStateDelegate* delegate = shell->session_state_delegate();
if (!screen_locked_ && delegate->ShouldLockScreenBeforeSuspending() &&
delegate->CanLockScreen()) {
screen_lock_callback_ = chromeos::DBusThreadManager::Get()->
GetPowerManagerClient()->GetSuspendReadinessCallback();
VLOG(1) << "Requesting screen lock from PowerEventObserver";
chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->
RequestLockScreen();
}
shell->user_activity_detector()->OnDisplayPowerChanging();
shell->output_configurator()->SuspendDisplays();
}
void PowerEventObserver::SystemResumed(const base::TimeDelta& sleep_duration) {
Shell::GetInstance()->output_configurator()->ResumeDisplays();
Shell::GetInstance()->system_tray_notifier()->NotifyRefreshClock();
}
void PowerEventObserver::ScreenIsLocked() {
screen_locked_ = true;
if (!screen_lock_callback_.is_null()) {
VLOG(1) << "Screen locked due to suspend";
base::MessageLoop::current()->PostTask(FROM_HERE, screen_lock_callback_);
screen_lock_callback_.Reset();
} else {
VLOG(1) << "Screen locked without suspend";
}
}
void PowerEventObserver::ScreenIsUnlocked() {
screen_locked_ = false;
}
}