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

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

Issue 1322503002: Revert of Allow direct and indirect navigation values to be varied via field trial. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « chrome/browser/banners/app_banner_settings_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/metrics/field_trial.h" 11 #include "base/metrics/field_trial.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h"
14 #include "chrome/browser/banners/app_banner_data_fetcher.h" 13 #include "chrome/browser/banners/app_banner_data_fetcher.h"
15 #include "chrome/browser/banners/app_banner_metrics.h" 14 #include "chrome/browser/banners/app_banner_metrics.h"
16 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
19 #include "components/content_settings/core/browser/host_content_settings_map.h" 18 #include "components/content_settings/core/browser/host_content_settings_map.h"
20 #include "components/content_settings/core/common/content_settings_pattern.h" 19 #include "components/content_settings/core/common/content_settings_pattern.h"
21 #include "components/rappor/rappor_utils.h" 20 #include "components/rappor/rappor_utils.h"
22 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
23 #include "net/base/escape.h" 22 #include "net/base/escape.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 if (ui::PageTransitionCoreTypeIs(transition_type, 102 if (ui::PageTransitionCoreTypeIs(transition_type,
104 ui::PAGE_TRANSITION_TYPED) || 103 ui::PAGE_TRANSITION_TYPED) ||
105 ui::PageTransitionCoreTypeIs(transition_type, 104 ui::PageTransitionCoreTypeIs(transition_type,
106 ui::PAGE_TRANSITION_GENERATED)) { 105 ui::PAGE_TRANSITION_GENERATED)) {
107 return kDirectNavigationEngagement; 106 return kDirectNavigationEngagement;
108 } else { 107 } else {
109 return kIndirectNavigationEnagagement; 108 return kIndirectNavigationEnagagement;
110 } 109 }
111 } 110 }
112 111
113 // Queries a field trial for updates to the default engagement values assigned
114 // to direct and indirect navigations.
115 void UpdateEngagementWeights() {
116 // Expect a field trial value of "X:Y", where X is the direct engagement
117 // value and Y is the indirect engagement value.
118 std::string weights =
119 base::FieldTrialList::FindFullName("AppBannersEngagementWeights");
120 if (weights.empty())
121 return;
122
123 std::vector<std::string> tokens = base::SplitString(
124 weights, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
125 if (tokens.size() == 2) {
126 double direct_engagement = -1;
127 double indirect_engagement = -1;
128
129 // Ensure that we get valid doubles from the field trial, and that both
130 // values are greater than or equal to zero and less than or equal to the
131 // total engagement required to trigger the banner.
132 if (base::StringToDouble(tokens[0], &direct_engagement) &&
133 base::StringToDouble(tokens[1], &indirect_engagement) &&
134 direct_engagement >= 0 && indirect_engagement >= 0 &&
135 direct_engagement <= kTotalEngagementToTrigger &&
136 indirect_engagement <= kTotalEngagementToTrigger) {
137 AppBannerSettingsHelper::SetEngagementWeights(direct_engagement,
138 indirect_engagement);
139 }
140 }
141 }
142
143 // Queries a field trial for updates to the default number of minutes between
144 // site visits counted for the purposes of displaying a banner.
145 void UpdateMinutesBetweenVisits() {
146 std::string minutes_between_visits =
147 base::FieldTrialList::FindFullName("AppBannersMinutesBetweenVisits");
148 if (minutes_between_visits.empty())
149 return;
150
151 int minimum_minutes = 0;
152 if (base::StringToInt(minutes_between_visits, &minimum_minutes))
153 AppBannerSettingsHelper::SetMinimumMinutesBetweenVisits(minimum_minutes);
154 }
155
156 } // namespace 112 } // namespace
157 113
158 void AppBannerSettingsHelper::ClearHistoryForURLs( 114 void AppBannerSettingsHelper::ClearHistoryForURLs(
159 Profile* profile, 115 Profile* profile,
160 const std::set<GURL>& origin_urls) { 116 const std::set<GURL>& origin_urls) {
161 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); 117 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap();
162 for (const GURL& origin_url : origin_urls) { 118 for (const GURL& origin_url : origin_urls) {
163 ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url)); 119 ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url));
164 if (!pattern.IsValid()) 120 if (!pattern.IsValid())
165 continue; 121 continue;
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 449
494 // Given a time, returns that time scoped to the nearest minute resolution 450 // Given a time, returns that time scoped to the nearest minute resolution
495 // locally. For example, if the resolution is one hour, this function will 451 // locally. For example, if the resolution is one hour, this function will
496 // return the time to the closest (previous) hour in the local time zone. 452 // return the time to the closest (previous) hour in the local time zone.
497 base::Time AppBannerSettingsHelper::BucketTimeToResolution( 453 base::Time AppBannerSettingsHelper::BucketTimeToResolution(
498 base::Time time, 454 base::Time time,
499 unsigned int minutes) { 455 unsigned int minutes) {
500 // Only support resolutions smaller than or equal to one day. Enforce 456 // Only support resolutions smaller than or equal to one day. Enforce
501 // that resolutions divide evenly into one day. Otherwise, default to a 457 // that resolutions divide evenly into one day. Otherwise, default to a
502 // day resolution (each time converted to midnight local time). 458 // day resolution (each time converted to midnight local time).
503 if (minutes == 0 || minutes >= kNumberOfMinutesInADay || 459 if (minutes == 0 || minutes > kNumberOfMinutesInADay ||
504 kNumberOfMinutesInADay % minutes != 0) { 460 kNumberOfMinutesInADay % minutes != 0) {
505 return time.LocalMidnight(); 461 return time.LocalMidnight();
506 } 462 }
507 463
508 // Extract the number of minutes past midnight in local time. Divide that 464 // Extract the number of minutes past midnight in local time. Divide that
509 // number by the resolution size, and return the time converted to local 465 // number by the resolution size, and return the time converted to local
510 // midnight with the resulting truncated number added. 466 // midnight with the resulting truncated number added.
511 base::Time::Exploded exploded; 467 base::Time::Exploded exploded;
512 time.LocalExplode(&exploded); 468 time.LocalExplode(&exploded);
513 int total_minutes = exploded.hour * 60 + exploded.minute; 469 int total_minutes = exploded.hour * 60 + exploded.minute;
514 470
515 // Use truncating integer division here. 471 // Use truncating integer division here.
516 return time.LocalMidnight() + 472 return time.LocalMidnight() +
517 base::TimeDelta::FromMinutes((total_minutes / minutes) * minutes); 473 base::TimeDelta::FromMinutes((total_minutes / minutes) * minutes);
518 } 474 }
519 475
520 void AppBannerSettingsHelper::UpdateFromFieldTrial() { 476 void AppBannerSettingsHelper::UpdateMinutesBetweenVisits() {
521 UpdateEngagementWeights(); 477 std::string minutes_between_visits =
522 UpdateMinutesBetweenVisits(); 478 base::FieldTrialList::FindFullName("AppBannersMinutesBetweenVisits");
479 int minimum_minutes = 0;
480 if (base::StringToInt(minutes_between_visits, &minimum_minutes))
481 AppBannerSettingsHelper::SetMinimumMinutesBetweenVisits(minimum_minutes);
523 } 482 }
OLDNEW
« no previous file with comments | « chrome/browser/banners/app_banner_settings_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698