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

Side by Side Diff: ash/common/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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/system/chromeos/session/logout_confirmation_controller.h" 5 #include "ash/common/system/chromeos/session/logout_confirmation_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 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"
9 #include "ash/common/wm_shell.h" 13 #include "ash/common/wm_shell.h"
10 #include "ash/system/chromeos/session/logout_confirmation_dialog.h"
11 #include "base/location.h" 14 #include "base/location.h"
12 #include "base/time/default_tick_clock.h" 15 #include "base/time/default_tick_clock.h"
13 #include "base/time/tick_clock.h" 16 #include "base/time/tick_clock.h"
14 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
15 18
16 namespace ash { 19 namespace ash {
20 namespace {
21 const int kLogoutConfirmationDelayInSeconds = 20;
22 }
17 23
18 LogoutConfirmationController::LogoutConfirmationController( 24 LogoutConfirmationController::LogoutConfirmationController(
19 const base::Closure& logout_closure) 25 const base::Closure& logout_closure)
20 : clock_(new base::DefaultTickClock), 26 : clock_(new base::DefaultTickClock),
21 logout_closure_(logout_closure), 27 logout_closure_(logout_closure),
22 dialog_(NULL), 28 dialog_(NULL),
23 logout_timer_(false, false) { 29 logout_timer_(false, false) {
24 if (WmShell::HasInstance()) 30 if (WmShell::HasInstance()) {
25 WmShell::Get()->AddShellObserver(this); 31 WmShell::Get()->AddShellObserver(this);
32 WmShell::Get()->system_tray_notifier()->AddLastWindowClosedObserver(this);
33 }
26 } 34 }
27 35
28 LogoutConfirmationController::~LogoutConfirmationController() { 36 LogoutConfirmationController::~LogoutConfirmationController() {
29 if (WmShell::HasInstance()) 37 if (WmShell::HasInstance()) {
30 WmShell::Get()->RemoveShellObserver(this); 38 WmShell::Get()->RemoveShellObserver(this);
39 WmShell::Get()->system_tray_notifier()->RemoveLastWindowClosedObserver(
40 this);
41 }
31 if (dialog_) 42 if (dialog_)
32 dialog_->ControllerGone(); 43 dialog_->ControllerGone();
33 } 44 }
34 45
35 void LogoutConfirmationController::ConfirmLogout(base::TimeTicks logout_time) { 46 void LogoutConfirmationController::ConfirmLogout(base::TimeTicks logout_time) {
36 if (!logout_time_.is_null() && logout_time >= logout_time_) { 47 if (!logout_time_.is_null() && logout_time >= logout_time_) {
37 // If a confirmation dialog is already being shown and its countdown expires 48 // 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 49 // no later than the |logout_time| requested now, keep the current dialog
39 // open. 50 // open.
40 return; 51 return;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 logout_timer_.Stop(); 85 logout_timer_.Stop();
75 logout_closure_.Run(); 86 logout_closure_.Run();
76 } 87 }
77 88
78 void LogoutConfirmationController::OnDialogClosed() { 89 void LogoutConfirmationController::OnDialogClosed() {
79 logout_time_ = base::TimeTicks(); 90 logout_time_ = base::TimeTicks();
80 dialog_ = NULL; 91 dialog_ = NULL;
81 logout_timer_.Stop(); 92 logout_timer_.Stop();
82 } 93 }
83 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
84 } // namespace ash 108 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698