OLD | NEW |
(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/session/logout_confirmation_controller.h" |
| 6 |
| 7 #include "ash/session_state_delegate.h" |
| 8 #include "ash/shell.h" |
| 9 #include "ash/system/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" |
| 14 |
| 15 namespace ash { |
| 16 namespace internal { |
| 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 (Shell::HasInstance()) |
| 25 Shell::GetInstance()->AddShellObserver(this); |
| 26 } |
| 27 |
| 28 LogoutConfirmationController::~LogoutConfirmationController() { |
| 29 if (Shell::HasInstance()) |
| 30 Shell::GetInstance()->RemoveShellObserver(this); |
| 31 if (dialog_) |
| 32 dialog_->GetWidget()->Close(); |
| 33 } |
| 34 |
| 35 void LogoutConfirmationController::ConfirmLogout( |
| 36 base::TimeTicks logout_time) { |
| 37 if (!logout_time_.is_null() && logout_time >= logout_time_) { |
| 38 // If a confirmation dialog is already being shown and its countdown expires |
| 39 // no later than the |logout_time| requested now, keep the current dialog |
| 40 // open. |
| 41 return; |
| 42 } |
| 43 logout_time_ = logout_time; |
| 44 |
| 45 if (!dialog_) { |
| 46 // Show confirmation dialog unless this is a unit test without a Shell. |
| 47 if (Shell::HasInstance()) |
| 48 dialog_ = new LogoutConfirmationDialog(this, logout_time_); |
| 49 } else { |
| 50 dialog_->Update(logout_time_); |
| 51 } |
| 52 |
| 53 logout_timer_.Start(FROM_HERE, |
| 54 logout_time_ - clock_->NowTicks(), |
| 55 logout_closure_); |
| 56 } |
| 57 |
| 58 void LogoutConfirmationController::SetClockForTesting( |
| 59 scoped_ptr<base::TickClock> clock) { |
| 60 clock_ = clock.Pass(); |
| 61 } |
| 62 |
| 63 void LogoutConfirmationController::OnLockStateChanged(bool locked) { |
| 64 if (!locked || logout_time_.is_null()) |
| 65 return; |
| 66 |
| 67 // If the screen is locked while a confirmation dialog is being shown, close |
| 68 // the dialog. |
| 69 logout_time_ = base::TimeTicks(); |
| 70 if (dialog_) |
| 71 dialog_->GetWidget()->Close(); |
| 72 logout_timer_.Stop(); |
| 73 } |
| 74 |
| 75 void LogoutConfirmationController::OnLogoutConfirmed() { |
| 76 logout_timer_.Stop(); |
| 77 logout_closure_.Run(); |
| 78 } |
| 79 |
| 80 void LogoutConfirmationController::OnDialogClosed() { |
| 81 logout_time_ = base::TimeTicks(); |
| 82 dialog_ = NULL; |
| 83 logout_timer_.Stop(); |
| 84 } |
| 85 |
| 86 } // namespace internal |
| 87 } // namespace ash |
OLD | NEW |