Componentize HistoryURLProvider/ScoredHistoryMatch.
[chromium-blink-merge.git] / chrome / browser / banners / app_banner_settings_helper.h
blobb71802110e5e5a191c9b656414dbf4e464ee940f
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"
15 namespace content {
16 class WebContents;
17 } // namespace content
19 class GURL;
20 class Profile;
22 // Utility class to record banner events for the given package or start url.
24 // These events are used to decide when banners should be shown, using a
25 // heuristic based on how many different days in a recent period of time (for
26 // example the past two weeks) the banner could have been shown, when it was
27 // last shown, when it was last blocked, and when it was last installed (for
28 // ServiceWorker style apps - native apps can query whether the app was
29 // installed directly).
31 // The desired effect is to have banners appear once a user has demonstrated
32 // an ongoing relationship with the app, and not to pester the user too much.
34 // For most events only the last event is recorded. The exception are the
35 // could show events. For these a list of the events is maintained. At most
36 // one event is stored per day, and events outside the window the heuristic
37 // uses are discarded. Local times are used to enforce these rules, to ensure
38 // what we count as a day matches what the user perceives to be days.
39 class AppBannerSettingsHelper {
40 public:
41 enum AppBannerEvent {
42 APP_BANNER_EVENT_COULD_SHOW,
43 APP_BANNER_EVENT_DID_SHOW,
44 APP_BANNER_EVENT_DID_BLOCK,
45 APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
46 APP_BANNER_EVENT_NUM_EVENTS,
49 enum AppBannerRapporMetric {
50 WEB,
51 NATIVE,
54 // The content setting basically records a simplified subset of history.
55 // For privacy reasons this needs to be cleared. The ClearHistoryForURLs
56 // function removes any information from the banner content settings for the
57 // given URls.
58 static void ClearHistoryForURLs(Profile* profile,
59 const std::set<GURL>& origin_urls);
61 // Record a banner installation event, for either a WEB or NATIVE app.
62 static void RecordBannerInstallEvent(
63 content::WebContents* web_contents,
64 const std::string& package_name_or_start_url,
65 AppBannerRapporMetric rappor_metric);
67 // Record a banner dismissal event, for either a WEB or NATIVE app.
68 static void RecordBannerDismissEvent(
69 content::WebContents* web_contents,
70 const std::string& package_name_or_start_url,
71 AppBannerRapporMetric rappor_metric);
73 static void RecordBannerEvent(content::WebContents* web_contents,
74 const GURL& origin_url,
75 const std::string& package_name_or_start_url,
76 AppBannerEvent event,
77 base::Time time);
79 // Determine if the banner should be shown, given the recorded events for the
80 // supplied app.
81 static bool ShouldShowBanner(content::WebContents* web_contents,
82 const GURL& origin_url,
83 const std::string& package_name_or_start_url,
84 base::Time time);
86 // Gets the could have been shown events that are stored for the given package
87 // or start url. This is only exposed for testing.
88 static std::vector<base::Time> GetCouldShowBannerEvents(
89 content::WebContents* web_contents,
90 const GURL& origin_url,
91 const std::string& package_name_or_start_url);
93 // Get the recorded event for an event type that only records the last event.
94 // Should not be used with APP_BANNER_EVENT_COULD_SHOW. This is only exposed
95 // for testing.
96 static base::Time GetSingleBannerEvent(
97 content::WebContents* web_contents,
98 const GURL& origin_url,
99 const std::string& package_name_or_start_url,
100 AppBannerEvent event);
102 private:
103 DISALLOW_IMPLICIT_CONSTRUCTORS(AppBannerSettingsHelper);
106 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_SETTINGS_HELPER_H_