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/android/instantapps/instant_apps_settings.h" | |
Ted C
2016/09/30 18:01:34
This class isn't android specific as of yet, so ma
Maria
2016/09/30 20:35:18
Done.
| |
18 #include "chrome/browser/banners/app_banner_manager.h" | 19 #include "chrome/browser/banners/app_banner_manager.h" |
19 #include "chrome/browser/banners/app_banner_metrics.h" | 20 #include "chrome/browser/banners/app_banner_metrics.h" |
20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
22 #include "chrome/browser/installable/installable_logging.h" | 23 #include "chrome/browser/installable/installable_logging.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
25 #include "components/content_settings/core/browser/host_content_settings_map.h" | 26 #include "components/content_settings/core/browser/host_content_settings_map.h" |
26 #include "components/content_settings/core/common/content_settings_pattern.h" | 27 #include "components/content_settings/core/common/content_settings_pattern.h" |
27 #include "components/rappor/rappor_utils.h" | 28 #include "components/rappor/rappor_utils.h" |
28 #include "components/variations/variations_associated_data.h" | 29 #include "components/variations/variations_associated_data.h" |
29 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
30 #include "net/base/escape.h" | 31 #include "net/base/escape.h" |
31 #include "url/gurl.h" | 32 #include "url/gurl.h" |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 // Max number of apps (including ServiceWorker based web apps) that a particular | 36 // Max number of apps (including ServiceWorker based web apps) that a particular |
36 // site may show a banner for. | 37 // site may show a banner for. |
37 const size_t kMaxAppsPerSite = 3; | 38 const size_t kMaxAppsPerSite = 3; |
38 | 39 |
39 // Oldest could show banner event we care about, in days. | 40 // Oldest could show banner event we care about, in days. |
40 const unsigned int kOldestCouldShowBannerEventInDays = 14; | 41 const unsigned int kOldestCouldShowBannerEventInDays = 14; |
41 | 42 |
42 // Number of days that showing the banner will prevent it being seen again for. | 43 // Number of days that showing the banner will prevent it being seen again for. |
43 const unsigned int kMinimumDaysBetweenBannerShows = 60; | 44 const unsigned int kMinimumDaysBetweenBannerShows = 14; |
44 | 45 |
45 const unsigned int kNumberOfMinutesInADay = 1440; | 46 const unsigned int kNumberOfMinutesInADay = 1440; |
46 | 47 |
47 // Number of days that the banner being blocked will prevent it being seen again | 48 // Number of days that the banner being blocked will prevent it being seen again |
48 // for. | 49 // for. |
49 const unsigned int kMinimumBannerBlockedToBannerShown = 90; | 50 const unsigned int kMinimumBannerBlockedToBannerShown = 90; |
50 | 51 |
51 // Default scores assigned to direct and indirect navigations respectively. | 52 // Default scores assigned to direct and indirect navigations respectively. |
52 const unsigned int kDefaultDirectNavigationEngagement = 1; | 53 const unsigned int kDefaultDirectNavigationEngagement = 1; |
53 const unsigned int kDefaultIndirectNavigationEngagement = 1; | 54 const unsigned int kDefaultIndirectNavigationEngagement = 1; |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 } | 388 } |
388 | 389 |
389 // Never show a banner when the package name or URL is empty. | 390 // Never show a banner when the package name or URL is empty. |
390 if (package_name_or_start_url.empty()) | 391 if (package_name_or_start_url.empty()) |
391 return PACKAGE_NAME_OR_START_URL_EMPTY; | 392 return PACKAGE_NAME_OR_START_URL_EMPTY; |
392 | 393 |
393 // Don't show if it has been added to the homescreen. | 394 // Don't show if it has been added to the homescreen. |
394 base::Time added_time = | 395 base::Time added_time = |
395 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, | 396 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, |
396 APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN); | 397 APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN); |
397 if (!added_time.is_null()) { | 398 if (!added_time.is_null()) |
398 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_INSTALLED_PREVIOUSLY); | |
399 return ALREADY_INSTALLED; | 399 return ALREADY_INSTALLED; |
400 } | |
401 | 400 |
402 base::Time blocked_time = | 401 base::Time blocked_time = |
403 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, | 402 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, |
404 APP_BANNER_EVENT_DID_BLOCK); | 403 APP_BANNER_EVENT_DID_BLOCK); |
405 | 404 |
406 // Null times are in the distant past, so the delta between real times and | 405 // Null times are in the distant past, so the delta between real times and |
407 // null events will always be greater than the limits. | 406 // null events will always be greater than the limits. |
408 if (time - blocked_time < | 407 if (time - blocked_time < |
409 base::TimeDelta::FromDays(kMinimumBannerBlockedToBannerShown)) { | 408 base::TimeDelta::FromDays(kMinimumBannerBlockedToBannerShown)) |
410 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_BLOCKED_PREVIOUSLY); | |
411 return PREVIOUSLY_BLOCKED; | 409 return PREVIOUSLY_BLOCKED; |
412 } | |
413 | 410 |
414 base::Time shown_time = | 411 base::Time shown_time = |
415 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, | 412 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, |
416 APP_BANNER_EVENT_DID_SHOW); | 413 APP_BANNER_EVENT_DID_SHOW); |
417 if (time - shown_time < | 414 if (time - shown_time < |
418 base::TimeDelta::FromDays(kMinimumDaysBetweenBannerShows)) { | 415 base::TimeDelta::FromDays(kMinimumDaysBetweenBannerShows)) |
419 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_IGNORED_PREVIOUSLY); | |
420 return PREVIOUSLY_IGNORED; | 416 return PREVIOUSLY_IGNORED; |
421 } | |
422 | 417 |
423 // If we have gotten this far and want to use site engagement, the banner flow | 418 // If we have gotten this far and want to use site engagement, the banner flow |
424 // was triggered by the site engagement service informing the banner manager | 419 // was triggered by the site engagement service informing the banner manager |
425 // that sufficient engagement has been accumulated. Hence there is no need to | 420 // that sufficient engagement has been accumulated. Hence there is no need to |
426 // check the total amount of engagement. | 421 // check the total amount of engagement. |
427 // TODO(dominickn): just return true here and remove all of the following code | 422 // TODO(dominickn): just return true here and remove all of the following code |
428 // in this method when app banners have fully migrated to using site | 423 // in this method when app banners have fully migrated to using site |
429 // engagement as a trigger condition. See crbug.com/616322. | 424 // engagement as a trigger condition. See crbug.com/616322. |
430 if (ShouldUseSiteEngagementScore()) | 425 // Do not do engagement checks for instant app banners. |
426 if (ShouldUseSiteEngagementScore() || | |
427 package_name_or_start_url == InstantAppsSettings::kInstantAppsKey) | |
Ted C
2016/09/30 18:01:34
when the condition is more than one line, I like t
Maria
2016/09/30 20:35:18
Done.
| |
431 return NO_ERROR_DETECTED; | 428 return NO_ERROR_DETECTED; |
432 | 429 |
433 double total_engagement = 0; | 430 double total_engagement = 0; |
434 std::vector<BannerEvent> could_show_events = GetCouldShowBannerEvents( | 431 std::vector<BannerEvent> could_show_events = GetCouldShowBannerEvents( |
435 web_contents, origin_url, package_name_or_start_url); | 432 web_contents, origin_url, package_name_or_start_url); |
436 | 433 |
437 for (const auto& event : could_show_events) | 434 for (const auto& event : could_show_events) |
438 total_engagement += event.engagement; | 435 total_engagement += event.engagement; |
439 | 436 |
440 if (!HasSufficientEngagement(total_engagement)) { | 437 if (!HasSufficientEngagement(total_engagement)) |
441 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_NOT_VISITED_ENOUGH); | |
442 return INSUFFICIENT_ENGAGEMENT; | 438 return INSUFFICIENT_ENGAGEMENT; |
443 } | |
444 | 439 |
445 return NO_ERROR_DETECTED; | 440 return NO_ERROR_DETECTED; |
446 } | 441 } |
447 | 442 |
448 std::vector<AppBannerSettingsHelper::BannerEvent> | 443 std::vector<AppBannerSettingsHelper::BannerEvent> |
449 AppBannerSettingsHelper::GetCouldShowBannerEvents( | 444 AppBannerSettingsHelper::GetCouldShowBannerEvents( |
450 content::WebContents* web_contents, | 445 content::WebContents* web_contents, |
451 const GURL& origin_url, | 446 const GURL& origin_url, |
452 const std::string& package_name_or_start_url) { | 447 const std::string& package_name_or_start_url) { |
453 std::vector<BannerEvent> result; | 448 std::vector<BannerEvent> result; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 // homescreen recently, return true. | 553 // homescreen recently, return true. |
559 for (base::DictionaryValue::Iterator it(*origin_dict); !it.IsAtEnd(); | 554 for (base::DictionaryValue::Iterator it(*origin_dict); !it.IsAtEnd(); |
560 it.Advance()) { | 555 it.Advance()) { |
561 if (it.value().IsType(base::Value::TYPE_DICTIONARY)) { | 556 if (it.value().IsType(base::Value::TYPE_DICTIONARY)) { |
562 const base::DictionaryValue* value; | 557 const base::DictionaryValue* value; |
563 it.value().GetAsDictionary(&value); | 558 it.value().GetAsDictionary(&value); |
564 | 559 |
565 std::string event_key( | 560 std::string event_key( |
566 kBannerEventKeys[APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN]); | 561 kBannerEventKeys[APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN]); |
567 double internal_time; | 562 double internal_time; |
568 if (!value->GetDouble(event_key, &internal_time)) | 563 if (it.key() == InstantAppsSettings::kInstantAppsKey || |
564 !value->GetDouble(event_key, &internal_time)) | |
569 continue; | 565 continue; |
570 | 566 |
571 base::Time added_time = base::Time::FromInternalValue(internal_time); | 567 base::Time added_time = base::Time::FromInternalValue(internal_time); |
572 | 568 |
573 if ((now - added_time) <= | 569 if ((now - added_time) <= |
574 base::TimeDelta::FromDays(kRecentLastLaunchInDays)) { | 570 base::TimeDelta::FromDays(kRecentLastLaunchInDays)) { |
575 return true; | 571 return true; |
576 } | 572 } |
577 } | 573 } |
578 } | 574 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 return true; | 642 return true; |
647 } | 643 } |
648 | 644 |
649 // Assume any value which is not "0" or "false" indicates that we should use | 645 // Assume any value which is not "0" or "false" indicates that we should use |
650 // site engagement. | 646 // site engagement. |
651 std::string param = variations::GetVariationParamValue( | 647 std::string param = variations::GetVariationParamValue( |
652 kBannerParamsKey, kBannerSiteEngagementParamsKey); | 648 kBannerParamsKey, kBannerSiteEngagementParamsKey); |
653 | 649 |
654 return (!param.empty() && param != "0" && param != "false"); | 650 return (!param.empty() && param != "0" && param != "false"); |
655 } | 651 } |
OLD | NEW |