| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/dns/mojo_host_resolver_impl.h" | 5 #include "net/dns/mojo_host_resolver_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 #include "net/base/network_interfaces.h" |
| 12 #include "net/dns/host_resolver.h" | 13 #include "net/dns/host_resolver.h" |
| 13 #include "net/dns/mojo_host_type_converters.h" | 14 #include "net/dns/mojo_host_type_converters.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 | 17 |
| 17 // Handles host resolution for a single request and sends a response when done. | 18 // Handles host resolution for a single request and sends a response when done. |
| 18 // Also detects connection errors for HostResolverRequestClient and cancels the | 19 // Also detects connection errors for HostResolverRequestClient and cancels the |
| 19 // outstanding resolve request. Owned by MojoHostResolverImpl. | 20 // outstanding resolve request. Owned by MojoHostResolverImpl. |
| 20 class MojoHostResolverImpl::Job { | 21 class MojoHostResolverImpl::Job { |
| 21 public: | 22 public: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 52 | 53 |
| 53 MojoHostResolverImpl::~MojoHostResolverImpl() { | 54 MojoHostResolverImpl::~MojoHostResolverImpl() { |
| 54 DCHECK(thread_checker_.CalledOnValidThread()); | 55 DCHECK(thread_checker_.CalledOnValidThread()); |
| 55 STLDeleteElements(&pending_jobs_); | 56 STLDeleteElements(&pending_jobs_); |
| 56 } | 57 } |
| 57 | 58 |
| 58 void MojoHostResolverImpl::Resolve( | 59 void MojoHostResolverImpl::Resolve( |
| 59 interfaces::HostResolverRequestInfoPtr request_info, | 60 interfaces::HostResolverRequestInfoPtr request_info, |
| 60 interfaces::HostResolverRequestClientPtr client) { | 61 interfaces::HostResolverRequestClientPtr client) { |
| 61 DCHECK(thread_checker_.CalledOnValidThread()); | 62 DCHECK(thread_checker_.CalledOnValidThread()); |
| 62 Job* job = new Job(this, resolver_, | 63 HostResolver::RequestInfo host_request_info = |
| 63 request_info->To<net::HostResolver::RequestInfo>(), | 64 request_info->To<net::HostResolver::RequestInfo>(); |
| 64 net_log_, std::move(client)); | 65 if (host_request_info.is_my_ip_address()) { |
| 66 // The proxy resolver running inside a sandbox may not be able to get the |
| 67 // correct host name. Instead, fill it ourself if the request is for our own |
| 68 // IP address. |
| 69 host_request_info.set_host_port_pair(HostPortPair(GetHostName(), 80)); |
| 70 } |
| 71 Job* job = new Job(this, resolver_, host_request_info, net_log_, |
| 72 std::move(client)); |
| 65 pending_jobs_.insert(job); | 73 pending_jobs_.insert(job); |
| 66 job->Start(); | 74 job->Start(); |
| 67 } | 75 } |
| 68 | 76 |
| 69 void MojoHostResolverImpl::DeleteJob(Job* job) { | 77 void MojoHostResolverImpl::DeleteJob(Job* job) { |
| 70 DCHECK(thread_checker_.CalledOnValidThread()); | 78 DCHECK(thread_checker_.CalledOnValidThread()); |
| 71 size_t num_erased = pending_jobs_.erase(job); | 79 size_t num_erased = pending_jobs_.erase(job); |
| 72 DCHECK(num_erased); | 80 DCHECK(num_erased); |
| 73 delete job; | 81 delete job; |
| 74 } | 82 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 void MojoHostResolverImpl::Job::OnConnectionError() { | 135 void MojoHostResolverImpl::Job::OnConnectionError() { |
| 128 DCHECK(thread_checker_.CalledOnValidThread()); | 136 DCHECK(thread_checker_.CalledOnValidThread()); |
| 129 // |resolver_service_| should always outlive us. | 137 // |resolver_service_| should always outlive us. |
| 130 DCHECK(resolver_service_); | 138 DCHECK(resolver_service_); |
| 131 DVLOG(1) << "Connection error on request for " | 139 DVLOG(1) << "Connection error on request for " |
| 132 << request_info_.host_port_pair().ToString(); | 140 << request_info_.host_port_pair().ToString(); |
| 133 resolver_service_->DeleteJob(this); | 141 resolver_service_->DeleteJob(this); |
| 134 } | 142 } |
| 135 | 143 |
| 136 } // namespace net | 144 } // namespace net |
| OLD | NEW |