Chromium Code Reviews| 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 HostResolver::RequestInfo& host_request_info = *request_info; |
|
eroman
2016/06/24 18:48:09
Can you instead delete this line and just directly
Sam McNally
2016/06/27 01:41:31
Done.
| |
| 64 request_info->To<net::HostResolver::RequestInfo>(); | |
| 65 if (host_request_info.is_my_ip_address()) { | 63 if (host_request_info.is_my_ip_address()) { |
| 66 // The proxy resolver running inside a sandbox may not be able to get the | 64 // 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 | 65 // correct host name. Instead, fill it ourself if the request is for our own |
| 68 // IP address. | 66 // IP address. |
| 69 host_request_info.set_host_port_pair(HostPortPair(GetHostName(), 80)); | 67 host_request_info.set_host_port_pair(HostPortPair(GetHostName(), 80)); |
| 70 } | 68 } |
| 71 Job* job = new Job(this, resolver_, host_request_info, net_log_, | 69 Job* job = new Job(this, resolver_, host_request_info, net_log_, |
| 72 std::move(client)); | 70 std::move(client)); |
| 73 pending_jobs_.insert(job); | 71 pending_jobs_.insert(job); |
| 74 job->Start(); | 72 job->Start(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 | 115 |
| 118 void MojoHostResolverImpl::Job::OnResolveDone(int result) { | 116 void MojoHostResolverImpl::Job::OnResolveDone(int result) { |
| 119 DCHECK(thread_checker_.CalledOnValidThread()); | 117 DCHECK(thread_checker_.CalledOnValidThread()); |
| 120 handle_ = nullptr; | 118 handle_ = nullptr; |
| 121 DVLOG(1) << "Resolved " << request_info_.host_port_pair().ToString() | 119 DVLOG(1) << "Resolved " << request_info_.host_port_pair().ToString() |
| 122 << " with error " << result << " and " << result_.size() | 120 << " with error " << result << " and " << result_.size() |
| 123 << " results!"; | 121 << " results!"; |
| 124 for (const auto& address : result_) { | 122 for (const auto& address : result_) { |
| 125 DVLOG(1) << address.ToString(); | 123 DVLOG(1) << address.ToString(); |
| 126 } | 124 } |
| 127 if (result == OK) | 125 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); | 126 resolver_service_->DeleteJob(this); |
| 133 } | 127 } |
| 134 | 128 |
| 135 void MojoHostResolverImpl::Job::OnConnectionError() { | 129 void MojoHostResolverImpl::Job::OnConnectionError() { |
| 136 DCHECK(thread_checker_.CalledOnValidThread()); | 130 DCHECK(thread_checker_.CalledOnValidThread()); |
| 137 // |resolver_service_| should always outlive us. | 131 // |resolver_service_| should always outlive us. |
| 138 DCHECK(resolver_service_); | 132 DCHECK(resolver_service_); |
| 139 DVLOG(1) << "Connection error on request for " | 133 DVLOG(1) << "Connection error on request for " |
| 140 << request_info_.host_port_pair().ToString(); | 134 << request_info_.host_port_pair().ToString(); |
| 141 resolver_service_->DeleteJob(this); | 135 resolver_service_->DeleteJob(this); |
| 142 } | 136 } |
| 143 | 137 |
| 144 } // namespace net | 138 } // namespace net |
| OLD | NEW |