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 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 if (cur_completing_job_) | 747 if (cur_completing_job_) |
748 cur_completing_job_->Cancel(); | 748 cur_completing_job_->Cancel(); |
749 | 749 |
750 NetworkChangeNotifier::RemoveObserver(this); | 750 NetworkChangeNotifier::RemoveObserver(this); |
751 | 751 |
752 // Delete the job pools. | 752 // Delete the job pools. |
753 for (size_t i = 0u; i < arraysize(job_pools_); ++i) | 753 for (size_t i = 0u; i < arraysize(job_pools_); ++i) |
754 delete job_pools_[i]; | 754 delete job_pools_[i]; |
755 } | 755 } |
756 | 756 |
| 757 // TODO(eroman): Don't create cache entries for hostnames which are simply IP |
| 758 // address literals. |
757 int HostResolverImpl::Resolve(const RequestInfo& info, | 759 int HostResolverImpl::Resolve(const RequestInfo& info, |
758 AddressList* addresses, | 760 AddressList* addresses, |
759 CompletionCallback* callback, | 761 CompletionCallback* callback, |
760 RequestHandle* out_req, | 762 RequestHandle* out_req, |
761 const BoundNetLog& net_log) { | 763 const BoundNetLog& net_log) { |
762 DCHECK(CalledOnValidThread()); | 764 DCHECK(CalledOnValidThread()); |
763 | 765 |
764 if (shutdown_) | 766 if (shutdown_) |
765 return ERR_UNEXPECTED; | 767 return ERR_UNEXPECTED; |
766 | 768 |
767 // Choose a unique ID number for observers to see. | 769 // Choose a unique ID number for observers to see. |
768 int request_id = next_request_id_++; | 770 int request_id = next_request_id_++; |
769 | 771 |
770 // Update the net log and notify registered observers. | 772 // Update the net log and notify registered observers. |
771 OnStartRequest(net_log, request_id, info); | 773 OnStartRequest(net_log, request_id, info); |
772 | 774 |
773 // Check for IP literal. | |
774 IPAddressNumber ip_number; | |
775 if (ParseIPLiteralToNumber(info.hostname(), &ip_number)) { | |
776 DCHECK_EQ((info.host_resolver_flags() & | |
777 ~(HOST_RESOLVER_CANONNAME | HOST_RESOLVER_LOOPBACK_ONLY)), 0) | |
778 << " Unhandled flag"; | |
779 AddressList result(ip_number, info.port(), | |
780 (info.host_resolver_flags() & HOST_RESOLVER_CANONNAME)); | |
781 | |
782 *addresses = result; | |
783 // Update the net log and notify registered observers. | |
784 OnFinishRequest(net_log, request_id, info, OK, | |
785 0, /* os_error (unknown since from cache) */ | |
786 false /* was_from_cache */); | |
787 return OK; | |
788 } | |
789 | |
790 // Build a key that identifies the request in the cache and in the | 775 // Build a key that identifies the request in the cache and in the |
791 // outstanding jobs map. | 776 // outstanding jobs map. |
792 Key key = GetEffectiveKeyForRequest(info); | 777 Key key = GetEffectiveKeyForRequest(info); |
793 | 778 |
794 // If we have an unexpired cache entry, use it. | 779 // If we have an unexpired cache entry, use it. |
795 if (info.allow_cached_response() && cache_.get()) { | 780 if (info.allow_cached_response() && cache_.get()) { |
796 const HostCache::Entry* cache_entry = cache_->Lookup( | 781 const HostCache::Entry* cache_entry = cache_->Lookup( |
797 key, base::TimeTicks::Now()); | 782 key, base::TimeTicks::Now()); |
798 if (cache_entry) { | 783 if (cache_entry) { |
799 int net_error = cache_entry->error; | 784 int net_error = cache_entry->error; |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 if (r == req) | 1168 if (r == req) |
1184 return error; | 1169 return error; |
1185 | 1170 |
1186 r->OnComplete(error, AddressList()); | 1171 r->OnComplete(error, AddressList()); |
1187 } | 1172 } |
1188 | 1173 |
1189 return ERR_IO_PENDING; | 1174 return ERR_IO_PENDING; |
1190 } | 1175 } |
1191 | 1176 |
1192 } // namespace net | 1177 } // namespace net |
OLD | NEW |