1 // Copyright 2014 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 "ash/system/chromeos/session/logout_confirmation_controller.h"
7 #include "ash/session/session_state_delegate.h"
9 #include "ash/system/chromeos/session/logout_confirmation_dialog.h"
10 #include "base/location.h"
11 #include "base/time/default_tick_clock.h"
12 #include "base/time/tick_clock.h"
13 #include "ui/views/widget/widget.h"
17 LogoutConfirmationController::LogoutConfirmationController(
18 const base::Closure
& logout_closure
)
19 : clock_(new base::DefaultTickClock
),
20 logout_closure_(logout_closure
),
22 logout_timer_(false, false) {
23 if (Shell::HasInstance())
24 Shell::GetInstance()->AddShellObserver(this);
27 LogoutConfirmationController::~LogoutConfirmationController() {
28 if (Shell::HasInstance())
29 Shell::GetInstance()->RemoveShellObserver(this);
31 dialog_
->GetWidget()->Close();
34 void LogoutConfirmationController::ConfirmLogout(
35 base::TimeTicks logout_time
) {
36 if (!logout_time_
.is_null() && logout_time
>= logout_time_
) {
37 // If a confirmation dialog is already being shown and its countdown expires
38 // no later than the |logout_time| requested now, keep the current dialog
42 logout_time_
= logout_time
;
45 // Show confirmation dialog unless this is a unit test without a Shell.
46 if (Shell::HasInstance())
47 dialog_
= new LogoutConfirmationDialog(this, logout_time_
);
49 dialog_
->Update(logout_time_
);
52 logout_timer_
.Start(FROM_HERE
,
53 logout_time_
- clock_
->NowTicks(),
57 void LogoutConfirmationController::SetClockForTesting(
58 scoped_ptr
<base::TickClock
> clock
) {
59 clock_
= clock
.Pass();
62 void LogoutConfirmationController::OnLockStateChanged(bool locked
) {
63 if (!locked
|| logout_time_
.is_null())
66 // If the screen is locked while a confirmation dialog is being shown, close
68 logout_time_
= base::TimeTicks();
70 dialog_
->GetWidget()->Close();
74 void LogoutConfirmationController::OnLogoutConfirmed() {
76 logout_closure_
.Run();
79 void LogoutConfirmationController::OnDialogClosed() {
80 logout_time_
= base::TimeTicks();