Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / banners / app_banner_settings_helper.h
blob8e0e971589ad75acc3160e7f25492d1eaf555671
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 // The content setting basically records a simplified subset of history.
50 // For privacy reasons this needs to be cleared. The ClearHistoryForURLs
51 // function removes any information from the banner content settings for the
52 // given URls.
53 static void ClearHistoryForURLs(Profile* profile,
54 const std::set<GURL>& origin_urls);
56 static void RecordBannerEvent(content::WebContents* web_contents,
57 const GURL& origin_url,
58 const std::string& package_name_or_start_url,
59 AppBannerEvent event,
60 base::Time time);
62 // Determine if the banner should be shown, given the recorded events for the
63 // supplied app.
64 static bool ShouldShowBanner(content::WebContents* web_contents,
65 const GURL& origin_url,
66 const std::string& package_name_or_start_url,
67 base::Time time);
69 // Gets the could have been shown events that are stored for the given package
70 // or start url. This is only exposed for testing.
71 static std::vector<base::Time> GetCouldShowBannerEvents(
72 content::WebContents* web_contents,
73 const GURL& origin_url,
74 const std::string& package_name_or_start_url);
76 // Get the recorded event for an event type that only records the last event.
77 // Should not be used with APP_BANNER_EVENT_COULD_SHOW. This is only exposed
78 // for testing.
79 static base::Time GetSingleBannerEvent(
80 content::WebContents* web_contents,
81 const GURL& origin_url,
82 const std::string& package_name_or_start_url,
83 AppBannerEvent event);
85 private:
86 DISALLOW_IMPLICIT_CONSTRUCTORS(AppBannerSettingsHelper);
89 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_SETTINGS_HELPER_H_