We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / net / tools / quic / synchronous_host_resolver.cc
blobaa96719538cccc1662fcd8e1e524e38dde71b88a
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
3 // found in the LICENSE file.
5 #include "net/tools/quic/synchronous_host_resolver.h"
7 #include "base/at_exit.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/threading/simple_thread.h"
10 #include "net/base/host_port_pair.h"
11 #include "net/base/net_errors.h"
12 #include "net/dns/host_resolver_impl.h"
13 #include "net/dns/single_request_host_resolver.h"
15 namespace net {
17 namespace tools {
19 namespace {
21 class ResolverThread : public base::SimpleThread {
22 public:
23 ResolverThread();
25 ~ResolverThread() override;
27 // Called on the main thread.
28 int Resolve(const std::string& host, AddressList* addresses);
30 // SimpleThread methods:
31 void Run() override;
33 private:
34 void OnResolutionComplete(int rv);
36 AddressList* addresses_;
37 std::string host_;
38 int rv_;
40 base::WeakPtrFactory<ResolverThread> weak_factory_;
42 DISALLOW_COPY_AND_ASSIGN(ResolverThread);
45 ResolverThread::ResolverThread()
46 : SimpleThread("resolver_thread"),
47 rv_(ERR_UNEXPECTED),
48 weak_factory_(this) {}
50 ResolverThread::~ResolverThread() {}
52 void ResolverThread::Run() {
53 base::AtExitManager exit_manager;
54 base::MessageLoopForIO loop;
56 net::NetLog net_log;
57 net::HostResolver::Options options;
58 options.max_concurrent_resolves = 6;
59 options.max_retry_attempts = 3u;
60 scoped_ptr<net::HostResolverImpl> resolver_impl(
61 new net::HostResolverImpl(options, &net_log));
62 SingleRequestHostResolver resolver(resolver_impl.get());
64 HostPortPair host_port_pair(host_, 80);
65 rv_ = resolver.Resolve(
66 HostResolver::RequestInfo(host_port_pair), DEFAULT_PRIORITY,
67 addresses_,
68 base::Bind(&ResolverThread::OnResolutionComplete,
69 weak_factory_.GetWeakPtr()),
70 BoundNetLog());
72 if (rv_ != ERR_IO_PENDING)
73 return;
75 // Run the mesage loop until OnResolutionComplete quits it.
76 base::MessageLoop::current()->Run();
79 int ResolverThread::Resolve(const std::string& host, AddressList* addresses) {
80 host_ = host;
81 addresses_ = addresses;
82 this->Start();
83 this->Join();
84 return rv_;
87 void ResolverThread::OnResolutionComplete(int rv) {
88 rv_ = rv;
89 base::MessageLoop::current()->PostTask(
90 FROM_HERE,
91 base::MessageLoop::QuitClosure());
94 } // namespace
96 // static
97 int SynchronousHostResolver::Resolve(const std::string& host,
98 AddressList* addresses) {
99 ResolverThread resolver;
100 return resolver.Resolve(host, addresses);
103 } // namespace tools
104 } // namespace net