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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/power/idle_action_warning_observer.h"
7 #include "base/time/time.h"
8 #include "chrome/browser/chromeos/power/idle_action_warning_dialog_view.h"
9 #include "chromeos/dbus/dbus_thread_manager.h"
13 IdleActionWarningObserver::IdleActionWarningObserver() : warning_dialog_(NULL
) {
14 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
17 IdleActionWarningObserver::~IdleActionWarningObserver() {
18 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
20 warning_dialog_
->CloseDialog();
23 void IdleActionWarningObserver::IdleActionImminent(
24 const base::TimeDelta
& time_until_idle_action
) {
25 const base::TimeTicks idle_action_time
=
26 base::TimeTicks::Now() + time_until_idle_action
;
28 warning_dialog_
->Update(idle_action_time
);
30 warning_dialog_
= new IdleActionWarningDialogView(idle_action_time
);
33 void IdleActionWarningObserver::IdleActionDeferred() {
35 warning_dialog_
->CloseDialog();
36 warning_dialog_
= NULL
;
39 } // namespace chromeos