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/base/network_interfaces.h" |
13 #include "net/dns/host_resolver.h" | 13 #include "net/dns/host_resolver.h" |
14 #include "net/dns/mojo_host_type_converters.h" | |
15 | 14 |
16 namespace net { | 15 namespace net { |
17 | 16 |
18 // Handles host resolution for a single request and sends a response when done. | 17 // Handles host resolution for a single request and sends a response when done. |
19 // Also detects connection errors for HostResolverRequestClient and cancels the | 18 // Also detects connection errors for HostResolverRequestClient and cancels the |
20 // outstanding resolve request. Owned by MojoHostResolverImpl. | 19 // outstanding resolve request. Owned by MojoHostResolverImpl. |
21 class MojoHostResolverImpl::Job { | 20 class MojoHostResolverImpl::Job { |
22 public: | 21 public: |
23 Job(MojoHostResolverImpl* resolver_service, | 22 Job(MojoHostResolverImpl* resolver_service, |
24 net::HostResolver* resolver, | 23 net::HostResolver* resolver, |
(...skipping 24 matching lines...) Expand all Loading... |
49 MojoHostResolverImpl::MojoHostResolverImpl(net::HostResolver* resolver, | 48 MojoHostResolverImpl::MojoHostResolverImpl(net::HostResolver* resolver, |
50 const NetLogWithSource& net_log) | 49 const NetLogWithSource& net_log) |
51 : resolver_(resolver), net_log_(net_log) {} | 50 : resolver_(resolver), net_log_(net_log) {} |
52 | 51 |
53 MojoHostResolverImpl::~MojoHostResolverImpl() { | 52 MojoHostResolverImpl::~MojoHostResolverImpl() { |
54 DCHECK(thread_checker_.CalledOnValidThread()); | 53 DCHECK(thread_checker_.CalledOnValidThread()); |
55 base::STLDeleteElements(&pending_jobs_); | 54 base::STLDeleteElements(&pending_jobs_); |
56 } | 55 } |
57 | 56 |
58 void MojoHostResolverImpl::Resolve( | 57 void MojoHostResolverImpl::Resolve( |
59 interfaces::HostResolverRequestInfoPtr request_info, | 58 std::unique_ptr<HostResolver::RequestInfo> request_info, |
60 interfaces::HostResolverRequestClientPtr client) { | 59 interfaces::HostResolverRequestClientPtr client) { |
61 DCHECK(thread_checker_.CalledOnValidThread()); | 60 DCHECK(thread_checker_.CalledOnValidThread()); |
62 HostResolver::RequestInfo host_request_info = | 61 if (request_info->is_my_ip_address()) { |
63 request_info->To<net::HostResolver::RequestInfo>(); | |
64 if (host_request_info.is_my_ip_address()) { | |
65 // The proxy resolver running inside a sandbox may not be able to get the | 62 // The proxy resolver running inside a sandbox may not be able to get the |
66 // correct host name. Instead, fill it ourself if the request is for our own | 63 // correct host name. Instead, fill it ourself if the request is for our own |
67 // IP address. | 64 // IP address. |
68 host_request_info.set_host_port_pair(HostPortPair(GetHostName(), 80)); | 65 request_info->set_host_port_pair(HostPortPair(GetHostName(), 80)); |
69 } | 66 } |
70 Job* job = new Job(this, resolver_, host_request_info, net_log_, | 67 Job* job = |
71 std::move(client)); | 68 new Job(this, resolver_, *request_info, net_log_, std::move(client)); |
72 pending_jobs_.insert(job); | 69 pending_jobs_.insert(job); |
73 job->Start(); | 70 job->Start(); |
74 } | 71 } |
75 | 72 |
76 void MojoHostResolverImpl::DeleteJob(Job* job) { | 73 void MojoHostResolverImpl::DeleteJob(Job* job) { |
77 DCHECK(thread_checker_.CalledOnValidThread()); | 74 DCHECK(thread_checker_.CalledOnValidThread()); |
78 size_t num_erased = pending_jobs_.erase(job); | 75 size_t num_erased = pending_jobs_.erase(job); |
79 DCHECK(num_erased); | 76 DCHECK(num_erased); |
80 delete job; | 77 delete job; |
81 } | 78 } |
(...skipping 30 matching lines...) Expand all Loading... |
112 | 109 |
113 void MojoHostResolverImpl::Job::OnResolveDone(int result) { | 110 void MojoHostResolverImpl::Job::OnResolveDone(int result) { |
114 DCHECK(thread_checker_.CalledOnValidThread()); | 111 DCHECK(thread_checker_.CalledOnValidThread()); |
115 request_.reset(); | 112 request_.reset(); |
116 DVLOG(1) << "Resolved " << request_info_.host_port_pair().ToString() | 113 DVLOG(1) << "Resolved " << request_info_.host_port_pair().ToString() |
117 << " with error " << result << " and " << result_.size() | 114 << " with error " << result << " and " << result_.size() |
118 << " results!"; | 115 << " results!"; |
119 for (const auto& address : result_) { | 116 for (const auto& address : result_) { |
120 DVLOG(1) << address.ToString(); | 117 DVLOG(1) << address.ToString(); |
121 } | 118 } |
122 if (result == OK) | 119 client_->ReportResult(result, result_); |
123 client_->ReportResult(result, interfaces::AddressList::From(result_)); | |
124 else | |
125 client_->ReportResult(result, nullptr); | |
126 | |
127 resolver_service_->DeleteJob(this); | 120 resolver_service_->DeleteJob(this); |
128 } | 121 } |
129 | 122 |
130 void MojoHostResolverImpl::Job::OnConnectionError() { | 123 void MojoHostResolverImpl::Job::OnConnectionError() { |
131 DCHECK(thread_checker_.CalledOnValidThread()); | 124 DCHECK(thread_checker_.CalledOnValidThread()); |
132 // |resolver_service_| should always outlive us. | 125 // |resolver_service_| should always outlive us. |
133 DCHECK(resolver_service_); | 126 DCHECK(resolver_service_); |
134 DVLOG(1) << "Connection error on request for " | 127 DVLOG(1) << "Connection error on request for " |
135 << request_info_.host_port_pair().ToString(); | 128 << request_info_.host_port_pair().ToString(); |
136 resolver_service_->DeleteJob(this); | 129 resolver_service_->DeleteJob(this); |
137 } | 130 } |
138 | 131 |
139 } // namespace net | 132 } // namespace net |
OLD | NEW |