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

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

Issue 2108793002: mash: Convert system tray logout button to wm common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more review comments, fix mash_unittests Created 4 years, 5 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/system/chromeos/session/logout_confirmation_controller.h"
6
7 #include <utility>
8
9 #include "ash/common/wm_shell.h"
10 #include "ash/system/chromeos/session/logout_confirmation_dialog.h"
11 #include "base/location.h"
12 #include "base/time/default_tick_clock.h"
13 #include "base/time/tick_clock.h"
14 #include "ui/views/widget/widget.h"
15
16 namespace ash {
17
18 LogoutConfirmationController::LogoutConfirmationController(
19 const base::Closure& logout_closure)
20 : clock_(new base::DefaultTickClock),
21 logout_closure_(logout_closure),
22 dialog_(NULL),
23 logout_timer_(false, false) {
24 if (WmShell::HasInstance())
25 WmShell::Get()->AddShellObserver(this);
26 }
27
28 LogoutConfirmationController::~LogoutConfirmationController() {
29 if (WmShell::HasInstance())
30 WmShell::Get()->RemoveShellObserver(this);
31 if (dialog_)
32 dialog_->ControllerGone();
33 }
34
35 void LogoutConfirmationController::ConfirmLogout(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
39 // open.
40 return;
41 }
42 logout_time_ = logout_time;
43
44 if (!dialog_) {
45 // Show confirmation dialog unless this is a unit test without a Shell.
46 if (WmShell::HasInstance())
47 dialog_ = new LogoutConfirmationDialog(this, logout_time_);
48 } else {
49 dialog_->Update(logout_time_);
50 }
51
52 logout_timer_.Start(FROM_HERE, logout_time_ - clock_->NowTicks(),
53 logout_closure_);
54 }
55
56 void LogoutConfirmationController::SetClockForTesting(
57 std::unique_ptr<base::TickClock> clock) {
58 clock_ = std::move(clock);
59 }
60
61 void LogoutConfirmationController::OnLockStateChanged(bool locked) {
62 if (!locked || logout_time_.is_null())
63 return;
64
65 // If the screen is locked while a confirmation dialog is being shown, close
66 // the dialog.
67 logout_time_ = base::TimeTicks();
68 if (dialog_)
69 dialog_->GetWidget()->Close();
70 logout_timer_.Stop();
71 }
72
73 void LogoutConfirmationController::OnLogoutConfirmed() {
74 logout_timer_.Stop();
75 logout_closure_.Run();
76 }
77
78 void LogoutConfirmationController::OnDialogClosed() {
79 logout_time_ = base::TimeTicks();
80 dialog_ = NULL;
81 logout_timer_.Stop();
82 }
83
84 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698