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

Unified Diff: net/dns/dns_util.cc

Issue 1778933002: DNS: Per-network-type and Finch-variable timeouts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix NaCl build issue? Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698