Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: chrome/browser/banners/app_banner_settings_helper.cc

Issue 2185453003: Expose a WasLaunchedRecently method using the app banner content setting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // for. 47 // for.
48 const unsigned int kMinimumBannerBlockedToBannerShown = 90; 48 const unsigned int kMinimumBannerBlockedToBannerShown = 90;
49 49
50 // Default scores assigned to direct and indirect navigations respectively. 50 // Default scores assigned to direct and indirect navigations respectively.
51 const unsigned int kDefaultDirectNavigationEngagement = 1; 51 const unsigned int kDefaultDirectNavigationEngagement = 1;
52 const unsigned int kDefaultIndirectNavigationEngagement = 1; 52 const unsigned int kDefaultIndirectNavigationEngagement = 1;
53 53
54 // Default number of navigations required to trigger the banner. 54 // Default number of navigations required to trigger the banner.
55 const unsigned int kDefaultTotalEngagementToTrigger = 2; 55 const unsigned int kDefaultTotalEngagementToTrigger = 2;
56 56
57 // The number of days in the past that a site should be launched from homescreen
58 // to be considered recent.
59 // TODO(dominickn): work out how to unify this with
60 // WebappDataStorage.wasLaunchedRecently.
61 const unsigned int kRecentLastLaunchInDays = 10;
62
57 // Dictionary keys to use for the events. 63 // Dictionary keys to use for the events.
58 const char* kBannerEventKeys[] = { 64 const char* kBannerEventKeys[] = {
59 "couldShowBannerEvents", 65 "couldShowBannerEvents",
60 "didShowBannerEvent", 66 "didShowBannerEvent",
61 "didBlockBannerEvent", 67 "didBlockBannerEvent",
62 "didAddToHomescreenEvent", 68 "didAddToHomescreenEvent",
63 }; 69 };
64 70
65 // Keys to use when storing BannerEvent structs. 71 // Keys to use when storing BannerEvent structs.
66 const char kBannerTimeKey[] = "time"; 72 const char kBannerTimeKey[] = "time";
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 210 }
205 } 211 }
206 212
207 void AppBannerSettingsHelper::RecordBannerInstallEvent( 213 void AppBannerSettingsHelper::RecordBannerInstallEvent(
208 content::WebContents* web_contents, 214 content::WebContents* web_contents,
209 const std::string& package_name_or_start_url, 215 const std::string& package_name_or_start_url,
210 AppBannerRapporMetric rappor_metric) { 216 AppBannerRapporMetric rappor_metric) {
211 banners::TrackInstallEvent(banners::INSTALL_EVENT_WEB_APP_INSTALLED); 217 banners::TrackInstallEvent(banners::INSTALL_EVENT_WEB_APP_INSTALLED);
212 218
213 AppBannerSettingsHelper::RecordBannerEvent( 219 AppBannerSettingsHelper::RecordBannerEvent(
214 web_contents, web_contents->GetURL(), 220 web_contents, web_contents->GetURL(), package_name_or_start_url,
215 package_name_or_start_url,
216 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, 221 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
217 banners::AppBannerDataFetcher::GetCurrentTime()); 222 banners::AppBannerDataFetcher::GetCurrentTime());
218 223
219 rappor::SampleDomainAndRegistryFromGURL( 224 rappor::SampleDomainAndRegistryFromGURL(
220 g_browser_process->rappor_service(), 225 g_browser_process->rappor_service(),
221 (rappor_metric == WEB ? "AppBanner.WebApp.Installed" 226 (rappor_metric == WEB ? "AppBanner.WebApp.Installed"
222 : "AppBanner.NativeApp.Installed"), 227 : "AppBanner.NativeApp.Installed"),
223 web_contents->GetURL()); 228 web_contents->GetURL());
224 } 229 }
225 230
226 void AppBannerSettingsHelper::RecordBannerDismissEvent( 231 void AppBannerSettingsHelper::RecordBannerDismissEvent(
227 content::WebContents* web_contents, 232 content::WebContents* web_contents,
228 const std::string& package_name_or_start_url, 233 const std::string& package_name_or_start_url,
229 AppBannerRapporMetric rappor_metric) { 234 AppBannerRapporMetric rappor_metric) {
230 banners::TrackDismissEvent(banners::DISMISS_EVENT_CLOSE_BUTTON); 235 banners::TrackDismissEvent(banners::DISMISS_EVENT_CLOSE_BUTTON);
231 236
232 AppBannerSettingsHelper::RecordBannerEvent( 237 AppBannerSettingsHelper::RecordBannerEvent(
233 web_contents, web_contents->GetURL(), 238 web_contents, web_contents->GetURL(), package_name_or_start_url,
234 package_name_or_start_url,
235 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, 239 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK,
236 banners::AppBannerDataFetcher::GetCurrentTime()); 240 banners::AppBannerDataFetcher::GetCurrentTime());
237 241
238 rappor::SampleDomainAndRegistryFromGURL( 242 rappor::SampleDomainAndRegistryFromGURL(
239 g_browser_process->rappor_service(), 243 g_browser_process->rappor_service(),
240 (rappor_metric == WEB ? "AppBanner.WebApp.Dismissed" 244 (rappor_metric == WEB ? "AppBanner.WebApp.Dismissed"
241 : "AppBanner.NativeApp.Dismissed"), 245 : "AppBanner.NativeApp.Dismissed"),
242 web_contents->GetURL()); 246 web_contents->GetURL());
243 } 247 }
244 248
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 std::vector<BannerEvent> could_show_events = GetCouldShowBannerEvents( 533 std::vector<BannerEvent> could_show_events = GetCouldShowBannerEvents(
530 web_contents, origin_url, package_name_or_start_url); 534 web_contents, origin_url, package_name_or_start_url);
531 535
532 int minutes = 0; 536 int minutes = 0;
533 if (could_show_events.size()) 537 if (could_show_events.size())
534 minutes = (time - could_show_events[0].time).InMinutes(); 538 minutes = (time - could_show_events[0].time).InMinutes();
535 539
536 banners::TrackMinutesFromFirstVisitToBannerShown(minutes); 540 banners::TrackMinutesFromFirstVisitToBannerShown(minutes);
537 } 541 }
538 542
543 bool AppBannerSettingsHelper::WasLaunchedRecently(
544 content::WebContents* web_contents,
545 const GURL& origin_url,
546 base::Time now) {
547 Profile* profile =
548 Profile::FromBrowserContext(web_contents->GetBrowserContext());
549 HostContentSettingsMap* settings =
550 HostContentSettingsMapFactory::GetForProfile(profile);
551 std::unique_ptr<base::DictionaryValue> origin_dict =
552 GetOriginDict(settings, origin_url);
553
554 if (!origin_dict)
555 return false;
556
557 // Iterate over everything in the content setting, which should be a set of
558 // dictionaries per app path. If we find one that has been added to
559 // homescreen recently, return true.
560 for (base::DictionaryValue::Iterator it(*origin_dict); !it.IsAtEnd();
561 it.Advance()) {
562 if (it.value().IsType(base::Value::TYPE_DICTIONARY)) {
563 const base::DictionaryValue* value;
564 it.value().GetAsDictionary(&value);
565
566 std::string event_key(
567 kBannerEventKeys[APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN]);
568 double internal_time;
569 if (!value->GetDouble(event_key, &internal_time))
570 continue;
571
572 base::Time added_time = base::Time::FromInternalValue(internal_time);
573 base::TimeDelta delta = now - added_time;
574
575 // Ensure that the delta isn't negative (i.e. the user has reset their
576 // clock backwards) and that it's within kRecentLastLaunchInDays.
577 if (delta >= base::TimeDelta() &&
benwells 2016/07/28 07:47:01 Optional nit: maybe we shouldn't test for a negati
dominickn 2016/07/29 00:34:08 Done.
578 delta <= base::TimeDelta::FromDays(kRecentLastLaunchInDays)) {
579 return true;
580 }
581 }
582 }
583
584 return false;
585 }
586
539 void AppBannerSettingsHelper::SetEngagementWeights(double direct_engagement, 587 void AppBannerSettingsHelper::SetEngagementWeights(double direct_engagement,
540 double indirect_engagement) { 588 double indirect_engagement) {
541 gDirectNavigationEngagement = direct_engagement; 589 gDirectNavigationEngagement = direct_engagement;
542 gIndirectNavigationEnagagement = indirect_engagement; 590 gIndirectNavigationEnagagement = indirect_engagement;
543 } 591 }
544 592
545 void AppBannerSettingsHelper::SetMinimumMinutesBetweenVisits( 593 void AppBannerSettingsHelper::SetMinimumMinutesBetweenVisits(
546 unsigned int minutes) { 594 unsigned int minutes) {
547 gMinimumMinutesBetweenVisits = minutes; 595 gMinimumMinutesBetweenVisits = minutes;
548 } 596 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 return true; 650 return true;
603 } 651 }
604 652
605 // Assume any value which is not "0" or "false" indicates that we should use 653 // Assume any value which is not "0" or "false" indicates that we should use
606 // site engagement. 654 // site engagement.
607 std::string param = variations::GetVariationParamValue( 655 std::string param = variations::GetVariationParamValue(
608 kBannerParamsKey, kBannerSiteEngagementParamsKey); 656 kBannerParamsKey, kBannerSiteEngagementParamsKey);
609 657
610 return (!param.empty() && param != "0" && param != "false"); 658 return (!param.empty() && param != "0" && param != "false");
611 } 659 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698