Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / power / idle_action_warning_observer.cc
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.
4
5 #include "chrome/browser/chromeos/power/idle_action_warning_observer.h"
6
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"
10
11 namespace chromeos {
12
13 IdleActionWarningObserver::IdleActionWarningObserver() : warning_dialog_(NULL) {
14   DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
15 }
16
17 IdleActionWarningObserver::~IdleActionWarningObserver() {
18   DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
19   if (warning_dialog_)
20     warning_dialog_->CloseDialog();
21 }
22
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);
31 }
32
33 void IdleActionWarningObserver::IdleActionDeferred() {
34   if (warning_dialog_)
35     warning_dialog_->CloseDialog();
36   warning_dialog_ = NULL;
37 }
38
39 }  // namespace chromeos