Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / power / idle_action_warning_observer.cc
blobe96c1c1d472e4df28bc49574652463cf95e5eebd
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"
11 namespace chromeos {
13 IdleActionWarningObserver::IdleActionWarningObserver() : warning_dialog_(NULL) {
14 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
17 IdleActionWarningObserver::~IdleActionWarningObserver() {
18 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
19 if (warning_dialog_)
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;
27 if (warning_dialog_)
28 warning_dialog_->Update(idle_action_time);
29 else
30 warning_dialog_ = new IdleActionWarningDialogView(idle_action_time);
33 void IdleActionWarningObserver::IdleActionDeferred() {
34 if (warning_dialog_)
35 warning_dialog_->CloseDialog();
36 warning_dialog_ = NULL;
39 } // namespace chromeos