1 // Copyright 2020 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 CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_GESTURE_NAVIGATION_SCREEN_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_GESTURE_NAVIGATION_SCREEN_H_
7 
8 #include <map>
9 #include <string>
10 
11 #include "base/callback.h"
12 #include "chrome/browser/chromeos/login/screens/base_screen.h"
13 #include "chrome/browser/ui/webui/chromeos/login/gesture_navigation_screen_handler.h"
14 
15 namespace chromeos {
16 
17 // The OOBE screen dedicated to gesture navigation education.
18 class GestureNavigationScreen : public BaseScreen {
19  public:
20   enum class Result { NEXT, NOT_APPLICABLE };
21 
22   static std::string GetResultString(Result result);
23 
24   using ScreenExitCallback = base::RepeatingCallback<void(Result result)>;
25   GestureNavigationScreen(GestureNavigationScreenView* view,
26                           const ScreenExitCallback& exit_callback);
27   ~GestureNavigationScreen() override;
28 
29   GestureNavigationScreen(const GestureNavigationScreen&) = delete;
30   GestureNavigationScreen operator=(const GestureNavigationScreen&) = delete;
31 
set_exit_callback_for_testing(const ScreenExitCallback & exit_callback)32   void set_exit_callback_for_testing(const ScreenExitCallback& exit_callback) {
33     exit_callback_ = exit_callback;
34   }
35 
get_exit_callback_for_testing()36   const ScreenExitCallback& get_exit_callback_for_testing() {
37     return exit_callback_;
38   }
39 
40   // Returns whether the gesture screen was shown.
was_shown()41   bool was_shown() const { return was_shown_; }
42 
43   // Called when the currently shown page is changed.
44   void GesturePageChange(const std::string& new_page);
45 
46   // BaseScreen:
47   bool MaybeSkip(WizardContext* context) override;
48 
49  protected:
50   // BaseScreen:
51   void ShowImpl() override;
52   void HideImpl() override;
53   void OnUserAction(const std::string& action_id) override;
54 
55  private:
56   // Record metrics for the elapsed time that each page was shown for.
57   void RecordPageShownTimeMetrics();
58 
59   GestureNavigationScreenView* view_;
60   ScreenExitCallback exit_callback_;
61 
62   // Used to keep track of the current elapsed time that each page has been
63   // shown for.
64   std::map<std::string, base::TimeDelta> page_times_;
65 
66   // The current page that is shown on the gesture navigation screen.
67   std::string current_page_;
68 
69   // The starting time for the most recently shown page.
70   base::TimeTicks start_time_;
71 
72   // Whether the gesture screen was shown.
73   bool was_shown_ = false;
74 };
75 
76 }  // namespace chromeos
77 
78 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_GESTURE_NAVIGATION_SCREEN_H_
79