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/logout_confirmation/logout_confirmation_controller.h" | |
6 | |
7 #include "ash/session_state_delegate.h" | |
8 #include "ash/shell.h" | |
9 #include "ash/system/logout_confirmation/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_(reinterpret_cast<base::TickClock*>(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); | |
stevenjb
2014/03/04 23:33:30
I think we need to destroy dialog_ here (if not NU
bartfab (slow)
2014/03/05 18:19:46
I think the code was actually safe: In my understa
| |
31 } | |
32 | |
33 void LogoutConfirmationController::ConfirmLogout( | |
34 base::TimeTicks logout_time) { | |
35 if (!logout_time_.is_null() && logout_time >= logout_time_) { | |
36 // If a confirmation dialog is already being shown and its countdown expires | |
37 // no later than the |logout_time| requested now, keep the current dialog | |
38 // open. | |
39 return; | |
40 } | |
41 logout_time_ = logout_time; | |
42 | |
43 if (!dialog_) { | |
44 // Show confirmation dialog unless this is a unit test without a Shell. | |
45 if (Shell::HasInstance()) | |
46 dialog_ = new LogoutConfirmationDialog(this, logout_time_); | |
47 } else { | |
48 dialog_->Update(logout_time_); | |
49 } | |
50 | |
51 logout_timer_.Start(FROM_HERE, | |
52 logout_time_ - clock_->NowTicks(), | |
53 logout_closure_); | |
54 } | |
55 | |
56 void LogoutConfirmationController::SetClockForTesting( | |
57 scoped_ptr<base::TickClock> clock) { | |
58 clock_ = clock.Pass(); | |
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 internal | |
85 } // namespace ash | |
OLD | NEW |