OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/base/host_resolver_impl.h" | 5 #include "net/base/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 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 // Choose a unique ID number for observers to see. | 868 // Choose a unique ID number for observers to see. |
869 int request_id = next_request_id_++; | 869 int request_id = next_request_id_++; |
870 | 870 |
871 // Make a log item for the request. | 871 // Make a log item for the request. |
872 BoundNetLog request_net_log = BoundNetLog::Make(net_log_, | 872 BoundNetLog request_net_log = BoundNetLog::Make(net_log_, |
873 NetLog::SOURCE_HOST_RESOLVER_IMPL_REQUEST); | 873 NetLog::SOURCE_HOST_RESOLVER_IMPL_REQUEST); |
874 | 874 |
875 // Update the net log and notify registered observers. | 875 // Update the net log and notify registered observers. |
876 OnStartRequest(source_net_log, request_net_log, request_id, info); | 876 OnStartRequest(source_net_log, request_net_log, request_id, info); |
877 | 877 |
878 // Check for IP literal. | |
879 IPAddressNumber ip_number; | |
880 if (ParseIPLiteralToNumber(info.hostname(), &ip_number)) { | |
881 DCHECK_EQ((info.host_resolver_flags() & | |
882 ~(HOST_RESOLVER_CANONNAME | HOST_RESOLVER_LOOPBACK_ONLY)), 0) | |
883 << " Unhandled flag"; | |
884 AddressList result(ip_number, info.port(), | |
885 (info.host_resolver_flags() & HOST_RESOLVER_CANONNAME)); | |
886 | |
887 *addresses = result; | |
888 // Update the net log and notify registered observers. | |
889 OnFinishRequest(source_net_log, request_net_log, request_id, info, OK, | |
890 0 /* os_error (unknown since from cache) */); | |
891 return OK; | |
892 } | |
893 | |
894 // Build a key that identifies the request in the cache and in the | 878 // Build a key that identifies the request in the cache and in the |
895 // outstanding jobs map. | 879 // outstanding jobs map. |
896 Key key = GetEffectiveKeyForRequest(info); | 880 Key key = GetEffectiveKeyForRequest(info); |
897 | 881 |
882 // Check for IP literal. | |
883 IPAddressNumber ip_number; | |
884 if (ParseIPLiteralToNumber(info.hostname(), &ip_number)) { | |
885 DCHECK_EQ(key.host_resolver_flags & | |
886 ~(HOST_RESOLVER_CANONNAME | HOST_RESOLVER_LOOPBACK_ONLY | | |
887 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6), | |
888 0) << " Unhandled flag"; | |
889 bool ipv6_disabled = default_address_family_ == ADDRESS_FAMILY_IPV4 && | |
890 !ipv6_probe_monitoring_; | |
891 int net_error = OK; | |
892 if (ip_number.size() == 16 && ipv6_disabled) { | |
893 net_error = ERR_NAME_NOT_RESOLVED; | |
willchan no longer on Chromium
2010/09/03 19:36:50
This strikes me as a weird error to return, since
| |
894 } else { | |
895 AddressList result(ip_number, info.port(), | |
896 (key.host_resolver_flags & HOST_RESOLVER_CANONNAME)); | |
897 *addresses = result; | |
898 } | |
899 // Update the net log and notify registered observers. | |
900 OnFinishRequest(source_net_log, request_net_log, request_id, info, | |
901 net_error, 0 /* os_error (unknown since from cache) */); | |
902 return net_error; | |
903 } | |
904 | |
898 // If we have an unexpired cache entry, use it. | 905 // If we have an unexpired cache entry, use it. |
899 if (info.allow_cached_response() && cache_.get()) { | 906 if (info.allow_cached_response() && cache_.get()) { |
900 const HostCache::Entry* cache_entry = cache_->Lookup( | 907 const HostCache::Entry* cache_entry = cache_->Lookup( |
901 key, base::TimeTicks::Now()); | 908 key, base::TimeTicks::Now()); |
902 if (cache_entry) { | 909 if (cache_entry) { |
903 request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CACHE_HIT, NULL); | 910 request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CACHE_HIT, NULL); |
904 int net_error = cache_entry->error; | 911 int net_error = cache_entry->error; |
905 if (net_error == OK) | 912 if (net_error == OK) |
906 addresses->SetFrom(cache_entry->addrlist, info.port()); | 913 addresses->SetFrom(cache_entry->addrlist, info.port()); |
907 | 914 |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1278 | 1285 |
1279 // Search for any other pending request which can piggy-back off this job. | 1286 // Search for any other pending request which can piggy-back off this job. |
1280 for (size_t pool_i = 0; pool_i < POOL_COUNT; ++pool_i) { | 1287 for (size_t pool_i = 0; pool_i < POOL_COUNT; ++pool_i) { |
1281 JobPool* pool = job_pools_[pool_i]; | 1288 JobPool* pool = job_pools_[pool_i]; |
1282 pool->MoveRequestsToJob(job); | 1289 pool->MoveRequestsToJob(job); |
1283 } | 1290 } |
1284 } | 1291 } |
1285 | 1292 |
1286 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( | 1293 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( |
1287 const RequestInfo& info) const { | 1294 const RequestInfo& info) const { |
1295 HostResolverFlags effective_flags = | |
1296 info.host_resolver_flags() | additional_resolver_flags_; | |
1288 AddressFamily effective_address_family = info.address_family(); | 1297 AddressFamily effective_address_family = info.address_family(); |
1289 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED) | 1298 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED && |
1299 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED) { | |
1290 effective_address_family = default_address_family_; | 1300 effective_address_family = default_address_family_; |
1291 return Key(info.hostname(), effective_address_family, | 1301 if (ipv6_probe_monitoring_) |
1292 info.host_resolver_flags() | additional_resolver_flags_); | 1302 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; |
1303 } | |
1304 return Key(info.hostname(), effective_address_family, effective_flags); | |
1293 } | 1305 } |
1294 | 1306 |
1295 HostResolverImpl::Job* HostResolverImpl::CreateAndStartJob(Request* req) { | 1307 HostResolverImpl::Job* HostResolverImpl::CreateAndStartJob(Request* req) { |
1296 DCHECK(CanCreateJobForPool(*GetPoolForRequest(req))); | 1308 DCHECK(CanCreateJobForPool(*GetPoolForRequest(req))); |
1297 Key key = GetEffectiveKeyForRequest(req->info()); | 1309 Key key = GetEffectiveKeyForRequest(req->info()); |
1298 | 1310 |
1299 req->request_net_log().AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB, | 1311 req->request_net_log().AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB, |
1300 NULL); | 1312 NULL); |
1301 | 1313 |
1302 scoped_refptr<Job> job = new Job(next_job_id_++, this, key, | 1314 scoped_refptr<Job> job = new Job(next_job_id_++, this, key, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1340 void HostResolverImpl::AbortAllJobs() { | 1352 void HostResolverImpl::AbortAllJobs() { |
1341 JobMap jobs; | 1353 JobMap jobs; |
1342 jobs.swap(jobs_); | 1354 jobs.swap(jobs_); |
1343 for (JobMap::iterator it = jobs.begin(); it != jobs.end(); ++it) { | 1355 for (JobMap::iterator it = jobs.begin(); it != jobs.end(); ++it) { |
1344 AbortJob(it->second); | 1356 AbortJob(it->second); |
1345 it->second->Cancel(); | 1357 it->second->Cancel(); |
1346 } | 1358 } |
1347 } | 1359 } |
1348 | 1360 |
1349 } // namespace net | 1361 } // namespace net |
OLD | NEW |