forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_banner_settings_helper.h
201 lines (171 loc) · 8.52 KB
/
app_banner_settings_helper.h
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
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_BANNERS_APP_BANNER_SETTINGS_HELPER_H_
#define CHROME_BROWSER_BANNERS_APP_BANNER_SETTINGS_HELPER_H_
#include <set>
#include <string>
#include "base/macros.h"
#include "base/time/time.h"
#include "chrome/browser/installable/installable_logging.h"
namespace content {
class WebContents;
} // namespace content
class GURL;
class Profile;
// Utility class to record banner events for the given package or start url.
//
// These events are used to decide when banners should be shown, using a
// heuristic based on how many different days in a recent period of time (for
// example the past two weeks) the banner could have been shown, when it was
// last shown, when it was last blocked, and when it was last installed (for
// ServiceWorker style apps - native apps can query whether the app was
// installed directly).
//
// The desired effect is to have banners appear once a user has demonstrated
// an ongoing relationship with the app, and not to pester the user too much.
//
// For most events only the last event is recorded. The exception are the
// could show events. For these a list of the events is maintained. At most
// one event is stored per day, and events outside the window the heuristic
// uses are discarded. Local times are used to enforce these rules, to ensure
// what we count as a day matches what the user perceives to be days.
class AppBannerSettingsHelper {
public:
// An enum for determining the title to use for the add to homescreen / app
// banner functionality.
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.banners
enum LanguageOption {
LANGUAGE_OPTION_DEFAULT = 0,
LANGUAGE_OPTION_MIN = LANGUAGE_OPTION_DEFAULT,
LANGUAGE_OPTION_ADD = 1,
LANGUAGE_OPTION_INSTALL = 2,
LANGUAGE_OPTION_MAX = LANGUAGE_OPTION_INSTALL,
};
// The various types of banner events recorded as timestamps in the app banner
// content setting per origin and package_name_or_start_url pair. This enum
// corresponds to the kBannerEventsKeys array.
// TODO(mariakhomenko): Rename events to reflect that they are used in more
// contexts now.
enum AppBannerEvent {
// Records the first time that a site met the conditions to show a banner.
// Used for computing the MinutesFromFirstVisitToBannerShown metric.
APP_BANNER_EVENT_COULD_SHOW,
// Records the latest time a banner was shown to the user. Used to suppress
// the banner from being shown too often.
APP_BANNER_EVENT_DID_SHOW,
// Records the latest time a banner was dismissed by the user. Used to
// suppress the banner for some time if the user explicitly didn't want it.
APP_BANNER_EVENT_DID_BLOCK,
// Records the latest time the user added a site to the homescreen from a
// banner, or launched that site from homescreen. Used to ensure banners are
// not shown for sites which were added, and to determine if sites were
// launched recently.
APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
APP_BANNER_EVENT_NUM_EVENTS,
};
static const char kInstantAppsKey[];
// The content setting basically records a simplified subset of history.
// For privacy reasons this needs to be cleared. The ClearHistoryForURLs
// function removes any information from the banner content settings for the
// given URls.
static void ClearHistoryForURLs(Profile* profile,
const std::set<GURL>& origin_urls);
// Record a banner installation event, for either a WEB or NATIVE app.
static void RecordBannerInstallEvent(
content::WebContents* web_contents,
const std::string& package_name_or_start_url);
// Record a banner dismissal event, for either a WEB or NATIVE app.
static void RecordBannerDismissEvent(
content::WebContents* web_contents,
const std::string& package_name_or_start_url);
// Record a banner event specified by |event|.
static void RecordBannerEvent(content::WebContents* web_contents,
const GURL& origin_url,
const std::string& package_name_or_start_url,
AppBannerEvent event,
base::Time time);
// Reports whether the app install banner was blocked by the user recently
// enough with respect to |now| that another banner should not yet be shown.
// |package_name_or_start_url| must be non-empty.
static bool WasBannerRecentlyBlocked(
content::WebContents* web_contents,
const GURL& origin_url,
const std::string& package_name_or_start_url,
base::Time now);
// Reports whether the app install banner was ignored by the user recently
// enough with respect to |now| that another banner should not yet be shown.
// |package_name_or_start_url| must be non-empty.
static bool WasBannerRecentlyIgnored(
content::WebContents* web_contents,
const GURL& origin_url,
const std::string& package_name_or_start_url,
base::Time now);
// Returns whether the supplied app has ever been installed from |origin_url|.
static bool HasBeenInstalled(content::WebContents* web_contents,
const GURL& origin_url,
const std::string& package_name_or_start_url);
// Get the time that |event| was recorded, or a null time if it has not yet
// been recorded. Exposed for testing.
static base::Time GetSingleBannerEvent(
content::WebContents* web_contents,
const GURL& origin_url,
const std::string& package_name_or_start_url,
AppBannerEvent event);
// Returns true if |total_engagement| is sufficiently high to warrant
// triggering a banner, or if the command-line flag to bypass engagement
// checking is true.
static bool HasSufficientEngagement(double total_engagement);
// Record a UMA statistic measuring the minutes between the first visit to the
// site and the first showing of the banner.
static void RecordMinutesFromFirstVisitToShow(
content::WebContents* web_contents,
const GURL& origin_url,
const std::string& package_name_or_start_url,
base::Time time);
// Returns true if any site under |origin| was launched from homescreen in the
// last ten days. This allows services outside app banners to utilise the
// content setting that ensures app banners are not shown for sites which ave
// already been added to homescreen.
static bool WasLaunchedRecently(Profile* profile,
const GURL& origin_url,
base::Time now);
// Set the number of days which dismissing/ignoring the banner should prevent
// a banner from showing.
static void SetDaysAfterDismissAndIgnoreToTrigger(unsigned int dismiss_days,
unsigned int ignore_days);
// Set the total engagement weight required to trigger a banner.
static void SetTotalEngagementToTrigger(double total_engagement);
// Resets the engagement weights, minimum minutes, and total engagement to
// trigger to their default values.
static void SetDefaultParameters();
// Updates all values from field trial.
static void UpdateFromFieldTrial();
// Queries variations to determine which language option should be used for
// app banners and add to homescreen.
static LanguageOption GetHomescreenLanguageOption();
// Returns whether we are out of |scope|'s animation suppression period and
// can show an animation.
static bool CanShowInstallTextAnimation(content::WebContents* web_contents,
const GURL& scope);
// Records the fact that we've shown an animation for |scope| and updates its
// animation suppression period.
static void RecordInstallTextAnimationShown(
content::WebContents* web_contents,
const GURL& scope);
// Utility class for testing, which sets how long the banner should be
// suppressed after it is dismissed or ignored. The previous configuration
// is restored when this object is destructed.
class ScopedTriggerSettings {
public:
ScopedTriggerSettings(unsigned int dismiss_days, unsigned int ignore_days);
virtual ~ScopedTriggerSettings();
private:
unsigned int old_dismiss_, old_ignore_;
DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedTriggerSettings);
};
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(AppBannerSettingsHelper);
};
#endif // CHROME_BROWSER_BANNERS_APP_BANNER_SETTINGS_HELPER_H_