| OLD | NEW |
| 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/common/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" | 9 #include "ash/common/login_status.h" |
| 10 #include "ash/common/system/chromeos/session/logout_confirmation_dialog.h" | 10 #include "ash/common/system/chromeos/session/logout_confirmation_dialog.h" |
| 11 #include "ash/common/system/tray/system_tray_delegate.h" | 11 #include "ash/common/system/tray/system_tray_delegate.h" |
| 12 #include "ash/common/system/tray/system_tray_notifier.h" | 12 #include "ash/common/system/tray/system_tray_notifier.h" |
| 13 #include "ash/common/wm_shell.h" | |
| 14 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 15 #include "base/location.h" | 14 #include "base/location.h" |
| 16 #include "base/time/default_tick_clock.h" | 15 #include "base/time/default_tick_clock.h" |
| 17 #include "base/time/tick_clock.h" | 16 #include "base/time/tick_clock.h" |
| 18 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 19 | 18 |
| 20 namespace ash { | 19 namespace ash { |
| 21 namespace { | 20 namespace { |
| 22 const int kLogoutConfirmationDelayInSeconds = 20; | 21 const int kLogoutConfirmationDelayInSeconds = 20; |
| 23 } | 22 } |
| 24 | 23 |
| 25 LogoutConfirmationController::LogoutConfirmationController( | 24 LogoutConfirmationController::LogoutConfirmationController( |
| 26 const base::Closure& logout_closure) | 25 const base::Closure& logout_closure) |
| 27 : clock_(new base::DefaultTickClock), | 26 : clock_(new base::DefaultTickClock), |
| 28 logout_closure_(logout_closure), | 27 logout_closure_(logout_closure), |
| 29 dialog_(NULL), | 28 dialog_(NULL), |
| 30 logout_timer_(false, false) { | 29 logout_timer_(false, false) { |
| 31 if (WmShell::HasInstance()) { | 30 if (Shell::HasInstance()) { |
| 32 Shell::GetInstance()->AddShellObserver(this); | 31 Shell::GetInstance()->AddShellObserver(this); |
| 33 WmShell::Get()->system_tray_notifier()->AddLastWindowClosedObserver(this); | 32 Shell::Get()->system_tray_notifier()->AddLastWindowClosedObserver(this); |
| 34 } | 33 } |
| 35 } | 34 } |
| 36 | 35 |
| 37 LogoutConfirmationController::~LogoutConfirmationController() { | 36 LogoutConfirmationController::~LogoutConfirmationController() { |
| 38 if (WmShell::HasInstance()) { | 37 if (Shell::HasInstance()) { |
| 39 Shell::GetInstance()->RemoveShellObserver(this); | 38 Shell::GetInstance()->RemoveShellObserver(this); |
| 40 WmShell::Get()->system_tray_notifier()->RemoveLastWindowClosedObserver( | 39 Shell::Get()->system_tray_notifier()->RemoveLastWindowClosedObserver(this); |
| 41 this); | |
| 42 } | 40 } |
| 43 if (dialog_) | 41 if (dialog_) |
| 44 dialog_->ControllerGone(); | 42 dialog_->ControllerGone(); |
| 45 } | 43 } |
| 46 | 44 |
| 47 void LogoutConfirmationController::ConfirmLogout(base::TimeTicks logout_time) { | 45 void LogoutConfirmationController::ConfirmLogout(base::TimeTicks logout_time) { |
| 48 if (!logout_time_.is_null() && logout_time >= logout_time_) { | 46 if (!logout_time_.is_null() && logout_time >= logout_time_) { |
| 49 // If a confirmation dialog is already being shown and its countdown expires | 47 // If a confirmation dialog is already being shown and its countdown expires |
| 50 // no later than the |logout_time| requested now, keep the current dialog | 48 // no later than the |logout_time| requested now, keep the current dialog |
| 51 // open. | 49 // open. |
| 52 return; | 50 return; |
| 53 } | 51 } |
| 54 logout_time_ = logout_time; | 52 logout_time_ = logout_time; |
| 55 | 53 |
| 56 if (!dialog_) { | 54 if (!dialog_) { |
| 57 // Show confirmation dialog unless this is a unit test without a Shell. | 55 // Show confirmation dialog unless this is a unit test without a Shell. |
| 58 if (WmShell::HasInstance()) | 56 if (Shell::HasInstance()) |
| 59 dialog_ = new LogoutConfirmationDialog(this, logout_time_); | 57 dialog_ = new LogoutConfirmationDialog(this, logout_time_); |
| 60 } else { | 58 } else { |
| 61 dialog_->Update(logout_time_); | 59 dialog_->Update(logout_time_); |
| 62 } | 60 } |
| 63 | 61 |
| 64 logout_timer_.Start(FROM_HERE, logout_time_ - clock_->NowTicks(), | 62 logout_timer_.Start(FROM_HERE, logout_time_ - clock_->NowTicks(), |
| 65 logout_closure_); | 63 logout_closure_); |
| 66 } | 64 } |
| 67 | 65 |
| 68 void LogoutConfirmationController::SetClockForTesting( | 66 void LogoutConfirmationController::SetClockForTesting( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } | 98 } |
| 101 | 99 |
| 102 // Ask the user to confirm logout if a public session is in progress and the | 100 // Ask the user to confirm logout if a public session is in progress and the |
| 103 // screen is not locked. | 101 // screen is not locked. |
| 104 ConfirmLogout( | 102 ConfirmLogout( |
| 105 base::TimeTicks::Now() + | 103 base::TimeTicks::Now() + |
| 106 base::TimeDelta::FromSeconds(kLogoutConfirmationDelayInSeconds)); | 104 base::TimeDelta::FromSeconds(kLogoutConfirmationDelayInSeconds)); |
| 107 } | 105 } |
| 108 | 106 |
| 109 } // namespace ash | 107 } // namespace ash |
| OLD | NEW |