| 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> |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // Keys to use when querying the variations params. | 74 // Keys to use when querying the variations params. |
| 75 const char kBannerParamsKey[] = "AppBannerTriggering"; | 75 const char kBannerParamsKey[] = "AppBannerTriggering"; |
| 76 const char kBannerParamsDirectKey[] = "direct"; | 76 const char kBannerParamsDirectKey[] = "direct"; |
| 77 const char kBannerParamsIndirectKey[] = "indirect"; | 77 const char kBannerParamsIndirectKey[] = "indirect"; |
| 78 const char kBannerParamsTotalKey[] = "total"; | 78 const char kBannerParamsTotalKey[] = "total"; |
| 79 const char kBannerParamsMinutesKey[] = "minutes"; | 79 const char kBannerParamsMinutesKey[] = "minutes"; |
| 80 const char kBannerParamsEngagementTotalKey[] = "site_engagement_total"; | 80 const char kBannerParamsEngagementTotalKey[] = "site_engagement_total"; |
| 81 const char kBannerParamsDaysAfterBannerDismissedKey[] = "days_after_dismiss"; | 81 const char kBannerParamsDaysAfterBannerDismissedKey[] = "days_after_dismiss"; |
| 82 const char kBannerParamsDaysAfterBannerIgnoredKey[] = "days_after_ignore"; | 82 const char kBannerParamsDaysAfterBannerIgnoredKey[] = "days_after_ignore"; |
| 83 const char kBannerSiteEngagementParamsKey[] = "use_site_engagement"; | 83 const char kBannerSiteEngagementParamsKey[] = "use_site_engagement"; |
| 84 const char kBannerParamsLanguageKey[] = "language_option"; |
| 84 | 85 |
| 85 // Engagement weight assigned to direct and indirect navigations. | 86 // Engagement weight assigned to direct and indirect navigations. |
| 86 // By default, a direct navigation is a page visit via ui::PAGE_TRANSITION_TYPED | 87 // By default, a direct navigation is a page visit via ui::PAGE_TRANSITION_TYPED |
| 87 // or ui::PAGE_TRANSITION_GENERATED. | 88 // or ui::PAGE_TRANSITION_GENERATED. |
| 88 double gDirectNavigationEngagement = kDefaultDirectNavigationEngagement; | 89 double gDirectNavigationEngagement = kDefaultDirectNavigationEngagement; |
| 89 double gIndirectNavigationEnagagement = kDefaultIndirectNavigationEngagement; | 90 double gIndirectNavigationEnagagement = kDefaultIndirectNavigationEngagement; |
| 90 | 91 |
| 91 // Number of minutes between visits that will trigger a could show banner event. | 92 // Number of minutes between visits that will trigger a could show banner event. |
| 92 // Defaults to the number of minutes in a day. | 93 // Defaults to the number of minutes in a day. |
| 93 unsigned int gMinimumMinutesBetweenVisits = kNumberOfMinutesInADay; | 94 unsigned int gMinimumMinutesBetweenVisits = kNumberOfMinutesInADay; |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 // engagement to trigger from the params variations. | 668 // engagement to trigger from the params variations. |
| 668 UpdateDaysBetweenShowing(); | 669 UpdateDaysBetweenShowing(); |
| 669 if (ShouldUseSiteEngagementScore()) { | 670 if (ShouldUseSiteEngagementScore()) { |
| 670 UpdateSiteEngagementToTrigger(); | 671 UpdateSiteEngagementToTrigger(); |
| 671 } else { | 672 } else { |
| 672 UpdateEngagementWeights(); | 673 UpdateEngagementWeights(); |
| 673 UpdateMinutesBetweenVisits(); | 674 UpdateMinutesBetweenVisits(); |
| 674 } | 675 } |
| 675 } | 676 } |
| 676 | 677 |
| 678 AppBannerSettingsHelper::LanguageOption |
| 679 AppBannerSettingsHelper::GetHomescreenLanguageOption() { |
| 680 std::string param = variations::GetVariationParamValue( |
| 681 kBannerParamsKey, kBannerParamsLanguageKey); |
| 682 unsigned int language_option = 0; |
| 683 |
| 684 if (param.empty() || !base::StringToUint(param, &language_option) || |
| 685 language_option < LANGUAGE_OPTION_MIN || |
| 686 language_option > LANGUAGE_OPTION_MAX) { |
| 687 return LANGUAGE_OPTION_DEFAULT; |
| 688 } |
| 689 |
| 690 return static_cast<LanguageOption>(language_option); |
| 691 } |
| 692 |
| 677 bool AppBannerSettingsHelper::ShouldUseSiteEngagementScore() { | 693 bool AppBannerSettingsHelper::ShouldUseSiteEngagementScore() { |
| 678 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 694 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 679 switches::kEnableSiteEngagementAppBanner)) { | 695 switches::kEnableSiteEngagementAppBanner)) { |
| 680 return true; | 696 return true; |
| 681 } | 697 } |
| 682 | 698 |
| 683 // Assume any value which is not "0" or "false" indicates that we should use | 699 // Assume any value which is not "0" or "false" indicates that we should use |
| 684 // site engagement. | 700 // site engagement. |
| 685 std::string param = variations::GetVariationParamValue( | 701 std::string param = variations::GetVariationParamValue( |
| 686 kBannerParamsKey, kBannerSiteEngagementParamsKey); | 702 kBannerParamsKey, kBannerSiteEngagementParamsKey); |
| 687 | 703 |
| 688 return (!param.empty() && param != "0" && param != "false"); | 704 return (!param.empty() && param != "0" && param != "false"); |
| 689 } | 705 } |
| OLD | NEW |