Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/previews/core/previews_experiments.h" | 5 #include "components/previews/core/previews_experiments.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 | 38 |
| 39 // The amount of time a host remains blacklisted due to opt outs. | 39 // The amount of time a host remains blacklisted due to opt outs. |
| 40 const char kBlackListDurationInDays[] = "black_list_duration_in_days"; | 40 const char kBlackListDurationInDays[] = "black_list_duration_in_days"; |
| 41 | 41 |
| 42 // The string that corresponds to enabled for the variation param experiments. | 42 // The string that corresponds to enabled for the variation param experiments. |
| 43 const char kExperimentEnabled[] = "true"; | 43 const char kExperimentEnabled[] = "true"; |
| 44 | 44 |
| 45 // In seconds. Hosts are blacklisted for 30 days. | 45 // In seconds. Hosts are blacklisted for 30 days. |
| 46 constexpr int kDefaultBlackListDurationInDays = 30; | 46 constexpr int kDefaultBlackListDurationInDays = 30; |
| 47 | 47 |
| 48 // Command line switch to change the previews per row DB size. | |
|
tbansal1
2016/10/28 22:07:14
why is there a need to set this using command line
RyanSturm
2016/11/03 18:30:03
I moved this to previews_opt_out_store_sql.cc
I w
| |
| 49 const char kMaxRowsPerHost[] = "previews-max-opt-out-rows-per-host"; | |
| 50 | |
| 51 // Command line switch to change the previews DB size. | |
| 52 const char kMaxRows[] = "previews-max-opt-out-rows"; | |
| 53 | |
| 54 // The maximum number of entries allowed per host in the SQLite DB. | |
| 55 const int kDefaultMaxRowsPerHost = 32; | |
| 56 | |
| 57 // The maximum number of entries allowed in the SQLite DB. | |
| 58 const int kDefaultMaxRowsInDB = 3200; | |
| 59 | |
| 48 // Returns the parameter value of |param| as a string. If there is no value for | 60 // Returns the parameter value of |param| as a string. If there is no value for |
| 49 // |param|, returns an empty string. | 61 // |param|, returns an empty string. |
| 50 std::string ParamValue(const std::string& param) { | 62 std::string ParamValue(const std::string& param) { |
| 51 if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial()) | 63 if (!IsIncludedInClientSidePreviewsExperimentsFieldTrial()) |
| 52 return std::string(); | 64 return std::string(); |
| 53 std::map<std::string, std::string> experiment_params; | 65 std::map<std::string, std::string> experiment_params; |
| 54 if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial, | 66 if (!variations::GetVariationParams(kClientSidePreviewsFieldTrial, |
| 55 &experiment_params)) { | 67 &experiment_params)) { |
| 56 return std::string(); | 68 return std::string(); |
| 57 } | 69 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 std::string param_value = ParamValue(kBlackListDurationInDays); | 107 std::string param_value = ParamValue(kBlackListDurationInDays); |
| 96 int duration; | 108 int duration; |
| 97 if (!base::StringToInt(param_value, &duration)) { | 109 if (!base::StringToInt(param_value, &duration)) { |
| 98 return base::TimeDelta::FromDays(kDefaultBlackListDurationInDays); | 110 return base::TimeDelta::FromDays(kDefaultBlackListDurationInDays); |
| 99 } | 111 } |
| 100 return base::TimeDelta::FromDays(duration); | 112 return base::TimeDelta::FromDays(duration); |
| 101 } | 113 } |
| 102 | 114 |
| 103 } // namespace params | 115 } // namespace params |
| 104 | 116 |
| 117 int MaxRowsPerHostInOptOutDB() { | |
| 118 std::string max_rows = | |
| 119 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 120 kMaxRowsPerHost); | |
| 121 int value; | |
| 122 return base::StringToInt(max_rows, &value) ? value : kDefaultMaxRowsPerHost; | |
| 123 } | |
| 124 | |
| 125 int MaxRowsInOptOutDB() { | |
| 126 std::string max_rows = | |
| 127 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kMaxRows); | |
| 128 int value; | |
| 129 return base::StringToInt(max_rows, &value) ? value : kDefaultMaxRowsInDB; | |
| 130 } | |
| 131 | |
| 105 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() { | 132 bool IsIncludedInClientSidePreviewsExperimentsFieldTrial() { |
| 106 // By convention, an experiment in the client-side previews study enables use | 133 // By convention, an experiment in the client-side previews study enables use |
| 107 // of at least one client-side previews optimization if its name begins with | 134 // of at least one client-side previews optimization if its name begins with |
| 108 // "Enabled." | 135 // "Enabled." |
| 109 return base::StartsWith( | 136 return base::StartsWith( |
| 110 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial), | 137 base::FieldTrialList::FindFullName(kClientSidePreviewsFieldTrial), |
| 111 kEnabled, base::CompareCase::SENSITIVE); | 138 kEnabled, base::CompareCase::SENSITIVE); |
| 112 } | 139 } |
| 113 | 140 |
| 114 bool IsPreviewsTypeEnabled(PreviewsType type) { | 141 bool IsPreviewsTypeEnabled(PreviewsType type) { |
| 115 switch (type) { | 142 switch (type) { |
| 116 case PreviewsType::OFFLINE: | 143 case PreviewsType::OFFLINE: |
| 117 return ParamValue(kOfflinePagesSlowNetwork) == kExperimentEnabled; | 144 return ParamValue(kOfflinePagesSlowNetwork) == kExperimentEnabled; |
| 118 default: | 145 default: |
| 119 NOTREACHED(); | 146 NOTREACHED(); |
| 120 return false; | 147 return false; |
| 121 } | 148 } |
| 122 } | 149 } |
| 123 | 150 |
| 124 bool EnableOfflinePreviewsForTesting() { | 151 bool EnableOfflinePreviewsForTesting() { |
| 125 std::map<std::string, std::string> params; | 152 std::map<std::string, std::string> params; |
| 126 params[kOfflinePagesSlowNetwork] = kExperimentEnabled; | 153 params[kOfflinePagesSlowNetwork] = kExperimentEnabled; |
| 127 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial, | 154 return variations::AssociateVariationParams(kClientSidePreviewsFieldTrial, |
| 128 kEnabled, params) && | 155 kEnabled, params) && |
| 129 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial, | 156 base::FieldTrialList::CreateFieldTrial(kClientSidePreviewsFieldTrial, |
| 130 kEnabled); | 157 kEnabled); |
| 131 } | 158 } |
| 132 | 159 |
| 133 } // namespace previews | 160 } // namespace previews |
| OLD | NEW |