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 #ifndef ASH_COMMON_SYSTEM_CHROMEOS_SESSION_LOGOUT_CONFIRMATION_CONTROLLER_H_ | |
6 #define ASH_COMMON_SYSTEM_CHROMEOS_SESSION_LOGOUT_CONFIRMATION_CONTROLLER_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "ash/ash_export.h" | |
11 #include "ash/common/shell_observer.h" | |
12 #include "ash/common/system/chromeos/session/last_window_closed_observer.h" | |
13 #include "base/callback.h" | |
14 #include "base/macros.h" | |
15 #include "base/time/time.h" | |
16 #include "base/timer/timer.h" | |
17 | |
18 namespace base { | |
19 class TickClock; | |
20 } | |
21 | |
22 namespace ash { | |
23 | |
24 class LogoutConfirmationDialog; | |
25 | |
26 // This class shows a dialog asking the user to confirm or deny logout and | |
27 // terminates the session if the user either confirms or allows the countdown | |
28 // shown in the dialog to expire. | |
29 // | |
30 // It is guaranteed that no more than one confirmation dialog will be visible at | |
31 // any given time. If there are multiple requests to show a confirmation dialog | |
32 // at the same time, the dialog whose countdown expires first is shown. | |
33 // | |
34 // In public sessions, asks the user to end the session when the last window is | |
35 // closed. | |
36 class ASH_EXPORT LogoutConfirmationController | |
37 : public ShellObserver, | |
38 public LastWindowClosedObserver { | |
39 public: | |
40 // The |logout_closure| must be safe to call as long as |this| is alive. | |
41 explicit LogoutConfirmationController(const base::Closure& logout_closure); | |
42 ~LogoutConfirmationController() override; | |
43 | |
44 base::TickClock* clock() const { return clock_.get(); } | |
45 | |
46 // Shows a LogoutConfirmationDialog. If a confirmation dialog is already being | |
47 // shown, it is closed and a new one opened if |logout_time| is earlier than | |
48 // the current dialog's |logout_time_|. | |
49 void ConfirmLogout(base::TimeTicks logout_time); | |
50 | |
51 void SetClockForTesting(std::unique_ptr<base::TickClock> clock); | |
52 | |
53 // ShellObserver: | |
54 void OnLockStateChanged(bool locked) override; | |
55 | |
56 // Called by the |dialog_| when the user confirms logout. | |
57 void OnLogoutConfirmed(); | |
58 | |
59 // Called by the |dialog_| when it is closed. | |
60 void OnDialogClosed(); | |
61 | |
62 LogoutConfirmationDialog* dialog_for_testing() const { return dialog_; } | |
63 | |
64 private: | |
65 // LastWindowClosedObserver: | |
66 void OnLastWindowClosed() override; | |
67 | |
68 std::unique_ptr<base::TickClock> clock_; | |
69 base::Closure logout_closure_; | |
70 | |
71 base::TimeTicks logout_time_; | |
72 LogoutConfirmationDialog* dialog_; // Owned by the Views hierarchy. | |
73 base::Timer logout_timer_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(LogoutConfirmationController); | |
76 }; | |
77 | |
78 } // namespace ash | |
79 | |
80 #endif // ASH_COMMON_SYSTEM_CHROMEOS_SESSION_LOGOUT_CONFIRMATION_CONTROLLER_H_ | |
OLD | NEW |