| 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, |
| 164 base::TimeDelta* out) { |
| 165 std::string group = base::FieldTrialList::FindFullName(field_trial); |
| 166 if (group.empty()) |
| 167 return false; |
| 168 std::vector<base::StringPiece> group_parts = base::SplitStringPiece( |
| 169 group, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 170 if (type < 0) |
| 171 return false; |
| 172 size_t type_size = static_cast<size_t>(type); |
| 173 if (type_size >= group_parts.size()) |
| 174 return false; |
| 175 int64_t ms; |
| 176 if (!base::StringToInt64(group_parts[type_size], &ms)) |
| 177 return false; |
| 178 *out = base::TimeDelta::FromMilliseconds(ms); |
| 179 return true; |
| 180 } |
| 181 |
| 182 } // namespace |
| 183 |
| 184 base::TimeDelta GetTimeDeltaForConnectionTypeFromFieldTrialOrDefault( |
| 185 const char* field_trial, |
| 186 base::TimeDelta default_delta, |
| 187 NetworkChangeNotifier::ConnectionType type) { |
| 188 base::TimeDelta out; |
| 189 if (!GetTimeDeltaForConnectionTypeFromFieldTrial(field_trial, type, &out)) |
| 190 out = default_delta; |
| 191 return out; |
| 192 } |
| 193 #endif // !defined(OS_NACL) |
| 194 |
| 155 } // namespace net | 195 } // namespace net |
| OLD | NEW |