Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "net/dns/dns_util.h" | 5 #include "net/dns/dns_util.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 | 9 |
| 10 #include <cstring> | 10 #include <cstring> |
| 11 | 11 |
| 12 #include "base/metrics/field_trial.h" | |
| 13 #include "base/strings/string_number_conversions.h" | |
| 14 #include "base/strings/string_split.h" | |
| 12 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 13 | 16 |
| 14 #if defined(OS_POSIX) | 17 #if defined(OS_POSIX) |
| 15 #include <netinet/in.h> | 18 #include <netinet/in.h> |
| 16 #if !defined(OS_NACL) | 19 #if !defined(OS_NACL) |
| 17 #include <net/if.h> | 20 #include <net/if.h> |
| 18 #if !defined(OS_ANDROID) | 21 #if !defined(OS_ANDROID) |
| 19 #include <ifaddrs.h> | 22 #include <ifaddrs.h> |
| 20 #endif // !defined(OS_ANDROID) | 23 #endif // !defined(OS_ANDROID) |
| 21 #endif // !defined(OS_NACL) | 24 #endif // !defined(OS_NACL) |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 #elif defined(OS_WIN) | 148 #elif defined(OS_WIN) |
| 146 // TODO(wtc): implement with the GetAdaptersAddresses function. | 149 // TODO(wtc): implement with the GetAdaptersAddresses function. |
| 147 NOTIMPLEMENTED(); | 150 NOTIMPLEMENTED(); |
| 148 return false; | 151 return false; |
| 149 #else | 152 #else |
| 150 NOTIMPLEMENTED(); | 153 NOTIMPLEMENTED(); |
| 151 return false; | 154 return false; |
| 152 #endif // defined(various platforms) | 155 #endif // defined(various platforms) |
| 153 } | 156 } |
| 154 | 157 |
| 158 #if !defined(OS_NACL) | |
| 159 namespace { | |
| 160 | |
| 161 bool GetTimeDeltaForConnectionTypeFromFieldTrial( | |
| 162 const char* field_trial, | |
| 163 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.
| |
| 164 base::TimeDelta* out) { | |
| 165 std::string group = base::FieldTrialList::FindFullName(field_trial); | |
| 166 std::vector<base::StringPiece> group_parts = base::SplitStringPiece( | |
| 167 group, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | |
| 168 if (type_int < 0) | |
| 169 return false; | |
| 170 size_t type = static_cast<size_t>(type_int); | |
| 171 if (type >= group_parts.size()) | |
| 172 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
| |
| 173 int64_t ms; | |
| 174 if (!base::StringToInt64(group_parts[type], &ms)) | |
| 175 return false; | |
| 176 *out = base::TimeDelta::FromMilliseconds(ms); | |
| 177 return true; | |
| 178 } | |
| 179 | |
| 180 } // namespace | |
| 181 | |
| 182 base::TimeDelta GetTimeDeltaForConnectionTypeFromFieldTrialOrDefault( | |
| 183 const char* field_trial, | |
| 184 base::TimeDelta default_delta, | |
| 185 NetworkChangeNotifier::ConnectionType type) { | |
| 186 base::TimeDelta out; | |
| 187 if (!GetTimeDeltaForConnectionTypeFromFieldTrial(field_trial, type, &out)) | |
| 188 out = default_delta; | |
| 189 return out; | |
| 190 } | |
| 191 #endif // !defined(OS_NACL) | |
| 192 | |
| 155 } // namespace net | 193 } // namespace net |
| OLD | NEW |