Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / banners / app_banner_settings_helper.h
blob3ff877c03616270736f3abf19a4c3500a8d36b28
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_BANNERS_APP_BANNER_SETTINGS_HELPER_H_
6 #define CHROME_BROWSER_BANNERS_APP_BANNER_SETTINGS_HELPER_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/macros.h"
13 #include "base/time/time.h"
14 #include "ui/base/page_transition_types.h"
16 namespace content {
17 class WebContents;
18 } // namespace content
20 class GURL;
21 class Profile;
23 // Utility class to record banner events for the given package or start url.
25 // These events are used to decide when banners should be shown, using a
26 // heuristic based on how many different days in a recent period of time (for
27 // example the past two weeks) the banner could have been shown, when it was
28 // last shown, when it was last blocked, and when it was last installed (for
29 // ServiceWorker style apps - native apps can query whether the app was
30 // installed directly).
32 // The desired effect is to have banners appear once a user has demonstrated
33 // an ongoing relationship with the app, and not to pester the user too much.
35 // For most events only the last event is recorded. The exception are the
36 // could show events. For these a list of the events is maintained. At most
37 // one event is stored per day, and events outside the window the heuristic
38 // uses are discarded. Local times are used to enforce these rules, to ensure
39 // what we count as a day matches what the user perceives to be days.
40 class AppBannerSettingsHelper {
41 public:
42 enum AppBannerEvent {
43 APP_BANNER_EVENT_COULD_SHOW,
44 APP_BANNER_EVENT_DID_SHOW,
45 APP_BANNER_EVENT_DID_BLOCK,
46 APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
47 APP_BANNER_EVENT_NUM_EVENTS,
50 enum AppBannerRapporMetric {
51 WEB,
52 NATIVE,
55 // BannerEvents record the time that a site was accessed, along with an
56 // engagement weight representing the importance of the access.
57 struct BannerEvent {
58 base::Time time;
59 double engagement;
62 // The content setting basically records a simplified subset of history.
63 // For privacy reasons this needs to be cleared. The ClearHistoryForURLs
64 // function removes any information from the banner content settings for the
65 // given URls.
66 static void ClearHistoryForURLs(Profile* profile,
67 const std::set<GURL>& origin_urls);
69 // Record a banner installation event, for either a WEB or NATIVE app.
70 static void RecordBannerInstallEvent(
71 content::WebContents* web_contents,
72 const std::string& package_name_or_start_url,
73 AppBannerRapporMetric rappor_metric);
75 // Record a banner dismissal event, for either a WEB or NATIVE app.
76 static void RecordBannerDismissEvent(
77 content::WebContents* web_contents,
78 const std::string& package_name_or_start_url,
79 AppBannerRapporMetric rappor_metric);
81 // Record a banner event. Should not be used for could show events, as they
82 // require a transition type.
83 static void RecordBannerEvent(content::WebContents* web_contents,
84 const GURL& origin_url,
85 const std::string& package_name_or_start_url,
86 AppBannerEvent event,
87 base::Time time);
89 // Record a banner could show event, with a specified transition type.
90 static void RecordBannerCouldShowEvent(
91 content::WebContents* web_contents,
92 const GURL& origin_url,
93 const std::string& package_name_or_start_url,
94 base::Time time,
95 ui::PageTransition transition_type);
97 // Determine if the banner should be shown, given the recorded events for the
98 // supplied app.
99 static bool ShouldShowBanner(content::WebContents* web_contents,
100 const GURL& origin_url,
101 const std::string& package_name_or_start_url,
102 base::Time time);
104 // Gets the could have been shown events that are stored for the given package
105 // or start url. This is only exposed for testing.
106 static std::vector<BannerEvent> GetCouldShowBannerEvents(
107 content::WebContents* web_contents,
108 const GURL& origin_url,
109 const std::string& package_name_or_start_url);
111 // Get the recorded event for an event type that only records the last event.
112 // Should not be used with APP_BANNER_EVENT_COULD_SHOW. This is only exposed
113 // for testing.
114 static base::Time GetSingleBannerEvent(
115 content::WebContents* web_contents,
116 const GURL& origin_url,
117 const std::string& package_name_or_start_url,
118 AppBannerEvent event);
120 // Set the engagement weights assigned to direct and indirect navigations.
121 static void SetEngagementWeights(double direct_engagement,
122 double indirect_engagement);
124 // Set the minimum number of minutes between banner visits that will
125 // trigger a could show banner event. This must be less than the
126 // number of minutes in a day, and evenly divide the number of minutes
127 // in a day.
128 static void SetMinimumMinutesBetweenVisits(unsigned int minutes);
130 // Set the total engagement weight required to trigger a banner.
131 static void SetTotalEngagementToTrigger(double total_engagement);
133 // Bucket a given time to the given resolution in local time.
134 static base::Time BucketTimeToResolution(base::Time time,
135 unsigned int minutes);
137 // Updates all values from field trial.
138 static void UpdateFromFieldTrial();
140 private:
141 DISALLOW_IMPLICIT_CONSTRUCTORS(AppBannerSettingsHelper);
144 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_SETTINGS_HELPER_H_