File: scalable_iph_delegate.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 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 (218 lines) | stat: -rw-r--r-- 8,029 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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// 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 CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH_SCALABLE_IPH_DELEGATE_H_
#define CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH_SCALABLE_IPH_DELEGATE_H_

#include <ostream>

#include "base/component_export.h"
#include "base/observer_list_types.h"
#include "chromeos/ash/components/scalable_iph/iph_session.h"
#include "chromeos/ash/components/scalable_iph/scalable_iph_constants.h"

namespace scalable_iph {

// `ScalableIphDelegate` is responsible to delegate tasks to Chrome or Ash. In
// contrast, `ScalableIph` is responsible to decide on which/when to trigger an
// IPH.
//
// This delegate is responsible for:
// - Show an IPH with a request from `ScalableIph`.
// - Observe events in Ash, e.g. Network state change, etc.
class COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH)
    ScalableIphDelegate {
 public:
  enum class SessionState { kUnknownInitialValue, kActive, kLocked, kOther };

  // Observer for observing events in Ash.
  class Observer : public base::CheckedObserver {
   public:
    virtual void OnConnectionChanged(bool online) {}

    // Called when `SessionState` is changed.
    virtual void OnSessionStateChanged(SessionState session_state) {}

    // Called when the device does not enables lock screen, and every time the
    // system resumes from suspension.
    virtual void OnSuspendDoneWithoutLockScreen() {}

    // Called when the visibility of an app list has changed.
    virtual void OnAppListVisibilityChanged(bool shown) {}

    // Called when there is a change in whether there is a saved printer or not.
    // This method is called only if there is a change in a value. Initial value
    // is expected to be `false`.
    virtual void OnHasSavedPrintersChanged(bool has_saved_printers) {}

    // Called when there is a change in eligibility of phone hub onboarding.
    // This method is called only if there is a change in a value. Initial value
    // is expected to be `false`.
    virtual void OnPhoneHubOnboardingEligibleChanged(
        bool phonehub_onboarding_eligible) {}
  };

  // Have a virtual destructor as we can put `ScalableIphDelegate` in
  // unique_ptr.
  virtual ~ScalableIphDelegate() = default;

  struct Action {
    ActionType action_type = ActionType::kInvalid;

    // An event name notified to the feature engagement framework on the
    // execution of this action. Typically this event name will be set to
    // `event_used` of an event config.
    std::string iph_event_name;
    bool operator==(const Action& action) const = default;
  };

  struct Button {
    std::string text;
    Action action;

    bool operator==(const Button& button) const = default;
  };

  enum class BubbleIcon {
    kNoIcon,
    kChromeIcon,
    kPlayStoreIcon,
    kGoogleDocsIcon,
    kGooglePhotosIcon,
    kPrintJobsIcon,
    kYouTubeIcon,
    kLastIcon = kYouTubeIcon,
  };

  struct BubbleParams {
    BubbleParams();
    BubbleParams(const BubbleParams&);
    BubbleParams& operator=(const BubbleParams&);
    ~BubbleParams();

    std::string bubble_id;
    std::string title;
    std::string text;
    BubbleIcon icon = BubbleIcon::kNoIcon;
    Button button;
    std::string anchor_view_app_id;

    bool operator==(const BubbleParams& params) const = default;
  };

  // TODO(b/284158831): Define types of notifications, such as wallpaper,
  // printer, etc.
  enum class NotificationImageType {
    kNoImage = 0,
    kWallpaper,
    kMinecraft,
  };

  enum class NotificationIcon {
    kDefault,
    kRedeem,
  };

  enum class NotificationSummaryText {
    kNone,
    kWelcomeTips,
  };

  struct NotificationParams {
    NotificationParams();
    NotificationParams(const NotificationParams&);
    NotificationParams& operator=(const NotificationParams&);
    ~NotificationParams();

    NotificationImageType image_type = NotificationImageType::kNoImage;
    std::string notification_id;
    std::string title;
    std::string text;
    std::string source = kCustomNotificationSourceTextValueDefault;
    NotificationIcon icon = NotificationIcon::kDefault;
    NotificationSummaryText summary_text =
        NotificationSummaryText::kWelcomeTips;
    Button button;

    bool operator==(const NotificationParams& params) const = default;
  };

  // Deliver a bubble UI IPH to a user with specified behavior via
  // `BubbleParams`. A delegate must show an IPH if this method gets called.
  // Note that `IphSession` has a reference to `feature_engagement::Tracker`. Do
  // NOT interact it after a `Tracker` service `Shutdown`. `ScalableIphDelegate`
  // is owned by `ScalableIph` keyed service. `ScalableIph` keyed service
  // depends on `Tracker` keyed service and `ScalableIph` keyed service
  // destrcuts this `ScalableIphDelegate` in `ScalableIph::Shutdown`. Do NOT
  // interact with `IphSession` once the destructor gets called. Returns true if
  // it has requested the UI framework to show a bubble. Note that it's not
  // guaranteed that the UI framework has actually shown a bubble.
  virtual bool ShowBubble(const BubbleParams& params,
                          std::unique_ptr<IphSession> iph_session) = 0;

  // Same with `ShowBubble` method. But this method delivers a notification UI
  // IPH to a user with specified behavior via `NotificationParams`. Returns
  // true if it has requested the UI framework to show a notification. Note that
  // it's not guaranteed that the UI framework has actually shown a
  // notification.
  virtual bool ShowNotification(const NotificationParams& params,
                                std::unique_ptr<IphSession> iph_session) = 0;

  virtual void AddObserver(Observer* observer) = 0;
  virtual void RemoveObserver(Observer* observer) = 0;

  // Returns true if a device is online.
  virtual bool IsOnline() = 0;

  // Returns client age in days. The day count starts from 0. Day 0 means the
  // first 24 hours. Note that this can return a negative number if a profile
  // creation time is in a future time for some reason, e.g. Clock has changed.
  virtual int ClientAgeInDays() = 0;

  // Performs `action_type` in Ash or Chrome. This method is for `ScalableIph`
  // keyed service to delegate actions. Other code (e.g. Ui code) MUST use
  // `PerformAction` in `IphSession` or `ScalableIph`.
  virtual void PerformActionForScalableIph(ActionType action_type) = 0;
};

COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH)
std::ostream& operator<<(std::ostream& out,
                         ScalableIphDelegate::SessionState session_state);

COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH)
std::ostream& operator<<(std::ostream& out, ScalableIphDelegate::Action action);

COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH)
std::ostream& operator<<(std::ostream& out, ScalableIphDelegate::Button button);

COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH)
std::ostream& operator<<(std::ostream& out,
                         ScalableIphDelegate::BubbleIcon bubble_icon);

COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH)
std::ostream& operator<<(std::ostream& out,
                         ScalableIphDelegate::BubbleParams bubble_params);

COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH)
std::ostream& operator<<(
    std::ostream& out,
    ScalableIphDelegate::NotificationImageType notification_image_type);

COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH)
std::ostream& operator<<(
    std::ostream& out,
    ScalableIphDelegate::NotificationIcon notification_icon);

COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH)
std::ostream& operator<<(
    std::ostream& out,
    ScalableIphDelegate::NotificationSummaryText summary_text);

COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH)
std::ostream& operator<<(std::ostream& out,
                         ScalableIphDelegate::NotificationParams params);

}  // namespace scalable_iph

#endif  // CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH_SCALABLE_IPH_DELEGATE_H_