ProfilePolicyConnectorFactory: Refactoring from Profile to BrowserContext.
[chromium-blink-merge.git] / ash / accelerators / exit_warning_handler.h
blobb99681cb4359c82190d5953f7549cfe104f11f5b
1 // Copyright 2013 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.
5 #ifndef ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_
6 #define ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_
8 #include "ash/ash_export.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/timer/timer.h"
11 #include "ui/base/accelerators/accelerator.h"
13 namespace views {
14 class Widget;
17 namespace ash {
19 // In order to avoid accidental exits when the user presses the exit
20 // shortcut by mistake, we require the user press it twice within a
21 // period of time. During that time we show a popup informing the
22 // user of this.
24 // Notes:
26 // The corresponding accelerator must be non-repeatable (see
27 // kNonrepeatableActions in accelerator_table.cc). Otherwise the "Double Press
28 // Exit" will be activated just by holding it down, i.e. probably every time.
30 // State Transition Diagrams:
32 // IDLE
33 // | Press
34 // WAIT_FOR_DOUBLE_PRESS action: show ui & start timers
35 // | Press (before time limit )
36 // EXITING action: hide ui, stop timer, exit
38 // IDLE
39 // | Press
40 // WAIT_FOR_DOUBLE_PRESS action: show ui & start timers
41 // | T timer expires
42 // IDLE action: hide ui
45 class AcceleratorControllerTest;
47 class ASH_EXPORT ExitWarningHandler {
48 public:
49 ExitWarningHandler();
51 ~ExitWarningHandler();
53 // Handles accelerator for exit (Ctrl-Shift-Q).
54 void HandleAccelerator();
56 private:
57 friend class AcceleratorControllerTest;
59 enum State {
60 IDLE,
61 WAIT_FOR_DOUBLE_PRESS,
62 EXITING
65 // Performs actions when the time limit is exceeded.
66 void TimerAction();
68 void StartTimer();
69 void CancelTimer();
71 void Show();
72 void Hide();
74 State state_;
75 scoped_ptr<views::Widget> widget_;
76 base::OneShotTimer<ExitWarningHandler> timer_;
78 // Flag to suppress starting the timer for testing. For test we call
79 // TimerAction() directly to simulate the expiration of the timer.
80 bool stub_timer_for_test_;
82 DISALLOW_COPY_AND_ASSIGN(ExitWarningHandler);
85 } // namespace ash
87 #endif // ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_