Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/host_resolver_impl.h" | 5 #include "net/dns/host_resolver_impl.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <Winsock2.h> | 8 #include <Winsock2.h> |
| 9 #elif defined(OS_POSIX) | 9 #elif defined(OS_POSIX) |
| 10 #include <netdb.h> | 10 #include <netdb.h> |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 | 65 |
| 66 // Default TTL for successful resolutions with ProcTask. | 66 // Default TTL for successful resolutions with ProcTask. |
| 67 const unsigned kCacheEntryTTLSeconds = 60; | 67 const unsigned kCacheEntryTTLSeconds = 60; |
| 68 | 68 |
| 69 // Default TTL for unsuccessful resolutions with ProcTask. | 69 // Default TTL for unsuccessful resolutions with ProcTask. |
| 70 const unsigned kNegativeCacheEntryTTLSeconds = 0; | 70 const unsigned kNegativeCacheEntryTTLSeconds = 0; |
| 71 | 71 |
| 72 // Minimum TTL for successful resolutions with DnsTask. | 72 // Minimum TTL for successful resolutions with DnsTask. |
| 73 const unsigned kMinimumTTLSeconds = kCacheEntryTTLSeconds; | 73 const unsigned kMinimumTTLSeconds = kCacheEntryTTLSeconds; |
| 74 | 74 |
| 75 const char kLocalhost[] = "localhost."; | |
| 76 | |
| 75 // We use a separate histogram name for each platform to facilitate the | 77 // We use a separate histogram name for each platform to facilitate the |
| 76 // display of error codes by their symbolic name (since each platform has | 78 // display of error codes by their symbolic name (since each platform has |
| 77 // different mappings). | 79 // different mappings). |
| 78 const char kOSErrorsForGetAddrinfoHistogramName[] = | 80 const char kOSErrorsForGetAddrinfoHistogramName[] = |
| 79 #if defined(OS_WIN) | 81 #if defined(OS_WIN) |
| 80 "Net.OSErrorsForGetAddrinfo_Win"; | 82 "Net.OSErrorsForGetAddrinfo_Win"; |
| 81 #elif defined(OS_MACOSX) | 83 #elif defined(OS_MACOSX) |
| 82 "Net.OSErrorsForGetAddrinfo_Mac"; | 84 "Net.OSErrorsForGetAddrinfo_Mac"; |
| 83 #elif defined(OS_LINUX) | 85 #elif defined(OS_LINUX) |
| 84 "Net.OSErrorsForGetAddrinfo_Linux"; | 86 "Net.OSErrorsForGetAddrinfo_Linux"; |
| (...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1262 // The dispatcher could have started |this| in the above call to Add, which | 1264 // The dispatcher could have started |this| in the above call to Add, which |
| 1263 // could have called Schedule again. In that case |handle| will be null, | 1265 // could have called Schedule again. In that case |handle| will be null, |
| 1264 // but |handle_| may have been set by the other nested call to Schedule. | 1266 // but |handle_| may have been set by the other nested call to Schedule. |
| 1265 if (!handle.is_null()) { | 1267 if (!handle.is_null()) { |
| 1266 DCHECK(handle_.is_null()); | 1268 DCHECK(handle_.is_null()); |
| 1267 handle_ = handle; | 1269 handle_ = handle; |
| 1268 } | 1270 } |
| 1269 } | 1271 } |
| 1270 | 1272 |
| 1271 void AddRequest(scoped_ptr<Request> req) { | 1273 void AddRequest(scoped_ptr<Request> req) { |
| 1272 DCHECK_EQ(key_.hostname, req->info().hostname()); | 1274 // .localhost queries are redirected to "localhost." to make sure |
| 1275 // that they are never sent out on the network, per RFC 6761. | |
| 1276 if (IsLocalhostTLD(req->info().hostname())) { | |
| 1277 DCHECK_EQ(key_.hostname, kLocalhost); | |
| 1278 } else { | |
| 1279 DCHECK_EQ(key_.hostname, req->info().hostname()); | |
| 1280 } | |
| 1273 | 1281 |
| 1274 req->set_job(this); | 1282 req->set_job(this); |
| 1275 priority_tracker_.Add(req->priority()); | 1283 priority_tracker_.Add(req->priority()); |
| 1276 | 1284 |
| 1277 req->source_net_log().AddEvent( | 1285 req->source_net_log().AddEvent( |
| 1278 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH, | 1286 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH, |
| 1279 net_log_.source().ToEventParametersCallback()); | 1287 net_log_.source().ToEventParametersCallback()); |
| 1280 | 1288 |
| 1281 net_log_.AddEvent( | 1289 net_log_.AddEvent( |
| 1282 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_ATTACH, | 1290 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_ATTACH, |
| (...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2185 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED); | 2193 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED); |
| 2186 | 2194 |
| 2187 effective_address_family = ADDRESS_FAMILY_IPV4; | 2195 effective_address_family = ADDRESS_FAMILY_IPV4; |
| 2188 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; | 2196 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; |
| 2189 } | 2197 } |
| 2190 } else { | 2198 } else { |
| 2191 effective_address_family = default_address_family_; | 2199 effective_address_family = default_address_family_; |
| 2192 } | 2200 } |
| 2193 } | 2201 } |
| 2194 | 2202 |
| 2195 return Key(info.hostname(), effective_address_family, effective_flags); | 2203 std::string hostname = info.hostname(); |
| 2204 // Redirect .localhost queries to "localhost." to make sure that they | |
| 2205 // are never sent out on the network, per RFC 6761. | |
| 2206 if (IsLocalhostTLD(info.hostname())) { | |
|
Ryan Sleevi
2015/02/27 03:21:10
no braces around single-line conditionals in //net
estark
2015/02/27 05:00:47
Done.
| |
| 2207 hostname = kLocalhost; | |
| 2208 } | |
| 2209 | |
| 2210 return Key(hostname, effective_address_family, effective_flags); | |
| 2196 } | 2211 } |
| 2197 | 2212 |
| 2198 void HostResolverImpl::AbortAllInProgressJobs() { | 2213 void HostResolverImpl::AbortAllInProgressJobs() { |
| 2199 // In Abort, a Request callback could spawn new Jobs with matching keys, so | 2214 // In Abort, a Request callback could spawn new Jobs with matching keys, so |
| 2200 // first collect and remove all running jobs from |jobs_|. | 2215 // first collect and remove all running jobs from |jobs_|. |
| 2201 ScopedVector<Job> jobs_to_abort; | 2216 ScopedVector<Job> jobs_to_abort; |
| 2202 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ) { | 2217 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ) { |
| 2203 Job* job = it->second; | 2218 Job* job = it->second; |
| 2204 if (job->is_running()) { | 2219 if (job->is_running()) { |
| 2205 jobs_to_abort.push_back(job); | 2220 jobs_to_abort.push_back(job); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2363 dns_client_->SetConfig(dns_config); | 2378 dns_client_->SetConfig(dns_config); |
| 2364 num_dns_failures_ = 0; | 2379 num_dns_failures_ = 0; |
| 2365 if (dns_client_->GetConfig()) | 2380 if (dns_client_->GetConfig()) |
| 2366 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2381 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
| 2367 } | 2382 } |
| 2368 | 2383 |
| 2369 AbortDnsTasks(); | 2384 AbortDnsTasks(); |
| 2370 } | 2385 } |
| 2371 | 2386 |
| 2372 } // namespace net | 2387 } // namespace net |
| OLD | NEW |