Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1023)

Side by Side Diff: net/base/host_resolver_impl.cc

Issue 1593015: HostResolver supports optional CNAME lookups. (Closed)
Patch Set: Addressing wtc's nits. Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2006-2008 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 #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
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,
63 AddressList* out) { 64 AddressList* out) {
64 if (resolver_proc) { 65 if (resolver_proc) {
65 // Use the custom procedure. 66 // Use the custom procedure.
66 return resolver_proc->Resolve(host, address_family, out); 67 return resolver_proc->Resolve(host, address_family,
68 host_resolver_flags, out);
67 } else { 69 } else {
68 // Use the system procedure (getaddrinfo). 70 // Use the system procedure (getaddrinfo).
69 return SystemHostResolverProc(host, address_family, out); 71 return SystemHostResolverProc(host, address_family,
72 host_resolver_flags, out);
70 } 73 }
71 } 74 }
72 75
73 //----------------------------------------------------------------------------- 76 //-----------------------------------------------------------------------------
74 77
75 class HostResolverImpl::Request { 78 class HostResolverImpl::Request {
76 public: 79 public:
77 Request(const BoundNetLog& net_log, 80 Request(const BoundNetLog& net_log,
78 int id, 81 int id,
79 const RequestInfo& info, 82 const RequestInfo& info,
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 void DoLookup() { 319 void DoLookup() {
317 if (requests_trace_) { 320 if (requests_trace_) {
318 requests_trace_->Add(StringPrintf( 321 requests_trace_->Add(StringPrintf(
319 "[resolver thread] Running job j%d", id_)); 322 "[resolver thread] Running job j%d", id_));
320 } 323 }
321 324
322 // Running on the worker thread 325 // Running on the worker thread
323 error_ = ResolveAddrInfo(resolver_proc_, 326 error_ = ResolveAddrInfo(resolver_proc_,
324 key_.hostname, 327 key_.hostname,
325 key_.address_family, 328 key_.address_family,
329 key_.host_resolver_flags,
326 &results_); 330 &results_);
327 331
328 if (requests_trace_) { 332 if (requests_trace_) {
329 requests_trace_->Add(StringPrintf( 333 requests_trace_->Add(StringPrintf(
330 "[resolver thread] Completed job j%d", id_)); 334 "[resolver thread] Completed job j%d", id_));
331 } 335 }
332 336
333 Task* reply = NewRunnableMethod(this, &Job::OnLookupComplete); 337 Task* reply = NewRunnableMethod(this, &Job::OnLookupComplete);
334 338
335 // The origin loop could go away while we are trying to post to it, so we 339 // 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
736 OnFinishRequest(net_log, request_id, info, error); 740 OnFinishRequest(net_log, request_id, info, error);
737 741
738 return error; 742 return error;
739 } 743 }
740 } 744 }
741 745
742 // If no callback was specified, do a synchronous resolution. 746 // If no callback was specified, do a synchronous resolution.
743 if (!callback) { 747 if (!callback) {
744 AddressList addrlist; 748 AddressList addrlist;
745 int error = ResolveAddrInfo( 749 int error = ResolveAddrInfo(
746 effective_resolver_proc(), key.hostname, key.address_family, &addrlist); 750 effective_resolver_proc(), key.hostname, key.address_family,
751 key.host_resolver_flags, &addrlist);
747 if (error == OK) { 752 if (error == OK) {
748 addrlist.SetPort(info.port()); 753 addrlist.SetPort(info.port());
749 *addresses = addrlist; 754 *addresses = addrlist;
750 } 755 }
751 756
752 // Write to cache. 757 // Write to cache.
753 if (cache_.get()) 758 if (cache_.get())
754 cache_->Set(key, error, addrlist, base::TimeTicks::Now()); 759 cache_->Set(key, error, addrlist, base::TimeTicks::Now());
755 760
756 // Update the net log and notify registered observers. 761 // Update the net log and notify registered observers.
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 JobPool* pool = job_pools_[pool_i]; 1149 JobPool* pool = job_pools_[pool_i];
1145 pool->MoveRequestsToJob(job); 1150 pool->MoveRequestsToJob(job);
1146 } 1151 }
1147 } 1152 }
1148 1153
1149 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( 1154 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest(
1150 const RequestInfo& info) const { 1155 const RequestInfo& info) const {
1151 AddressFamily effective_address_family = info.address_family(); 1156 AddressFamily effective_address_family = info.address_family();
1152 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED) 1157 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED)
1153 effective_address_family = default_address_family_; 1158 effective_address_family = default_address_family_;
1154 return Key(info.hostname(), effective_address_family); 1159 return Key(info.hostname(), effective_address_family,
1160 info.host_resolver_flags());
1155 } 1161 }
1156 1162
1157 HostResolverImpl::Job* HostResolverImpl::CreateAndStartJob(Request* req) { 1163 HostResolverImpl::Job* HostResolverImpl::CreateAndStartJob(Request* req) {
1158 DCHECK(CanCreateJobForPool(*GetPoolForRequest(req))); 1164 DCHECK(CanCreateJobForPool(*GetPoolForRequest(req)));
1159 Key key = GetEffectiveKeyForRequest(req->info()); 1165 Key key = GetEffectiveKeyForRequest(req->info());
1160 scoped_refptr<Job> job = new Job(next_job_id_++, this, key, requests_trace_); 1166 scoped_refptr<Job> job = new Job(next_job_id_++, this, key, requests_trace_);
1161 job->AddRequest(req); 1167 job->AddRequest(req);
1162 AddOutstandingJob(job); 1168 AddOutstandingJob(job);
1163 job->Start(); 1169 job->Start();
1164 return job.get(); 1170 return job.get();
(...skipping 19 matching lines...) Expand all
1184 if (r == req) 1190 if (r == req)
1185 return error; 1191 return error;
1186 1192
1187 r->OnComplete(error, AddressList()); 1193 r->OnComplete(error, AddressList());
1188 } 1194 }
1189 1195
1190 return ERR_IO_PENDING; 1196 return ERR_IO_PENDING;
1191 } 1197 }
1192 1198
1193 } // namespace net 1199 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698