Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1213)

Side by Side Diff: ash/common/system/chromeos/session/logout_confirmation_controller.cc

Issue 2732813002: chromeos: Move files in //ash/common to //ash, part 1 (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "ash/common/system/chromeos/session/logout_confirmation_controller.h"
6
7 #include <utility>
8
9 #include "ash/common/login_status.h"
10 #include "ash/common/system/chromeos/session/logout_confirmation_dialog.h"
11 #include "ash/common/system/tray/system_tray_delegate.h"
12 #include "ash/common/system/tray/system_tray_notifier.h"
13 #include "ash/common/wm_shell.h"
14 #include "base/location.h"
15 #include "base/time/default_tick_clock.h"
16 #include "base/time/tick_clock.h"
17 #include "ui/views/widget/widget.h"
18
19 namespace ash {
20 namespace {
21 const int kLogoutConfirmationDelayInSeconds = 20;
22 }
23
24 LogoutConfirmationController::LogoutConfirmationController(
25 const base::Closure& logout_closure)
26 : clock_(new base::DefaultTickClock),
27 logout_closure_(logout_closure),
28 dialog_(NULL),
29 logout_timer_(false, false) {
30 if (WmShell::HasInstance()) {
31 WmShell::Get()->AddShellObserver(this);
32 WmShell::Get()->system_tray_notifier()->AddLastWindowClosedObserver(this);
33 }
34 }
35
36 LogoutConfirmationController::~LogoutConfirmationController() {
37 if (WmShell::HasInstance()) {
38 WmShell::Get()->RemoveShellObserver(this);
39 WmShell::Get()->system_tray_notifier()->RemoveLastWindowClosedObserver(
40 this);
41 }
42 if (dialog_)
43 dialog_->ControllerGone();
44 }
45
46 void LogoutConfirmationController::ConfirmLogout(base::TimeTicks logout_time) {
47 if (!logout_time_.is_null() && logout_time >= logout_time_) {
48 // If a confirmation dialog is already being shown and its countdown expires
49 // no later than the |logout_time| requested now, keep the current dialog
50 // open.
51 return;
52 }
53 logout_time_ = logout_time;
54
55 if (!dialog_) {
56 // Show confirmation dialog unless this is a unit test without a Shell.
57 if (WmShell::HasInstance())
58 dialog_ = new LogoutConfirmationDialog(this, logout_time_);
59 } else {
60 dialog_->Update(logout_time_);
61 }
62
63 logout_timer_.Start(FROM_HERE, logout_time_ - clock_->NowTicks(),
64 logout_closure_);
65 }
66
67 void LogoutConfirmationController::SetClockForTesting(
68 std::unique_ptr<base::TickClock> clock) {
69 clock_ = std::move(clock);
70 }
71
72 void LogoutConfirmationController::OnLockStateChanged(bool locked) {
73 if (!locked || logout_time_.is_null())
74 return;
75
76 // If the screen is locked while a confirmation dialog is being shown, close
77 // the dialog.
78 logout_time_ = base::TimeTicks();
79 if (dialog_)
80 dialog_->GetWidget()->Close();
81 logout_timer_.Stop();
82 }
83
84 void LogoutConfirmationController::OnLogoutConfirmed() {
85 logout_timer_.Stop();
86 logout_closure_.Run();
87 }
88
89 void LogoutConfirmationController::OnDialogClosed() {
90 logout_time_ = base::TimeTicks();
91 dialog_ = NULL;
92 logout_timer_.Stop();
93 }
94
95 void LogoutConfirmationController::OnLastWindowClosed() {
96 if (WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() !=
97 LoginStatus::PUBLIC) {
98 return;
99 }
100
101 // Ask the user to confirm logout if a public session is in progress and the
102 // screen is not locked.
103 ConfirmLogout(
104 base::TimeTicks::Now() +
105 base::TimeDelta::FromSeconds(kLogoutConfirmationDelayInSeconds));
106 }
107
108 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698