| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/tools/quic/synchronous_host_resolver.h" | 5 #include "net/tools/quic/synchronous_host_resolver.h" |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/run_loop.h" |
| 11 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 12 #include "base/threading/simple_thread.h" | 13 #include "base/threading/simple_thread.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "net/base/host_port_pair.h" | 15 #include "net/base/host_port_pair.h" |
| 15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 16 #include "net/dns/host_resolver_impl.h" | 17 #include "net/dns/host_resolver_impl.h" |
| 17 #include "net/dns/single_request_host_resolver.h" | 18 #include "net/dns/single_request_host_resolver.h" |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 | 21 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 rv_ = resolver.Resolve(HostResolver::RequestInfo(host_port_pair), | 68 rv_ = resolver.Resolve(HostResolver::RequestInfo(host_port_pair), |
| 68 DEFAULT_PRIORITY, addresses_, | 69 DEFAULT_PRIORITY, addresses_, |
| 69 base::Bind(&ResolverThread::OnResolutionComplete, | 70 base::Bind(&ResolverThread::OnResolutionComplete, |
| 70 weak_factory_.GetWeakPtr()), | 71 weak_factory_.GetWeakPtr()), |
| 71 BoundNetLog()); | 72 BoundNetLog()); |
| 72 | 73 |
| 73 if (rv_ != ERR_IO_PENDING) | 74 if (rv_ != ERR_IO_PENDING) |
| 74 return; | 75 return; |
| 75 | 76 |
| 76 // Run the mesage loop until OnResolutionComplete quits it. | 77 // Run the mesage loop until OnResolutionComplete quits it. |
| 77 base::MessageLoop::current()->Run(); | 78 base::RunLoop().Run(); |
| 78 } | 79 } |
| 79 | 80 |
| 80 int ResolverThread::Resolve(const std::string& host, AddressList* addresses) { | 81 int ResolverThread::Resolve(const std::string& host, AddressList* addresses) { |
| 81 host_ = host; | 82 host_ = host; |
| 82 addresses_ = addresses; | 83 addresses_ = addresses; |
| 83 this->Start(); | 84 this->Start(); |
| 84 this->Join(); | 85 this->Join(); |
| 85 return rv_; | 86 return rv_; |
| 86 } | 87 } |
| 87 | 88 |
| 88 void ResolverThread::OnResolutionComplete(int rv) { | 89 void ResolverThread::OnResolutionComplete(int rv) { |
| 89 rv_ = rv; | 90 rv_ = rv; |
| 90 base::ThreadTaskRunnerHandle::Get()->PostTask( | 91 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 91 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 92 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 92 } | 93 } |
| 93 | 94 |
| 94 } // namespace | 95 } // namespace |
| 95 | 96 |
| 96 // static | 97 // static |
| 97 int SynchronousHostResolver::Resolve(const std::string& host, | 98 int SynchronousHostResolver::Resolve(const std::string& host, |
| 98 AddressList* addresses) { | 99 AddressList* addresses) { |
| 99 ResolverThread resolver; | 100 ResolverThread resolver; |
| 100 return resolver.Resolve(host, addresses); | 101 return resolver.Resolve(host, addresses); |
| 101 } | 102 } |
| 102 | 103 |
| 103 } // namespace net | 104 } // namespace net |
| OLD | NEW |