File: capture_mode_education_controller.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (98 lines) | stat: -rw-r--r-- 3,884 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_CAPTURE_MODE_CAPTURE_MODE_EDUCATION_CONTROLLER_H_
#define ASH_CAPTURE_MODE_CAPTURE_MODE_EDUCATION_CONTROLLER_H_

#include "ash/ash_export.h"
#include "base/memory/weak_ptr.h"
#include "base/time/clock.h"
#include "ui/views/widget/unique_widget_ptr.h"

class PrefRegistrySimple;

namespace ash {

// Controller for showing the different forms of user education for Screen
// Capture entry points. Education is split into three different arms:
//  - Arm 1: Shortcut Nudge. A simple system nudge appears with text indicating
//    the keyboard shortcut to take a screenshot.
//  - Arm 2: Shortcut Tutorial. Similar to Arm 1, but the nudge also appears
//    with a button that opens a new popup, showing the keyboard layout of where
//    the shortcut keys are found.
//  - Arm 3: Quick Settings Nudge. A system nudge anchored to the quick settings
//    button in the shelf, with text alerting users to the Screen Capture tile
//    in the quick settings menu.
class ASH_EXPORT CaptureModeEducationController {
 public:
  CaptureModeEducationController();
  CaptureModeEducationController(const CaptureModeEducationController&) =
      delete;
  CaptureModeEducationController& operator=(
      const CaptureModeEducationController&) = delete;
  ~CaptureModeEducationController();

  // Registers prefs related to user education show count and time last shown.
  static void RegisterProfilePrefs(PrefRegistrySimple* registry);

  // Returns true if the feature flag 'kCaptureModeEducation' is enabled and
  // the associated param is 'kShortcutNudge';
  static bool IsArm1ShortcutNudgeEnabled();

  // Returns true if the feature flag 'kCaptureModeEducation' is enabled and
  // the associated param is 'kShortcutTutorial';
  static bool IsArm2ShortcutTutorialEnabled();

  // Returns true if the feature flag 'kCaptureModeEducation' is enabled and
  // the associated param is 'kQuickSettingsNudge';
  static bool IsArm3QuickSettingsNudgeEnabled();

  // If a form of user education has already been shown 3 times or once in the
  // past 24 hours, returns. Otherwise, shows the appropriate form of user
  // education based on the enabled arm/feature param.
  void MaybeShowEducation();

  // Closes any Screen Capture nudges or tutorials that may be open.
  void CloseAllEducationNudgesAndTutorials();

  views::Widget* tutorial_widget_for_test() { return tutorial_widget_.get(); }

 private:
  friend class CaptureModeEducationControllerTest;

  // Used to control the clock in a test setting.
  static void SetOverrideClockForTesting(base::Clock* test_clock);

  // Shows Arm 1, an unanchored system nudge indicating the keyboard shortcut to
  // take a screenshot.
  void ShowShortcutNudge();

  // Shows Arm 2, an unanchored system nudge indicating the keyboard shortcut to
  // take a screenshot, with a button to open a new tutorial widget.
  void ShowTutorialNudge();

  // Shows Arm 3, a system nudge anchored to the unified system tray button,
  // indicating the location of the screen capture tool in the quick settings
  // menu.
  void ShowQuickSettingsNudge();

  // Creates and shows the system dialog displaying the keyboard shortcut and
  // illustration for taking a screenshot.
  void CreateAndShowTutorialDialog();

  // Closes the nudge and shows the tutorial dialog for Arm 2.
  void OnShowMeHowButtonPressed();

  // If set to true, ignores the 3 times/24 hours show limit for testing.
  bool skip_prefs_for_test_ = false;

  // The widget that contains the tutorial dialog view for Arm 2.
  views::UniqueWidgetPtr tutorial_widget_;

  base::WeakPtrFactory<CaptureModeEducationController> weak_ptr_factory_{this};
};

}  // namespace ash

#endif  // ASH_CAPTURE_MODE_CAPTURE_MODE_EDUCATION_CONTROLLER_H_