OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_BANNERS_APP_BANNER_SETTINGS_HELPER_H_ | 5 #ifndef CHROME_BROWSER_BANNERS_APP_BANNER_SETTINGS_HELPER_H_ |
6 #define CHROME_BROWSER_BANNERS_APP_BANNER_SETTINGS_HELPER_H_ | 6 #define CHROME_BROWSER_BANNERS_APP_BANNER_SETTINGS_HELPER_H_ |
7 | 7 |
| 8 #include <set> |
8 #include <string> | 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 | 14 |
14 namespace content { | 15 namespace content { |
15 class WebContents; | 16 class WebContents; |
16 } // namespace content | 17 } // namespace content |
17 | 18 |
18 class GURL; | 19 class GURL; |
| 20 class Profile; |
19 | 21 |
20 // Utility class to record banner events for the given package or start url. | 22 // Utility class to record banner events for the given package or start url. |
21 // | 23 // |
22 // These events are used to decide when banners should be shown, using a | 24 // These events are used to decide when banners should be shown, using a |
23 // heuristic based on how many different days in a recent period of time (for | 25 // heuristic based on how many different days in a recent period of time (for |
24 // example the past two weeks) the banner could have been shown, when it was | 26 // example the past two weeks) the banner could have been shown, when it was |
25 // last shown, when it was last blocked, and when it was last installed (for | 27 // last shown, when it was last blocked, and when it was last installed (for |
26 // ServiceWorker style apps - native apps can query whether the app was | 28 // ServiceWorker style apps - native apps can query whether the app was |
27 // installed directly). | 29 // installed directly). |
28 // | 30 // |
29 // The desired effect is to have banners appear once a user has demonstrated | 31 // The desired effect is to have banners appear once a user has demonstrated |
30 // an ongoing relationship with the app, and not to pester the user too much. | 32 // an ongoing relationship with the app, and not to pester the user too much. |
31 // | 33 // |
32 // For most events only the last event is recorded. The exception are the | 34 // For most events only the last event is recorded. The exception are the |
33 // could show events. For these a list of the events is maintained. At most | 35 // could show events. For these a list of the events is maintained. At most |
34 // one event is stored per day, and events outside the window the heuristic | 36 // one event is stored per day, and events outside the window the heuristic |
35 // uses are discarded. Local times are used to enforce these rules, to ensure | 37 // uses are discarded. Local times are used to enforce these rules, to ensure |
36 // what we count as a day matches what the user perceives to be days. | 38 // what we count as a day matches what the user perceives to be days. |
37 class AppBannerSettingsHelper { | 39 class AppBannerSettingsHelper { |
38 public: | 40 public: |
39 enum AppBannerEvent { | 41 enum AppBannerEvent { |
40 APP_BANNER_EVENT_COULD_SHOW, | 42 APP_BANNER_EVENT_COULD_SHOW, |
41 APP_BANNER_EVENT_DID_SHOW, | 43 APP_BANNER_EVENT_DID_SHOW, |
42 APP_BANNER_EVENT_DID_BLOCK, | 44 APP_BANNER_EVENT_DID_BLOCK, |
43 APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | 45 APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, |
44 APP_BANNER_EVENT_NUM_EVENTS, | 46 APP_BANNER_EVENT_NUM_EVENTS, |
45 }; | 47 }; |
46 | 48 |
| 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); |
| 55 |
47 static void RecordBannerEvent(content::WebContents* web_contents, | 56 static void RecordBannerEvent(content::WebContents* web_contents, |
48 const GURL& origin_url, | 57 const GURL& origin_url, |
49 const std::string& package_name_or_start_url, | 58 const std::string& package_name_or_start_url, |
50 AppBannerEvent event, | 59 AppBannerEvent event, |
51 base::Time time); | 60 base::Time time); |
52 | 61 |
53 // Determine if the banner should be shown, given the recorded events for the | 62 // Determine if the banner should be shown, given the recorded events for the |
54 // supplied app. | 63 // supplied app. |
55 static bool ShouldShowBanner(content::WebContents* web_contents, | 64 static bool ShouldShowBanner(content::WebContents* web_contents, |
56 const GURL& origin_url, | 65 const GURL& origin_url, |
(...skipping 25 matching lines...) Expand all Loading... |
82 // Blocks a URL from showing a banner for the given package or start url. | 91 // Blocks a URL from showing a banner for the given package or start url. |
83 static void Block(content::WebContents* web_contents, | 92 static void Block(content::WebContents* web_contents, |
84 const GURL& origin_url, | 93 const GURL& origin_url, |
85 const std::string& package_name_or_start_url); | 94 const std::string& package_name_or_start_url); |
86 | 95 |
87 private: | 96 private: |
88 DISALLOW_IMPLICIT_CONSTRUCTORS(AppBannerSettingsHelper); | 97 DISALLOW_IMPLICIT_CONSTRUCTORS(AppBannerSettingsHelper); |
89 }; | 98 }; |
90 | 99 |
91 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_SETTINGS_HELPER_H_ | 100 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_SETTINGS_HELPER_H_ |
OLD | NEW |