| 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 <stddef.h> | 7 #include <stddef.h> | 
| 8 | 8 | 
| 9 #include <algorithm> | 9 #include <algorithm> | 
| 10 #include <string> | 10 #include <string> | 
| 11 #include <utility> | 11 #include <utility> | 
| 12 | 12 | 
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" | 
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" | 
| 15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" | 
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" | 
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" | 
| 18 #include "chrome/browser/banners/app_banner_manager.h" | 18 #include "chrome/browser/banners/app_banner_manager.h" | 
| 19 #include "chrome/browser/banners/app_banner_metrics.h" | 19 #include "chrome/browser/banners/app_banner_metrics.h" | 
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" | 
| 21 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 21 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 
|  | 22 #include "chrome/browser/installable/installable_logging.h" | 
| 22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" | 
| 23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" | 
| 24 #include "components/content_settings/core/browser/host_content_settings_map.h" | 25 #include "components/content_settings/core/browser/host_content_settings_map.h" | 
| 25 #include "components/content_settings/core/common/content_settings_pattern.h" | 26 #include "components/content_settings/core/common/content_settings_pattern.h" | 
| 26 #include "components/rappor/rappor_utils.h" | 27 #include "components/rappor/rappor_utils.h" | 
| 27 #include "components/variations/variations_associated_data.h" | 28 #include "components/variations/variations_associated_data.h" | 
| 28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" | 
| 29 #include "net/base/escape.h" | 30 #include "net/base/escape.h" | 
| 30 #include "url/gurl.h" | 31 #include "url/gurl.h" | 
| 31 | 32 | 
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 367   std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 368   std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 
| 368   value->SetDouble(kBannerTimeKey, time.ToInternalValue()); | 369   value->SetDouble(kBannerTimeKey, time.ToInternalValue()); | 
| 369   value->SetDouble(kBannerEngagementKey, engagement); | 370   value->SetDouble(kBannerEngagementKey, engagement); | 
| 370   could_show_list->Append(std::move(value)); | 371   could_show_list->Append(std::move(value)); | 
| 371 | 372 | 
| 372   settings->SetWebsiteSettingDefaultScope( | 373   settings->SetWebsiteSettingDefaultScope( | 
| 373       origin_url, GURL(), CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), | 374       origin_url, GURL(), CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), | 
| 374       std::move(origin_dict)); | 375       std::move(origin_dict)); | 
| 375 } | 376 } | 
| 376 | 377 | 
| 377 bool AppBannerSettingsHelper::ShouldShowBanner( | 378 InstallableStatusCode AppBannerSettingsHelper::ShouldShowBanner( | 
| 378     content::WebContents* web_contents, | 379     content::WebContents* web_contents, | 
| 379     const GURL& origin_url, | 380     const GURL& origin_url, | 
| 380     const std::string& package_name_or_start_url, | 381     const std::string& package_name_or_start_url, | 
| 381     base::Time time) { | 382     base::Time time) { | 
| 382   // Ignore all checks if the flag to do so is set. | 383   // Ignore all checks if the flag to do so is set. | 
| 383   if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 384   if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| 384           switches::kBypassAppBannerEngagementChecks)) { | 385           switches::kBypassAppBannerEngagementChecks)) { | 
| 385     return true; | 386     return NO_ERROR_DETECTED; | 
| 386   } | 387   } | 
| 387 | 388 | 
| 388   // Never show a banner when the package name or URL is empty. | 389   // Never show a banner when the package name or URL is empty. | 
| 389   if (package_name_or_start_url.empty()) | 390   if (package_name_or_start_url.empty()) | 
| 390     return false; | 391     return PACKAGE_NAME_OR_START_URL_EMPTY; | 
| 391 | 392 | 
| 392   // Don't show if it has been added to the homescreen. | 393   // Don't show if it has been added to the homescreen. | 
| 393   base::Time added_time = | 394   base::Time added_time = | 
| 394       GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, | 395       GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, | 
| 395                            APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN); | 396                            APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN); | 
| 396   if (!added_time.is_null()) { | 397   if (!added_time.is_null()) { | 
| 397     banners::TrackDisplayEvent(banners::DISPLAY_EVENT_INSTALLED_PREVIOUSLY); | 398     banners::TrackDisplayEvent(banners::DISPLAY_EVENT_INSTALLED_PREVIOUSLY); | 
| 398     return false; | 399     return ALREADY_INSTALLED; | 
| 399   } | 400   } | 
| 400 | 401 | 
| 401   base::Time blocked_time = | 402   base::Time blocked_time = | 
| 402       GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, | 403       GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, | 
| 403                            APP_BANNER_EVENT_DID_BLOCK); | 404                            APP_BANNER_EVENT_DID_BLOCK); | 
| 404 | 405 | 
| 405   // Null times are in the distant past, so the delta between real times and | 406   // Null times are in the distant past, so the delta between real times and | 
| 406   // null events will always be greater than the limits. | 407   // null events will always be greater than the limits. | 
| 407   if (time - blocked_time < | 408   if (time - blocked_time < | 
| 408       base::TimeDelta::FromDays(kMinimumBannerBlockedToBannerShown)) { | 409       base::TimeDelta::FromDays(kMinimumBannerBlockedToBannerShown)) { | 
| 409     banners::TrackDisplayEvent(banners::DISPLAY_EVENT_BLOCKED_PREVIOUSLY); | 410     banners::TrackDisplayEvent(banners::DISPLAY_EVENT_BLOCKED_PREVIOUSLY); | 
| 410     return false; | 411     return PREVIOUSLY_BLOCKED; | 
| 411   } | 412   } | 
| 412 | 413 | 
| 413   base::Time shown_time = | 414   base::Time shown_time = | 
| 414       GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, | 415       GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, | 
| 415                            APP_BANNER_EVENT_DID_SHOW); | 416                            APP_BANNER_EVENT_DID_SHOW); | 
| 416   if (time - shown_time < | 417   if (time - shown_time < | 
| 417       base::TimeDelta::FromDays(kMinimumDaysBetweenBannerShows)) { | 418       base::TimeDelta::FromDays(kMinimumDaysBetweenBannerShows)) { | 
| 418     banners::TrackDisplayEvent(banners::DISPLAY_EVENT_IGNORED_PREVIOUSLY); | 419     banners::TrackDisplayEvent(banners::DISPLAY_EVENT_IGNORED_PREVIOUSLY); | 
| 419     return false; | 420     return PREVIOUSLY_IGNORED; | 
| 420   } | 421   } | 
| 421 | 422 | 
| 422   // If we have gotten this far and want to use site engagement, the banner flow | 423   // If we have gotten this far and want to use site engagement, the banner flow | 
| 423   // was triggered by the site engagement service informing the banner manager | 424   // was triggered by the site engagement service informing the banner manager | 
| 424   // that sufficient engagement has been accumulated. Hence there is no need to | 425   // that sufficient engagement has been accumulated. Hence there is no need to | 
| 425   // check the total amount of engagement. | 426   // check the total amount of engagement. | 
| 426   // TODO(dominickn): just return true here and remove all of the following code | 427   // TODO(dominickn): just return true here and remove all of the following code | 
| 427   // in this method when app banners have fully migrated to using site | 428   // in this method when app banners have fully migrated to using site | 
| 428   // engagement as a trigger condition. See crbug.com/616322. | 429   // engagement as a trigger condition. See crbug.com/616322. | 
| 429   if (ShouldUseSiteEngagementScore()) | 430   if (ShouldUseSiteEngagementScore()) | 
| 430     return true; | 431     return NO_ERROR_DETECTED; | 
| 431 | 432 | 
| 432   double total_engagement = 0; | 433   double total_engagement = 0; | 
| 433   std::vector<BannerEvent> could_show_events = GetCouldShowBannerEvents( | 434   std::vector<BannerEvent> could_show_events = GetCouldShowBannerEvents( | 
| 434       web_contents, origin_url, package_name_or_start_url); | 435       web_contents, origin_url, package_name_or_start_url); | 
| 435 | 436 | 
| 436   for (const auto& event : could_show_events) | 437   for (const auto& event : could_show_events) | 
| 437     total_engagement += event.engagement; | 438     total_engagement += event.engagement; | 
| 438 | 439 | 
| 439   if (!HasSufficientEngagement(total_engagement)) { | 440   if (!HasSufficientEngagement(total_engagement)) { | 
| 440     banners::TrackDisplayEvent(banners::DISPLAY_EVENT_NOT_VISITED_ENOUGH); | 441     banners::TrackDisplayEvent(banners::DISPLAY_EVENT_NOT_VISITED_ENOUGH); | 
| 441     return false; | 442     return INSUFFICIENT_ENGAGEMENT; | 
| 442   } | 443   } | 
| 443 | 444 | 
| 444   return true; | 445   return NO_ERROR_DETECTED; | 
| 445 } | 446 } | 
| 446 | 447 | 
| 447 std::vector<AppBannerSettingsHelper::BannerEvent> | 448 std::vector<AppBannerSettingsHelper::BannerEvent> | 
| 448 AppBannerSettingsHelper::GetCouldShowBannerEvents( | 449 AppBannerSettingsHelper::GetCouldShowBannerEvents( | 
| 449     content::WebContents* web_contents, | 450     content::WebContents* web_contents, | 
| 450     const GURL& origin_url, | 451     const GURL& origin_url, | 
| 451     const std::string& package_name_or_start_url) { | 452     const std::string& package_name_or_start_url) { | 
| 452   std::vector<BannerEvent> result; | 453   std::vector<BannerEvent> result; | 
| 453 | 454 | 
| 454   Profile* profile = | 455   Profile* profile = | 
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 648     return true; | 649     return true; | 
| 649   } | 650   } | 
| 650 | 651 | 
| 651   // Assume any value which is not "0" or "false" indicates that we should use | 652   // Assume any value which is not "0" or "false" indicates that we should use | 
| 652   // site engagement. | 653   // site engagement. | 
| 653   std::string param = variations::GetVariationParamValue( | 654   std::string param = variations::GetVariationParamValue( | 
| 654       kBannerParamsKey, kBannerSiteEngagementParamsKey); | 655       kBannerParamsKey, kBannerSiteEngagementParamsKey); | 
| 655 | 656 | 
| 656   return (!param.empty() && param != "0" && param != "false"); | 657   return (!param.empty() && param != "0" && param != "false"); | 
| 657 } | 658 } | 
| OLD | NEW | 
|---|