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 25 matching lines...) Expand all Loading... |
50 const BoundNetLog& net_log) | 49 const BoundNetLog& net_log) |
51 : resolver_(resolver), net_log_(net_log) { | 50 : resolver_(resolver), net_log_(net_log) { |
52 } | 51 } |
53 | 52 |
54 MojoHostResolverImpl::~MojoHostResolverImpl() { | 53 MojoHostResolverImpl::~MojoHostResolverImpl() { |
55 DCHECK(thread_checker_.CalledOnValidThread()); | 54 DCHECK(thread_checker_.CalledOnValidThread()); |
56 STLDeleteElements(&pending_jobs_); | 55 STLDeleteElements(&pending_jobs_); |
57 } | 56 } |
58 | 57 |
59 void MojoHostResolverImpl::Resolve( | 58 void MojoHostResolverImpl::Resolve( |
60 interfaces::HostResolverRequestInfoPtr request_info, | 59 std::unique_ptr<HostResolver::RequestInfo> request_info, |
61 interfaces::HostResolverRequestClientPtr client) { | 60 interfaces::HostResolverRequestClientPtr client) { |
62 DCHECK(thread_checker_.CalledOnValidThread()); | 61 DCHECK(thread_checker_.CalledOnValidThread()); |
63 HostResolver::RequestInfo host_request_info = | 62 if (request_info->is_my_ip_address()) { |
64 request_info->To<net::HostResolver::RequestInfo>(); | |
65 if (host_request_info.is_my_ip_address()) { | |
66 // The proxy resolver running inside a sandbox may not be able to get the | 63 // 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 | 64 // correct host name. Instead, fill it ourself if the request is for our own |
68 // IP address. | 65 // IP address. |
69 host_request_info.set_host_port_pair(HostPortPair(GetHostName(), 80)); | 66 request_info->set_host_port_pair(HostPortPair(GetHostName(), 80)); |
70 } | 67 } |
71 Job* job = new Job(this, resolver_, host_request_info, net_log_, | 68 Job* job = |
72 std::move(client)); | 69 new Job(this, resolver_, *request_info, net_log_, std::move(client)); |
73 pending_jobs_.insert(job); | 70 pending_jobs_.insert(job); |
74 job->Start(); | 71 job->Start(); |
75 } | 72 } |
76 | 73 |
77 void MojoHostResolverImpl::DeleteJob(Job* job) { | 74 void MojoHostResolverImpl::DeleteJob(Job* job) { |
78 DCHECK(thread_checker_.CalledOnValidThread()); | 75 DCHECK(thread_checker_.CalledOnValidThread()); |
79 size_t num_erased = pending_jobs_.erase(job); | 76 size_t num_erased = pending_jobs_.erase(job); |
80 DCHECK(num_erased); | 77 DCHECK(num_erased); |
81 delete job; | 78 delete job; |
82 } | 79 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 114 |
118 void MojoHostResolverImpl::Job::OnResolveDone(int result) { | 115 void MojoHostResolverImpl::Job::OnResolveDone(int result) { |
119 DCHECK(thread_checker_.CalledOnValidThread()); | 116 DCHECK(thread_checker_.CalledOnValidThread()); |
120 handle_ = nullptr; | 117 handle_ = nullptr; |
121 DVLOG(1) << "Resolved " << request_info_.host_port_pair().ToString() | 118 DVLOG(1) << "Resolved " << request_info_.host_port_pair().ToString() |
122 << " with error " << result << " and " << result_.size() | 119 << " with error " << result << " and " << result_.size() |
123 << " results!"; | 120 << " results!"; |
124 for (const auto& address : result_) { | 121 for (const auto& address : result_) { |
125 DVLOG(1) << address.ToString(); | 122 DVLOG(1) << address.ToString(); |
126 } | 123 } |
127 if (result == OK) | 124 client_->ReportResult(result, result_); |
128 client_->ReportResult(result, interfaces::AddressList::From(result_)); | |
129 else | |
130 client_->ReportResult(result, nullptr); | |
131 | |
132 resolver_service_->DeleteJob(this); | 125 resolver_service_->DeleteJob(this); |
133 } | 126 } |
134 | 127 |
135 void MojoHostResolverImpl::Job::OnConnectionError() { | 128 void MojoHostResolverImpl::Job::OnConnectionError() { |
136 DCHECK(thread_checker_.CalledOnValidThread()); | 129 DCHECK(thread_checker_.CalledOnValidThread()); |
137 // |resolver_service_| should always outlive us. | 130 // |resolver_service_| should always outlive us. |
138 DCHECK(resolver_service_); | 131 DCHECK(resolver_service_); |
139 DVLOG(1) << "Connection error on request for " | 132 DVLOG(1) << "Connection error on request for " |
140 << request_info_.host_port_pair().ToString(); | 133 << request_info_.host_port_pair().ToString(); |
141 resolver_service_->DeleteJob(this); | 134 resolver_service_->DeleteJob(this); |
142 } | 135 } |
143 | 136 |
144 } // namespace net | 137 } // namespace net |
OLD | NEW |