diff options
Diffstat (limited to 'net/base/host_resolver.cc')
-rw-r--r-- | net/base/host_resolver.cc | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/net/base/host_resolver.cc b/net/base/host_resolver.cc index bf5d3c2..d5d97e7 100644 --- a/net/base/host_resolver.cc +++ b/net/base/host_resolver.cc @@ -28,6 +28,10 @@ namespace net { static HostMapper* host_mapper; +std::string HostMapper::MapUsingPrevious(const std::string& host) { + return previous_mapper_.get() ? previous_mapper_->Map(host) : host; +} + HostMapper* SetHostMapper(HostMapper* value) { std::swap(host_mapper, value); return value; @@ -46,11 +50,11 @@ static int HostResolverProc( return err ? ERR_NAME_NOT_RESOLVED : OK; } -static int ResolveAddrInfo( - const std::string& host, const std::string& port, struct addrinfo** out) { +static int ResolveAddrInfo(HostMapper* mapper, const std::string& host, + const std::string& port, struct addrinfo** out) { int rv; - if (host_mapper) { - rv = HostResolverProc(host_mapper->Map(host), port, out); + if (mapper) { + rv = HostResolverProc(mapper->Map(host), port, out); } else { rv = HostResolverProc(host, port, out); } @@ -73,6 +77,7 @@ class HostResolver::Request : addresses_(addresses), callback_(callback), origin_loop_(MessageLoop::current()), + host_mapper_(host_mapper), error_(OK), results_(NULL) { } @@ -84,7 +89,7 @@ class HostResolver::Request : void DoLookup() { // Running on the worker thread - error_ = ResolveAddrInfo(host_, port_, &results_); + error_ = ResolveAddrInfo(host_mapper_, host_, port_, &results_); Task* reply = NewRunnableMethod(this, &Request::DoCallback); @@ -144,6 +149,12 @@ class HostResolver::Request : Lock origin_loop_lock_; MessageLoop* origin_loop_; + // Hold an owning reference to the host mapper that we are going to use. + // This may not be the current host mapper by the time we call + // ResolveAddrInfo, but that's OK... we'll use it anyways, and the owning + // reference ensures that it remains valid until we are done. + scoped_refptr<HostMapper> host_mapper_; + // Assigned on the worker thread, read on the origin thread. int error_; struct addrinfo* results_; @@ -172,7 +183,7 @@ int HostResolver::Resolve(const std::string& hostname, int port, // Do a synchronous resolution. if (!callback) { struct addrinfo* results; - int rv = ResolveAddrInfo(hostname, port_str, &results); + int rv = ResolveAddrInfo(host_mapper, hostname, port_str, &results); if (rv == OK) addresses->Adopt(results); return rv; |