OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/dns_client.h" | 5 #include "net/dns/dns_client.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
9 #include "net/dns/address_sorter.h" | 11 #include "net/dns/address_sorter.h" |
10 #include "net/dns/dns_config_service.h" | 12 #include "net/dns/dns_config_service.h" |
11 #include "net/dns/dns_session.h" | 13 #include "net/dns/dns_session.h" |
12 #include "net/dns/dns_socket_pool.h" | 14 #include "net/dns/dns_socket_pool.h" |
13 #include "net/dns/dns_transaction.h" | 15 #include "net/dns/dns_transaction.h" |
14 #include "net/log/net_log.h" | 16 #include "net/log/net_log.h" |
15 #include "net/socket/client_socket_factory.h" | 17 #include "net/socket/client_socket_factory.h" |
16 | 18 |
17 namespace net { | 19 namespace net { |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 class DnsClientImpl : public DnsClient { | 23 class DnsClientImpl : public DnsClient { |
22 public: | 24 public: |
23 explicit DnsClientImpl(NetLog* net_log) | 25 explicit DnsClientImpl(NetLog* net_log) |
24 : address_sorter_(AddressSorter::CreateAddressSorter()), | 26 : address_sorter_(AddressSorter::CreateAddressSorter()), |
25 net_log_(net_log) {} | 27 net_log_(net_log) {} |
26 | 28 |
27 void SetConfig(const DnsConfig& config) override { | 29 void SetConfig(const DnsConfig& config) override { |
28 factory_.reset(); | 30 factory_.reset(); |
29 session_ = NULL; | 31 session_ = NULL; |
30 if (config.IsValid() && !config.unhandled_options) { | 32 if (config.IsValid() && !config.unhandled_options) { |
31 ClientSocketFactory* factory = ClientSocketFactory::GetDefaultFactory(); | 33 ClientSocketFactory* factory = ClientSocketFactory::GetDefaultFactory(); |
32 scoped_ptr<DnsSocketPool> socket_pool( | 34 scoped_ptr<DnsSocketPool> socket_pool( |
33 config.randomize_ports ? DnsSocketPool::CreateDefault(factory) | 35 config.randomize_ports ? DnsSocketPool::CreateDefault(factory) |
34 : DnsSocketPool::CreateNull(factory)); | 36 : DnsSocketPool::CreateNull(factory)); |
35 session_ = new DnsSession(config, | 37 session_ = new DnsSession(config, std::move(socket_pool), |
36 socket_pool.Pass(), | 38 base::Bind(&base::RandInt), net_log_); |
37 base::Bind(&base::RandInt), | |
38 net_log_); | |
39 factory_ = DnsTransactionFactory::CreateFactory(session_.get()); | 39 factory_ = DnsTransactionFactory::CreateFactory(session_.get()); |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 const DnsConfig* GetConfig() const override { | 43 const DnsConfig* GetConfig() const override { |
44 return session_.get() ? &session_->config() : NULL; | 44 return session_.get() ? &session_->config() : NULL; |
45 } | 45 } |
46 | 46 |
47 DnsTransactionFactory* GetTransactionFactory() override { | 47 DnsTransactionFactory* GetTransactionFactory() override { |
48 return session_.get() ? factory_.get() : NULL; | 48 return session_.get() ? factory_.get() : NULL; |
(...skipping 11 matching lines...) Expand all Loading... |
60 | 60 |
61 } // namespace | 61 } // namespace |
62 | 62 |
63 // static | 63 // static |
64 scoped_ptr<DnsClient> DnsClient::CreateClient(NetLog* net_log) { | 64 scoped_ptr<DnsClient> DnsClient::CreateClient(NetLog* net_log) { |
65 return scoped_ptr<DnsClient>(new DnsClientImpl(net_log)); | 65 return scoped_ptr<DnsClient>(new DnsClientImpl(net_log)); |
66 } | 66 } |
67 | 67 |
68 } // namespace net | 68 } // namespace net |
69 | 69 |
OLD | NEW |