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
ash / public / cpp / system / anchored_nudge_manager.h [blame]
// 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_PUBLIC_CPP_SYSTEM_ANCHORED_NUDGE_MANAGER_H_
#define ASH_PUBLIC_CPP_SYSTEM_ANCHORED_NUDGE_MANAGER_H_
#include <memory>
#include <string>
#include "ash/constants/notifier_catalogs.h"
#include "ash/public/cpp/ash_public_export.h"
namespace ash {
struct AnchoredNudgeData;
class ScopedNudgePause;
// Public interface to show anchored nudges.
class ASH_PUBLIC_EXPORT AnchoredNudgeManager {
public:
// Returns the singleton `AnchoredNudgeManager`.
static AnchoredNudgeManager* Get();
// Shows an anchored nudge, and sets its contents with the provided
// `nudge_data`. It will persist until it is dismissed with `Cancel()`, it
// times out, or its anchor view is deleted/hidden. It will not be created if
// the anchor view is invisible or does not have a widget.
// TODO(b/285023559): Add and use a `ChainedCancelCallback` class instead of a
// `RepeatingClosure` so we don't have to manually modify the provided
// callbacks in the manager, and we can pass `nudge_data` as a constant.
virtual void Show(AnchoredNudgeData& nudge_data) = 0;
// Cancels an anchored nudge with the provided `id`.
virtual void Cancel(const std::string& id) = 0;
// Records Nudge "TimeToAction" metric, which tracks the time from when a
// nudge was shown to when the nudge's suggested action was performed.
// No op if the nudge specified by `catalog_name` hasn't been shown before.
virtual void MaybeRecordNudgeAction(NudgeCatalogName catalog_name) = 0;
// Returns true if the nudge with `id` is shown at the moment.
virtual bool IsNudgeShown(const std::string& id) = 0;
// Creates a `ScopedNudgePause`, which closes all `AnchoredNudge`'s and
// `SystemNudge`'s, and prevents more from being shown while any
// `ScopedNudgePause` is in scope.
virtual std::unique_ptr<ScopedNudgePause> CreateScopedPause() = 0;
protected:
AnchoredNudgeManager();
virtual ~AnchoredNudgeManager();
private:
friend class ScopedNudgePause;
// `Pause()` will stop all the nudges from showing up, until `Resume()` is
// called.
virtual void Pause() = 0;
virtual void Resume() = 0;
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_SYSTEM_ANCHORED_NUDGE_MANAGER_H_