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 #include "chrome/browser/banners/app_banner_settings_helper.h" | 5 #include "chrome/browser/banners/app_banner_settings_helper.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "chrome/browser/banners/app_banner_metrics.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
13 #include "components/content_settings/core/browser/host_content_settings_map.h" | 14 #include "components/content_settings/core/browser/host_content_settings_map.h" |
14 #include "components/content_settings/core/common/content_settings_pattern.h" | 15 #include "components/content_settings/core/common/content_settings_pattern.h" |
15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
16 #include "net/base/escape.h" | 17 #include "net/base/escape.h" |
17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 base::Time time) { | 182 base::Time time) { |
182 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 183 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
183 switches::kBypassAppBannerEngagementChecks)) { | 184 switches::kBypassAppBannerEngagementChecks)) { |
184 return true; | 185 return true; |
185 } | 186 } |
186 | 187 |
187 // Don't show if it has been added to the homescreen. | 188 // Don't show if it has been added to the homescreen. |
188 base::Time added_time = | 189 base::Time added_time = |
189 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, | 190 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, |
190 APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN); | 191 APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN); |
191 if (!added_time.is_null()) | 192 if (!added_time.is_null()) { |
| 193 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_INSTALLED_PREVIOUSLY); |
192 return false; | 194 return false; |
| 195 } |
193 | 196 |
194 base::Time blocked_time = | 197 base::Time blocked_time = |
195 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, | 198 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, |
196 APP_BANNER_EVENT_DID_BLOCK); | 199 APP_BANNER_EVENT_DID_BLOCK); |
197 | 200 |
198 // Null times are in the distant past, so the delta between real times and | 201 // Null times are in the distant past, so the delta between real times and |
199 // null events will always be greater than the limits. | 202 // null events will always be greater than the limits. |
200 if (time - blocked_time < | 203 if (time - blocked_time < |
201 base::TimeDelta::FromDays(kMinimumBannerBlockedToBannerShown)) { | 204 base::TimeDelta::FromDays(kMinimumBannerBlockedToBannerShown)) { |
| 205 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_BLOCKED_PREVIOUSLY); |
202 return false; | 206 return false; |
203 } | 207 } |
204 | 208 |
205 base::Time shown_time = | 209 base::Time shown_time = |
206 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, | 210 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, |
207 APP_BANNER_EVENT_DID_SHOW); | 211 APP_BANNER_EVENT_DID_SHOW); |
208 if (time - shown_time < | 212 if (time - shown_time < |
209 base::TimeDelta::FromDays(kMinimumDaysBetweenBannerShows)) { | 213 base::TimeDelta::FromDays(kMinimumDaysBetweenBannerShows)) { |
| 214 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_IGNORED_PREVIOUSLY); |
210 return false; | 215 return false; |
211 } | 216 } |
212 | 217 |
213 std::vector<base::Time> could_show_events = GetCouldShowBannerEvents( | 218 std::vector<base::Time> could_show_events = GetCouldShowBannerEvents( |
214 web_contents, origin_url, package_name_or_start_url); | 219 web_contents, origin_url, package_name_or_start_url); |
215 return could_show_events.size() >= kCouldShowEventsToTrigger; | 220 if (could_show_events.size() < kCouldShowEventsToTrigger) { |
| 221 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_NOT_VISITED_ENOUGH); |
| 222 return false; |
| 223 } |
| 224 |
| 225 return true; |
216 } | 226 } |
217 | 227 |
218 std::vector<base::Time> AppBannerSettingsHelper::GetCouldShowBannerEvents( | 228 std::vector<base::Time> AppBannerSettingsHelper::GetCouldShowBannerEvents( |
219 content::WebContents* web_contents, | 229 content::WebContents* web_contents, |
220 const GURL& origin_url, | 230 const GURL& origin_url, |
221 const std::string& package_name_or_start_url) { | 231 const std::string& package_name_or_start_url) { |
222 std::vector<base::Time> result; | 232 std::vector<base::Time> result; |
223 if (package_name_or_start_url.empty()) | 233 if (package_name_or_start_url.empty()) |
224 return result; | 234 return result; |
225 | 235 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 GetAppDict(origin_dict.get(), package_name_or_start_url); | 353 GetAppDict(origin_dict.get(), package_name_or_start_url); |
344 if (!app_dict) | 354 if (!app_dict) |
345 return; | 355 return; |
346 | 356 |
347 // Update the setting and save it back. | 357 // Update the setting and save it back. |
348 app_dict->SetBoolean(kHasBlockedKey, true); | 358 app_dict->SetBoolean(kHasBlockedKey, true); |
349 settings->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), | 359 settings->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), |
350 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), | 360 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), |
351 origin_dict.release()); | 361 origin_dict.release()); |
352 } | 362 } |
OLD | NEW |