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 <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" | |
13 #include "chrome/browser/banners/app_banner_data_fetcher.h" | 14 #include "chrome/browser/banners/app_banner_data_fetcher.h" |
14 #include "chrome/browser/banners/app_banner_metrics.h" | 15 #include "chrome/browser/banners/app_banner_metrics.h" |
15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
18 #include "components/content_settings/core/browser/host_content_settings_map.h" | 19 #include "components/content_settings/core/browser/host_content_settings_map.h" |
19 #include "components/content_settings/core/common/content_settings_pattern.h" | 20 #include "components/content_settings/core/common/content_settings_pattern.h" |
20 #include "components/rappor/rappor_utils.h" | 21 #include "components/rappor/rappor_utils.h" |
21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
22 #include "net/base/escape.h" | 23 #include "net/base/escape.h" |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 // midnight with the resulting truncated number added. | 467 // midnight with the resulting truncated number added. |
467 base::Time::Exploded exploded; | 468 base::Time::Exploded exploded; |
468 time.LocalExplode(&exploded); | 469 time.LocalExplode(&exploded); |
469 int total_minutes = exploded.hour * 60 + exploded.minute; | 470 int total_minutes = exploded.hour * 60 + exploded.minute; |
470 | 471 |
471 // Use truncating integer division here. | 472 // Use truncating integer division here. |
472 return time.LocalMidnight() + | 473 return time.LocalMidnight() + |
473 base::TimeDelta::FromMinutes((total_minutes / minutes) * minutes); | 474 base::TimeDelta::FromMinutes((total_minutes / minutes) * minutes); |
474 } | 475 } |
475 | 476 |
477 void AppBannerSettingsHelper::UpdateEngagementWeights() { | |
benwells
2015/08/26 06:50:06
UpdateEngagementWeights and UpdateMinutesBetweenVi
dominickn
2015/08/26 07:04:23
Done.
| |
478 // Expect a field trial value of "X:Y", where X is the direct engagement | |
479 // value and Y is the indirect engagement value. | |
480 std::string weights = | |
481 base::FieldTrialList::FindFullName("AppBannersEngagementWeights"); | |
benwells
2015/08/26 06:50:06
Nit: do you think it is worthwhile adding somethin
dominickn
2015/08/26 07:04:23
Done.
| |
482 std::vector<base::StringPiece> tokens = base::SplitStringPiece( | |
benwells
2015/08/26 06:50:06
Could you just use SplitString? Since you are call
dominickn
2015/08/26 07:04:23
I believe there's a memory advantage to SplitStrin
| |
483 weights, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | |
484 if (tokens.size() == 2) { | |
485 double direct_engagement = -1; | |
486 double indirect_engagement = -1; | |
487 | |
488 // Ensure that we get valid doubles from the field trial, and that both | |
489 // values are greater than or equal to zero and less than or equal to the | |
490 // total engagement required to trigger the banner. | |
491 if (base::StringToDouble(tokens[0].as_string(), &direct_engagement) && | |
492 base::StringToDouble(tokens[1].as_string(), &indirect_engagement) && | |
493 direct_engagement >= 0 && indirect_engagement >= 0 && | |
494 direct_engagement <= kTotalEngagementToTrigger && | |
495 indirect_engagement <= kTotalEngagementToTrigger) { | |
496 SetEngagementWeights(direct_engagement, indirect_engagement); | |
497 } | |
498 } | |
499 } | |
500 | |
476 void AppBannerSettingsHelper::UpdateMinutesBetweenVisits() { | 501 void AppBannerSettingsHelper::UpdateMinutesBetweenVisits() { |
477 std::string minutes_between_visits = | 502 std::string minutes_between_visits = |
478 base::FieldTrialList::FindFullName("AppBannersMinutesBetweenVisits"); | 503 base::FieldTrialList::FindFullName("AppBannersMinutesBetweenVisits"); |
479 int minimum_minutes = 0; | 504 int minimum_minutes = 0; |
480 if (base::StringToInt(minutes_between_visits, &minimum_minutes)) | 505 if (base::StringToInt(minutes_between_visits, &minimum_minutes)) |
481 AppBannerSettingsHelper::SetMinimumMinutesBetweenVisits(minimum_minutes); | 506 SetMinimumMinutesBetweenVisits(minimum_minutes); |
482 } | 507 } |
508 | |
509 void AppBannerSettingsHelper::UpdateFromFieldTrial() { | |
510 UpdateEngagementWeights(); | |
511 UpdateMinutesBetweenVisits(); | |
512 } | |
OLD | NEW |