Chromium Code Reviews| Index: net/dns/dns_util.cc |
| diff --git a/net/dns/dns_util.cc b/net/dns/dns_util.cc |
| index d2897ff2ae0438dac06ec2e7b810ab1266c4cc83..c6b188d29305574b11b859406a7ef138885c2e86 100644 |
| --- a/net/dns/dns_util.cc |
| +++ b/net/dns/dns_util.cc |
| @@ -9,6 +9,9 @@ |
| #include <cstring> |
| +#include "base/metrics/field_trial.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/strings/string_split.h" |
| #include "build/build_config.h" |
| #if defined(OS_POSIX) |
| @@ -152,4 +155,39 @@ bool HaveOnlyLoopbackAddresses() { |
| #endif // defined(various platforms) |
| } |
| +#if !defined(OS_NACL) |
| +namespace { |
| + |
| +bool GetTimeDeltaForConnectionTypeFromFieldTrial( |
| + const char* field_trial, |
| + NetworkChangeNotifier::ConnectionType type_int, |
|
Randy Smith (Not in Mondays)
2016/03/15 20:12:30
I mildly object to the naming; other variables of
Deprecated (see juliatuttle)
2016/03/16 16:45:30
Done.
|
| + base::TimeDelta* out) { |
| + std::string group = base::FieldTrialList::FindFullName(field_trial); |
| + std::vector<base::StringPiece> group_parts = base::SplitStringPiece( |
| + group, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| + if (type_int < 0) |
| + return false; |
| + size_t type = static_cast<size_t>(type_int); |
| + if (type >= group_parts.size()) |
| + return false; |
|
Randy Smith (Not in Mondays)
2016/03/15 20:12:30
Will this catch the case when the field trial isn'
Deprecated (see juliatuttle)
2016/03/16 16:45:30
Technically, I think StringToInt64 would then fail
|
| + int64_t ms; |
| + if (!base::StringToInt64(group_parts[type], &ms)) |
| + return false; |
| + *out = base::TimeDelta::FromMilliseconds(ms); |
| + return true; |
| +} |
| + |
| +} // namespace |
| + |
| +base::TimeDelta GetTimeDeltaForConnectionTypeFromFieldTrialOrDefault( |
| + const char* field_trial, |
| + base::TimeDelta default_delta, |
| + NetworkChangeNotifier::ConnectionType type) { |
| + base::TimeDelta out; |
| + if (!GetTimeDeltaForConnectionTypeFromFieldTrial(field_trial, type, &out)) |
| + out = default_delta; |
| + return out; |
| +} |
| +#endif // !defined(OS_NACL) |
| + |
| } // namespace net |