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/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 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1152 BoundNetLog request_net_log = BoundNetLog::Make(net_log_, | 1152 BoundNetLog request_net_log = BoundNetLog::Make(net_log_, |
| 1153 NetLog::SOURCE_HOST_RESOLVER_IMPL_REQUEST); | 1153 NetLog::SOURCE_HOST_RESOLVER_IMPL_REQUEST); |
| 1154 | 1154 |
| 1155 // Update the net log and notify registered observers. | 1155 // Update the net log and notify registered observers. |
| 1156 OnStartRequest(source_net_log, request_net_log, request_id, info); | 1156 OnStartRequest(source_net_log, request_net_log, request_id, info); |
| 1157 | 1157 |
| 1158 // Build a key that identifies the request in the cache and in the | 1158 // Build a key that identifies the request in the cache and in the |
| 1159 // outstanding jobs map. | 1159 // outstanding jobs map. |
| 1160 Key key = GetEffectiveKeyForRequest(info); | 1160 Key key = GetEffectiveKeyForRequest(info); |
| 1161 | 1161 |
| 1162 int rv = ResolveHelper(request_id, key, info, addresses, | 1162 int rv = ResolveHelper(request_id, key, info, addresses, request_net_log); |
| 1163 source_net_log, request_net_log); | |
| 1164 if (rv != ERR_DNS_CACHE_MISS) { | 1163 if (rv != ERR_DNS_CACHE_MISS) { |
| 1165 OnFinishRequest(source_net_log, request_net_log, request_id, info, | 1164 OnFinishRequest(source_net_log, request_net_log, request_id, info, |
| 1166 rv, | 1165 rv, |
| 1167 0 /* os_error (unknown since from cache) */); | 1166 0 /* os_error (unknown since from cache) */); |
| 1168 return rv; | 1167 return rv; |
| 1169 } | 1168 } |
| 1170 | 1169 |
| 1171 // Create a handle for this request, and pass it back to the user if they | 1170 // Create a handle for this request, and pass it back to the user if they |
| 1172 // asked for it (out_req != NULL). | 1171 // asked for it (out_req != NULL). |
| 1173 Request* req = new Request(source_net_log, request_net_log, request_id, info, | 1172 Request* req = new Request(source_net_log, request_net_log, request_id, info, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1194 } | 1193 } |
| 1195 | 1194 |
| 1196 // Completion happens during OnJobComplete(Job*). | 1195 // Completion happens during OnJobComplete(Job*). |
| 1197 return ERR_IO_PENDING; | 1196 return ERR_IO_PENDING; |
| 1198 } | 1197 } |
| 1199 | 1198 |
| 1200 int HostResolverImpl::ResolveHelper(int request_id, | 1199 int HostResolverImpl::ResolveHelper(int request_id, |
| 1201 const Key& key, | 1200 const Key& key, |
| 1202 const RequestInfo& info, | 1201 const RequestInfo& info, |
| 1203 AddressList* addresses, | 1202 AddressList* addresses, |
| 1204 const BoundNetLog& request_net_log, | 1203 const BoundNetLog& request_net_log) { |
| 1205 const BoundNetLog& source_net_log) { | |
| 1206 // The result of |getaddrinfo| for empty hosts is inconsistent across systems. | 1204 // The result of |getaddrinfo| for empty hosts is inconsistent across systems. |
| 1207 // On Windows it gives the default interface's address, whereas on Linux it | 1205 // On Windows it gives the default interface's address, whereas on Linux it |
| 1208 // gives an error. We will make it fail on all platforms for consistency. | 1206 // gives an error. We will make it fail on all platforms for consistency. |
| 1209 if (info.hostname().empty() || info.hostname().size() > kMaxHostLength) | 1207 if (info.hostname().empty() || info.hostname().size() > kMaxHostLength) |
| 1210 return ERR_NAME_NOT_RESOLVED; | 1208 return ERR_NAME_NOT_RESOLVED; |
| 1211 | 1209 |
| 1212 int net_error = ERR_UNEXPECTED; | 1210 int net_error = ERR_UNEXPECTED; |
| 1213 if (ResolveAsIP(key, info, &net_error, addresses)) | 1211 if (ResolveAsIP(key, info, &net_error, addresses)) |
| 1214 return net_error; | 1212 return net_error; |
| 1215 net_error = ERR_DNS_CACHE_MISS; | 1213 net_error = ERR_DNS_CACHE_MISS; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1230 BoundNetLog request_net_log = BoundNetLog::Make(net_log_, | 1228 BoundNetLog request_net_log = BoundNetLog::Make(net_log_, |
| 1231 NetLog::SOURCE_HOST_RESOLVER_IMPL_REQUEST); | 1229 NetLog::SOURCE_HOST_RESOLVER_IMPL_REQUEST); |
| 1232 | 1230 |
| 1233 // Update the net log and notify registered observers. | 1231 // Update the net log and notify registered observers. |
| 1234 OnStartRequest(source_net_log, request_net_log, request_id, info); | 1232 OnStartRequest(source_net_log, request_net_log, request_id, info); |
| 1235 | 1233 |
| 1236 // Build a key that identifies the request in the cache and in the | 1234 // Build a key that identifies the request in the cache and in the |
| 1237 // outstanding jobs map. | 1235 // outstanding jobs map. |
| 1238 Key key = GetEffectiveKeyForRequest(info); | 1236 Key key = GetEffectiveKeyForRequest(info); |
| 1239 | 1237 |
| 1240 int rv = ResolveHelper(request_id, key, info, addresses, request_net_log, | 1238 int rv = ResolveHelper(request_id, key, info, addresses, request_net_log); |
| 1241 source_net_log); | |
| 1242 OnFinishRequest(source_net_log, request_net_log, request_id, info, | 1239 OnFinishRequest(source_net_log, request_net_log, request_id, info, |
| 1243 rv, | 1240 rv, |
| 1244 0 /* os_error (unknown since from cache) */); | 1241 0 /* os_error (unknown since from cache) */); |
| 1245 return rv; | 1242 return rv; |
| 1246 } | 1243 } |
| 1247 | 1244 |
| 1248 // See OnJobComplete(Job*) for why it is important not to clean out | 1245 // See OnJobComplete(Job*) for why it is important not to clean out |
| 1249 // cancelled requests from Job::requests_. | 1246 // cancelled requests from Job::requests_. |
| 1250 void HostResolverImpl::CancelRequest(RequestHandle req_handle) { | 1247 void HostResolverImpl::CancelRequest(RequestHandle req_handle) { |
| 1251 DCHECK(CalledOnValidThread()); | 1248 DCHECK(CalledOnValidThread()); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1340 DCHECK(addresses); | 1337 DCHECK(addresses); |
| 1341 DCHECK(net_error); | 1338 DCHECK(net_error); |
| 1342 if (!info.allow_cached_response() || !cache_.get()) | 1339 if (!info.allow_cached_response() || !cache_.get()) |
| 1343 return false; | 1340 return false; |
| 1344 | 1341 |
| 1345 const HostCache::Entry* cache_entry = cache_->Lookup( | 1342 const HostCache::Entry* cache_entry = cache_->Lookup( |
| 1346 key, base::TimeTicks::Now()); | 1343 key, base::TimeTicks::Now()); |
| 1347 if (!cache_entry) | 1344 if (!cache_entry) |
| 1348 return false; | 1345 return false; |
| 1349 | 1346 |
| 1350 request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CACHE_HIT, NULL); | 1347 request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CACHE_HIT, NULL); |
|
wtc
2011/10/11 21:24:18
Note that in the original code, Resolve passes sou
wtc
2011/10/11 21:30:09
I forgot to mention that the original code before
| |
| 1351 *net_error = cache_entry->error; | 1348 *net_error = cache_entry->error; |
| 1352 if (*net_error == OK) | 1349 if (*net_error == OK) |
| 1353 *addresses = CreateAddressListUsingPort(cache_entry->addrlist, info.port()); | 1350 *addresses = CreateAddressListUsingPort(cache_entry->addrlist, info.port()); |
| 1354 return true; | 1351 return true; |
| 1355 } | 1352 } |
| 1356 | 1353 |
| 1357 void HostResolverImpl::AddOutstandingJob(Job* job) { | 1354 void HostResolverImpl::AddOutstandingJob(Job* job) { |
| 1358 scoped_refptr<Job>& found_job = jobs_[job->key()]; | 1355 scoped_refptr<Job>& found_job = jobs_[job->key()]; |
| 1359 DCHECK(!found_job); | 1356 DCHECK(!found_job); |
| 1360 found_job = job; | 1357 found_job = job; |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1659 // resolv.conf changes so we don't need to do anything to clear that cache. | 1656 // resolv.conf changes so we don't need to do anything to clear that cache. |
| 1660 if (cache_.get()) | 1657 if (cache_.get()) |
| 1661 cache_->clear(); | 1658 cache_->clear(); |
| 1662 // Existing jobs will have been sent to the original server so they need to | 1659 // Existing jobs will have been sent to the original server so they need to |
| 1663 // be aborted. TODO(Craig): Should these jobs be restarted? | 1660 // be aborted. TODO(Craig): Should these jobs be restarted? |
| 1664 AbortAllInProgressJobs(); | 1661 AbortAllInProgressJobs(); |
| 1665 // |this| may be deleted inside AbortAllInProgressJobs(). | 1662 // |this| may be deleted inside AbortAllInProgressJobs(). |
| 1666 } | 1663 } |
| 1667 | 1664 |
| 1668 } // namespace net | 1665 } // namespace net |
| OLD | NEW |