| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "net/base/net_log.h" | 6 #include "net/base/net_log.h" |
| 7 | 7 |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <deque> | 9 #include <deque> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 HostResolverImpl* resolver = new HostResolverImpl( | 54 HostResolverImpl* resolver = new HostResolverImpl( |
| 55 NULL, CreateDefaultCache(), network_change_notifier, kMaxJobs); | 55 NULL, CreateDefaultCache(), network_change_notifier, kMaxJobs); |
| 56 | 56 |
| 57 return resolver; | 57 return resolver; |
| 58 } | 58 } |
| 59 | 59 |
| 60 static int ResolveAddrInfo(HostResolverProc* resolver_proc, | 60 static int ResolveAddrInfo(HostResolverProc* resolver_proc, |
| 61 const std::string& host, | 61 const std::string& host, |
| 62 AddressFamily address_family, | 62 AddressFamily address_family, |
| 63 HostResolverFlags host_resolver_flags, | |
| 64 AddressList* out) { | 63 AddressList* out) { |
| 65 if (resolver_proc) { | 64 if (resolver_proc) { |
| 66 // Use the custom procedure. | 65 // Use the custom procedure. |
| 67 return resolver_proc->Resolve(host, address_family, | 66 return resolver_proc->Resolve(host, address_family, out); |
| 68 host_resolver_flags, out); | |
| 69 } else { | 67 } else { |
| 70 // Use the system procedure (getaddrinfo). | 68 // Use the system procedure (getaddrinfo). |
| 71 return SystemHostResolverProc(host, address_family, | 69 return SystemHostResolverProc(host, address_family, out); |
| 72 host_resolver_flags, out); | |
| 73 } | 70 } |
| 74 } | 71 } |
| 75 | 72 |
| 76 //----------------------------------------------------------------------------- | 73 //----------------------------------------------------------------------------- |
| 77 | 74 |
| 78 class HostResolverImpl::Request { | 75 class HostResolverImpl::Request { |
| 79 public: | 76 public: |
| 80 Request(const BoundNetLog& net_log, | 77 Request(const BoundNetLog& net_log, |
| 81 int id, | 78 int id, |
| 82 const RequestInfo& info, | 79 const RequestInfo& info, |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 void DoLookup() { | 316 void DoLookup() { |
| 320 if (requests_trace_) { | 317 if (requests_trace_) { |
| 321 requests_trace_->Add(StringPrintf( | 318 requests_trace_->Add(StringPrintf( |
| 322 "[resolver thread] Running job j%d", id_)); | 319 "[resolver thread] Running job j%d", id_)); |
| 323 } | 320 } |
| 324 | 321 |
| 325 // Running on the worker thread | 322 // Running on the worker thread |
| 326 error_ = ResolveAddrInfo(resolver_proc_, | 323 error_ = ResolveAddrInfo(resolver_proc_, |
| 327 key_.hostname, | 324 key_.hostname, |
| 328 key_.address_family, | 325 key_.address_family, |
| 329 key_.host_resolver_flags, | |
| 330 &results_); | 326 &results_); |
| 331 | 327 |
| 332 if (requests_trace_) { | 328 if (requests_trace_) { |
| 333 requests_trace_->Add(StringPrintf( | 329 requests_trace_->Add(StringPrintf( |
| 334 "[resolver thread] Completed job j%d", id_)); | 330 "[resolver thread] Completed job j%d", id_)); |
| 335 } | 331 } |
| 336 | 332 |
| 337 Task* reply = NewRunnableMethod(this, &Job::OnLookupComplete); | 333 Task* reply = NewRunnableMethod(this, &Job::OnLookupComplete); |
| 338 | 334 |
| 339 // The origin loop could go away while we are trying to post to it, so we | 335 // The origin loop could go away while we are trying to post to it, so we |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 OnFinishRequest(net_log, request_id, info, error); | 736 OnFinishRequest(net_log, request_id, info, error); |
| 741 | 737 |
| 742 return error; | 738 return error; |
| 743 } | 739 } |
| 744 } | 740 } |
| 745 | 741 |
| 746 // If no callback was specified, do a synchronous resolution. | 742 // If no callback was specified, do a synchronous resolution. |
| 747 if (!callback) { | 743 if (!callback) { |
| 748 AddressList addrlist; | 744 AddressList addrlist; |
| 749 int error = ResolveAddrInfo( | 745 int error = ResolveAddrInfo( |
| 750 effective_resolver_proc(), key.hostname, key.address_family, | 746 effective_resolver_proc(), key.hostname, key.address_family, &addrlist); |
| 751 key.host_resolver_flags, &addrlist); | |
| 752 if (error == OK) { | 747 if (error == OK) { |
| 753 addrlist.SetPort(info.port()); | 748 addrlist.SetPort(info.port()); |
| 754 *addresses = addrlist; | 749 *addresses = addrlist; |
| 755 } | 750 } |
| 756 | 751 |
| 757 // Write to cache. | 752 // Write to cache. |
| 758 if (cache_.get()) | 753 if (cache_.get()) |
| 759 cache_->Set(key, error, addrlist, base::TimeTicks::Now()); | 754 cache_->Set(key, error, addrlist, base::TimeTicks::Now()); |
| 760 | 755 |
| 761 // Update the net log and notify registered observers. | 756 // Update the net log and notify registered observers. |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 JobPool* pool = job_pools_[pool_i]; | 1144 JobPool* pool = job_pools_[pool_i]; |
| 1150 pool->MoveRequestsToJob(job); | 1145 pool->MoveRequestsToJob(job); |
| 1151 } | 1146 } |
| 1152 } | 1147 } |
| 1153 | 1148 |
| 1154 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( | 1149 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( |
| 1155 const RequestInfo& info) const { | 1150 const RequestInfo& info) const { |
| 1156 AddressFamily effective_address_family = info.address_family(); | 1151 AddressFamily effective_address_family = info.address_family(); |
| 1157 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED) | 1152 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED) |
| 1158 effective_address_family = default_address_family_; | 1153 effective_address_family = default_address_family_; |
| 1159 return Key(info.hostname(), effective_address_family, | 1154 return Key(info.hostname(), effective_address_family); |
| 1160 info.host_resolver_flags()); | |
| 1161 } | 1155 } |
| 1162 | 1156 |
| 1163 HostResolverImpl::Job* HostResolverImpl::CreateAndStartJob(Request* req) { | 1157 HostResolverImpl::Job* HostResolverImpl::CreateAndStartJob(Request* req) { |
| 1164 DCHECK(CanCreateJobForPool(*GetPoolForRequest(req))); | 1158 DCHECK(CanCreateJobForPool(*GetPoolForRequest(req))); |
| 1165 Key key = GetEffectiveKeyForRequest(req->info()); | 1159 Key key = GetEffectiveKeyForRequest(req->info()); |
| 1166 scoped_refptr<Job> job = new Job(next_job_id_++, this, key, requests_trace_); | 1160 scoped_refptr<Job> job = new Job(next_job_id_++, this, key, requests_trace_); |
| 1167 job->AddRequest(req); | 1161 job->AddRequest(req); |
| 1168 AddOutstandingJob(job); | 1162 AddOutstandingJob(job); |
| 1169 job->Start(); | 1163 job->Start(); |
| 1170 return job.get(); | 1164 return job.get(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1190 if (r == req) | 1184 if (r == req) |
| 1191 return error; | 1185 return error; |
| 1192 | 1186 |
| 1193 r->OnComplete(error, AddressList()); | 1187 r->OnComplete(error, AddressList()); |
| 1194 } | 1188 } |
| 1195 | 1189 |
| 1196 return ERR_IO_PENDING; | 1190 return ERR_IO_PENDING; |
| 1197 } | 1191 } |
| 1198 | 1192 |
| 1199 } // namespace net | 1193 } // namespace net |
| OLD | NEW |