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/memory/ptr_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 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 | 16 |
| 17 // 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. |
| 18 // Also detects connection errors for HostResolverRequestClient and cancels the | 18 // Also detects connection errors for HostResolverRequestClient and cancels the |
| 19 // outstanding resolve request. Owned by MojoHostResolverImpl. | 19 // outstanding resolve request. Owned by MojoHostResolverImpl. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 44 AddressList result_; | 44 AddressList result_; |
| 45 base::ThreadChecker thread_checker_; | 45 base::ThreadChecker thread_checker_; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 MojoHostResolverImpl::MojoHostResolverImpl(net::HostResolver* resolver, | 48 MojoHostResolverImpl::MojoHostResolverImpl(net::HostResolver* resolver, |
| 49 const NetLogWithSource& net_log) | 49 const NetLogWithSource& net_log) |
| 50 : resolver_(resolver), net_log_(net_log) {} | 50 : resolver_(resolver), net_log_(net_log) {} |
| 51 | 51 |
| 52 MojoHostResolverImpl::~MojoHostResolverImpl() { | 52 MojoHostResolverImpl::~MojoHostResolverImpl() { |
| 53 DCHECK(thread_checker_.CalledOnValidThread()); | 53 DCHECK(thread_checker_.CalledOnValidThread()); |
| 54 base::STLDeleteElements(&pending_jobs_); | |
| 55 } | 54 } |
| 56 | 55 |
| 57 void MojoHostResolverImpl::Resolve( | 56 void MojoHostResolverImpl::Resolve( |
| 58 std::unique_ptr<HostResolver::RequestInfo> request_info, | 57 std::unique_ptr<HostResolver::RequestInfo> request_info, |
| 59 interfaces::HostResolverRequestClientPtr client) { | 58 interfaces::HostResolverRequestClientPtr client) { |
| 60 DCHECK(thread_checker_.CalledOnValidThread()); | 59 DCHECK(thread_checker_.CalledOnValidThread()); |
| 61 if (request_info->is_my_ip_address()) { | 60 if (request_info->is_my_ip_address()) { |
| 62 // The proxy resolver running inside a sandbox may not be able to get the | 61 // The proxy resolver running inside a sandbox may not be able to get the |
| 63 // correct host name. Instead, fill it ourself if the request is for our own | 62 // correct host name. Instead, fill it ourself if the request is for our own |
| 64 // IP address. | 63 // IP address. |
| 65 request_info->set_host_port_pair(HostPortPair(GetHostName(), 80)); | 64 request_info->set_host_port_pair(HostPortPair(GetHostName(), 80)); |
| 66 } | 65 } |
| 67 Job* job = | 66 Job* job = |
| 68 new Job(this, resolver_, *request_info, net_log_, std::move(client)); | 67 new Job(this, resolver_, *request_info, net_log_, std::move(client)); |
| 69 pending_jobs_.insert(job); | 68 pending_jobs_.insert(base::WrapUnique(job)); |
| 70 job->Start(); | 69 job->Start(); |
| 71 } | 70 } |
| 72 | 71 |
| 73 void MojoHostResolverImpl::DeleteJob(Job* job) { | 72 void MojoHostResolverImpl::DeleteJob(Job* job) { |
| 74 DCHECK(thread_checker_.CalledOnValidThread()); | 73 DCHECK(thread_checker_.CalledOnValidThread()); |
| 75 size_t num_erased = pending_jobs_.erase(job); | 74 auto it = std::find_if( |
| 76 DCHECK(num_erased); | 75 pending_jobs_.begin(), pending_jobs_.end(), |
| 77 delete job; | 76 [job](const std::unique_ptr<Job>& ptr) { return ptr.get() == job; }); |
|
davidben
2016/11/09 22:22:03
Same issue as always. :-) std::find_if on a std::s
| |
| 77 DCHECK(it != pending_jobs_.end()); | |
| 78 pending_jobs_.erase(it); | |
| 78 } | 79 } |
| 79 | 80 |
| 80 MojoHostResolverImpl::Job::Job( | 81 MojoHostResolverImpl::Job::Job( |
| 81 MojoHostResolverImpl* resolver_service, | 82 MojoHostResolverImpl* resolver_service, |
| 82 net::HostResolver* resolver, | 83 net::HostResolver* resolver, |
| 83 const net::HostResolver::RequestInfo& request_info, | 84 const net::HostResolver::RequestInfo& request_info, |
| 84 const NetLogWithSource& net_log, | 85 const NetLogWithSource& net_log, |
| 85 interfaces::HostResolverRequestClientPtr client) | 86 interfaces::HostResolverRequestClientPtr client) |
| 86 : resolver_service_(resolver_service), | 87 : resolver_service_(resolver_service), |
| 87 resolver_(resolver), | 88 resolver_(resolver), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 void MojoHostResolverImpl::Job::OnConnectionError() { | 124 void MojoHostResolverImpl::Job::OnConnectionError() { |
| 124 DCHECK(thread_checker_.CalledOnValidThread()); | 125 DCHECK(thread_checker_.CalledOnValidThread()); |
| 125 // |resolver_service_| should always outlive us. | 126 // |resolver_service_| should always outlive us. |
| 126 DCHECK(resolver_service_); | 127 DCHECK(resolver_service_); |
| 127 DVLOG(1) << "Connection error on request for " | 128 DVLOG(1) << "Connection error on request for " |
| 128 << request_info_.host_port_pair().ToString(); | 129 << request_info_.host_port_pair().ToString(); |
| 129 resolver_service_->DeleteJob(this); | 130 resolver_service_->DeleteJob(this); |
| 130 } | 131 } |
| 131 | 132 |
| 132 } // namespace net | 133 } // namespace net |
| OLD | NEW |