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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 true; |
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()) { |
| 391 banners::TrackInstallableErrorCode(PACKAGE_NAME_OR_START_URL_EMPTY); |
390 return false; | 392 return false; |
| 393 } |
391 | 394 |
392 // Don't show if it has been added to the homescreen. | 395 // Don't show if it has been added to the homescreen. |
393 base::Time added_time = | 396 base::Time added_time = |
394 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, | 397 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, |
395 APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN); | 398 APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN); |
396 if (!added_time.is_null()) { | 399 if (!added_time.is_null()) { |
| 400 banners::TrackInstallableErrorCode(ALREADY_INSTALLED); |
397 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_INSTALLED_PREVIOUSLY); | 401 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_INSTALLED_PREVIOUSLY); |
398 return false; | 402 return false; |
399 } | 403 } |
400 | 404 |
401 base::Time blocked_time = | 405 base::Time blocked_time = |
402 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, | 406 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, |
403 APP_BANNER_EVENT_DID_BLOCK); | 407 APP_BANNER_EVENT_DID_BLOCK); |
404 | 408 |
405 // Null times are in the distant past, so the delta between real times and | 409 // Null times are in the distant past, so the delta between real times and |
406 // null events will always be greater than the limits. | 410 // null events will always be greater than the limits. |
407 if (time - blocked_time < | 411 if (time - blocked_time < |
408 base::TimeDelta::FromDays(kMinimumBannerBlockedToBannerShown)) { | 412 base::TimeDelta::FromDays(kMinimumBannerBlockedToBannerShown)) { |
| 413 banners::TrackInstallableErrorCode(PREVIOUSLY_BLOCKED); |
409 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_BLOCKED_PREVIOUSLY); | 414 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_BLOCKED_PREVIOUSLY); |
410 return false; | 415 return false; |
411 } | 416 } |
412 | 417 |
413 base::Time shown_time = | 418 base::Time shown_time = |
414 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, | 419 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, |
415 APP_BANNER_EVENT_DID_SHOW); | 420 APP_BANNER_EVENT_DID_SHOW); |
416 if (time - shown_time < | 421 if (time - shown_time < |
417 base::TimeDelta::FromDays(kMinimumDaysBetweenBannerShows)) { | 422 base::TimeDelta::FromDays(kMinimumDaysBetweenBannerShows)) { |
| 423 banners::TrackInstallableErrorCode(PREVIOUSLY_IGNORED); |
418 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_IGNORED_PREVIOUSLY); | 424 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_IGNORED_PREVIOUSLY); |
419 return false; | 425 return false; |
420 } | 426 } |
421 | 427 |
422 // If we have gotten this far and want to use site engagement, the banner flow | 428 // 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 | 429 // was triggered by the site engagement service informing the banner manager |
424 // that sufficient engagement has been accumulated. Hence there is no need to | 430 // that sufficient engagement has been accumulated. Hence there is no need to |
425 // check the total amount of engagement. | 431 // check the total amount of engagement. |
426 // TODO(dominickn): just return true here and remove all of the following code | 432 // 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 | 433 // in this method when app banners have fully migrated to using site |
428 // engagement as a trigger condition. See crbug.com/616322. | 434 // engagement as a trigger condition. See crbug.com/616322. |
429 if (ShouldUseSiteEngagementScore()) | 435 if (ShouldUseSiteEngagementScore()) |
430 return true; | 436 return true; |
431 | 437 |
432 double total_engagement = 0; | 438 double total_engagement = 0; |
433 std::vector<BannerEvent> could_show_events = GetCouldShowBannerEvents( | 439 std::vector<BannerEvent> could_show_events = GetCouldShowBannerEvents( |
434 web_contents, origin_url, package_name_or_start_url); | 440 web_contents, origin_url, package_name_or_start_url); |
435 | 441 |
436 for (const auto& event : could_show_events) | 442 for (const auto& event : could_show_events) |
437 total_engagement += event.engagement; | 443 total_engagement += event.engagement; |
438 | 444 |
439 if (!HasSufficientEngagement(total_engagement)) { | 445 if (!HasSufficientEngagement(total_engagement)) { |
| 446 banners::TrackInstallableErrorCode(INSUFFICIENT_ENGAGEMENT); |
440 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_NOT_VISITED_ENOUGH); | 447 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_NOT_VISITED_ENOUGH); |
441 return false; | 448 return false; |
442 } | 449 } |
443 | 450 |
444 return true; | 451 return true; |
445 } | 452 } |
446 | 453 |
447 std::vector<AppBannerSettingsHelper::BannerEvent> | 454 std::vector<AppBannerSettingsHelper::BannerEvent> |
448 AppBannerSettingsHelper::GetCouldShowBannerEvents( | 455 AppBannerSettingsHelper::GetCouldShowBannerEvents( |
449 content::WebContents* web_contents, | 456 content::WebContents* web_contents, |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 return true; | 655 return true; |
649 } | 656 } |
650 | 657 |
651 // Assume any value which is not "0" or "false" indicates that we should use | 658 // Assume any value which is not "0" or "false" indicates that we should use |
652 // site engagement. | 659 // site engagement. |
653 std::string param = variations::GetVariationParamValue( | 660 std::string param = variations::GetVariationParamValue( |
654 kBannerParamsKey, kBannerSiteEngagementParamsKey); | 661 kBannerParamsKey, kBannerSiteEngagementParamsKey); |
655 | 662 |
656 return (!param.empty() && param != "0" && param != "false"); | 663 return (!param.empty() && param != "0" && param != "false"); |
657 } | 664 } |
OLD | NEW |