File: browser_feature_promo_preconditions.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (166 lines) | stat: -rw-r--r-- 6,089 bytes parent folder | download | duplicates (2)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_VIEWS_USER_EDUCATION_IMPL_BROWSER_FEATURE_PROMO_PRECONDITIONS_H_
#define CHROME_BROWSER_UI_VIEWS_USER_EDUCATION_IMPL_BROWSER_FEATURE_PROMO_PRECONDITIONS_H_

#include <memory>

#include "base/memory/raw_ref.h"
#include "base/scoped_observation.h"
#include "base/time/clock.h"
#include "base/time/default_clock.h"
#include "base/time/time.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "components/user_education/common/feature_promo/feature_promo_precondition.h"
#include "components/user_education/common/feature_promo/feature_promo_result.h"
#include "components/user_education/common/user_education_storage_service.h"
#include "ui/events/event.h"
#include "ui/events/event_observer.h"
#include "ui/views/event_monitor.h"
#include "ui/views/view.h"
#include "ui/views/view_observer.h"

DECLARE_FEATURE_PROMO_PRECONDITION_IDENTIFIER_VALUE(kWindowActivePrecondition);
DECLARE_FEATURE_PROMO_PRECONDITION_IDENTIFIER_VALUE(
    kContentNotFullscreenPrecondition);
DECLARE_FEATURE_PROMO_PRECONDITION_IDENTIFIER_VALUE(
    kOmniboxNotOpenPrecondition);
DECLARE_FEATURE_PROMO_PRECONDITION_IDENTIFIER_VALUE(
    kToolbarNotCollapsedPrecondition);
DECLARE_FEATURE_PROMO_PRECONDITION_IDENTIFIER_VALUE(
    kBrowserNotClosingPrecondition);
DECLARE_FEATURE_PROMO_PRECONDITION_IDENTIFIER_VALUE(
    kNoCriticalNoticeShowingPrecondition);
DECLARE_FEATURE_PROMO_PRECONDITION_IDENTIFIER_VALUE(kUserNotActivePrecondition);

// Requires that the window a promo will be shown in is active.
class WindowActivePrecondition
    : public user_education::FeaturePromoPreconditionBase {
 public:
  WindowActivePrecondition();
  ~WindowActivePrecondition() override;

  // FeaturePromoPreconditionBase:
  user_education::FeaturePromoResult CheckPrecondition(
      ComputedData& data) const override;
};

// Requires that the window isn't in content-fullscreen.
class ContentNotFullscreenPrecondition
    : public user_education::FeaturePromoPreconditionBase {
 public:
  explicit ContentNotFullscreenPrecondition(Browser& browser);
  ~ContentNotFullscreenPrecondition() override;

  // FeaturePromoPreconditionBase:
  user_education::FeaturePromoResult CheckPrecondition(
      ComputedData& data) const override;

 private:
  const raw_ref<Browser> browser_;
};

// Precondition that the Omnibox isn't open.
class OmniboxNotOpenPrecondition
    : public user_education::FeaturePromoPreconditionBase {
 public:
  explicit OmniboxNotOpenPrecondition(const BrowserView& browser_view);
  ~OmniboxNotOpenPrecondition() override;

  // FeaturePromoPreconditionBase:
  user_education::FeaturePromoResult CheckPrecondition(
      ComputedData& data) const override;

 private:
  const raw_ref<const BrowserView> browser_view_;
};

// Trying to show an IPH when the toolbar is collapsed (Responsive Toolbar) is
// inadvisable, as the anchor may not be present, important UI for the feature
// might not be present (including tutorial elements), and the UI might be too
// small to properly accommodate a help bubble.
class ToolbarNotCollapsedPrecondition
    : public user_education::FeaturePromoPreconditionBase {
 public:
  explicit ToolbarNotCollapsedPrecondition(BrowserView& browser_view);
  ~ToolbarNotCollapsedPrecondition() override;

  // FeaturePromoPreconditionBase:
  user_education::FeaturePromoResult CheckPrecondition(
      ComputedData& data) const override;

 private:
  const raw_ref<BrowserView> browser_view_;
};

// Trying to show an IPH while the browser is closing can cause problems; see
// https://crbug.com/346461762 for an example. This can also crash unit_tests
// that use a BrowserWindow but not a browser, so also check if the browser
// view's widget is closing.
class BrowserNotClosingPrecondition
    : public user_education::FeaturePromoPreconditionBase {
 public:
  explicit BrowserNotClosingPrecondition(BrowserView& browser_view);
  ~BrowserNotClosingPrecondition() override;

  // FeaturePromoPreconditionBase:
  user_education::FeaturePromoResult CheckPrecondition(
      ComputedData& data) const override;

 private:
  const raw_ref<BrowserView> browser_view_;
};

// Certain critical notices do not (yet) use the Product Messaging Service.
// TODO(https://crbug.com/324785292): When the migration is done, remove this
// precondition.
class NoCriticalNoticeShowingPrecondition
    : public user_education::FeaturePromoPreconditionBase {
 public:
  explicit NoCriticalNoticeShowingPrecondition(BrowserView& browser_view);
  ~NoCriticalNoticeShowingPrecondition() override;

  // FeaturePromoPreconditionBase:
  user_education::FeaturePromoResult CheckPrecondition(
      ComputedData& data) const override;

 private:
  const raw_ref<BrowserView> browser_view_;
};

// Don't show heavyweight notices while the user is typing.
class UserNotActivePrecondition
    : public user_education::FeaturePromoPreconditionBase,
      public ui::EventObserver,
      public views::ViewObserver {
 public:
  explicit UserNotActivePrecondition(
      BrowserView& browser_view,
      const user_education::UserEducationTimeProvider& time_provider);
  ~UserNotActivePrecondition() override;

  // FeaturePromoPreconditionBase:
  user_education::FeaturePromoResult CheckPrecondition(
      ComputedData& data) const override;

 private:
  void CreateEventMonitor();

  // ui::EventObserver:
  void OnEvent(const ui::Event& event) override;

  // views::ViewObserver:
  void OnViewAddedToWidget(views::View* observed_view) override;
  void OnViewIsDeleting(views::View* observed_view) override;

  const raw_ref<BrowserView> browser_view_;
  const raw_ref<const user_education::UserEducationTimeProvider> time_provider_;
  std::unique_ptr<views::EventMonitor> event_monitor_;
  base::Time last_active_time_;
  base::ScopedObservation<views::View, views::ViewObserver>
      browser_view_observation_{this};
};

#endif  // CHROME_BROWSER_UI_VIEWS_USER_EDUCATION_IMPL_BROWSER_FEATURE_PROMO_PRECONDITIONS_H_