| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "net/base/net_log.h" | 9 #include "net/base/net_log.h" |
| 10 #include "net/dns/address_sorter.h" |
| 10 #include "net/dns/dns_config_service.h" | 11 #include "net/dns/dns_config_service.h" |
| 11 #include "net/dns/dns_session.h" | 12 #include "net/dns/dns_session.h" |
| 12 #include "net/dns/dns_transaction.h" | 13 #include "net/dns/dns_transaction.h" |
| 13 #include "net/socket/client_socket_factory.h" | 14 #include "net/socket/client_socket_factory.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 class DnsClientImpl : public DnsClient { | 20 class DnsClientImpl : public DnsClient { |
| 20 public: | 21 public: |
| 21 explicit DnsClientImpl(NetLog* net_log) : net_log_(net_log) {} | 22 explicit DnsClientImpl(NetLog* net_log) |
| 23 : address_sorter_(AddressSorter::CreateAddressSorter()), |
| 24 net_log_(net_log) {} |
| 22 | 25 |
| 23 virtual void SetConfig(const DnsConfig& config) OVERRIDE { | 26 virtual void SetConfig(const DnsConfig& config) OVERRIDE { |
| 24 factory_.reset(); | 27 factory_.reset(); |
| 25 session_.release(); | 28 session_.release(); |
| 26 if (config.IsValid()) { | 29 if (config.IsValid()) { |
| 27 session_ = new DnsSession(config, | 30 session_ = new DnsSession(config, |
| 28 ClientSocketFactory::GetDefaultFactory(), | 31 ClientSocketFactory::GetDefaultFactory(), |
| 29 base::Bind(&base::RandInt), | 32 base::Bind(&base::RandInt), |
| 30 net_log_); | 33 net_log_); |
| 31 factory_ = DnsTransactionFactory::CreateFactory(session_); | 34 factory_ = DnsTransactionFactory::CreateFactory(session_); |
| 32 } | 35 } |
| 33 } | 36 } |
| 34 | 37 |
| 35 virtual const DnsConfig* GetConfig() const OVERRIDE { | 38 virtual const DnsConfig* GetConfig() const OVERRIDE { |
| 36 return session_.get() ? &session_->config() : NULL; | 39 return session_.get() ? &session_->config() : NULL; |
| 37 } | 40 } |
| 38 | 41 |
| 39 virtual DnsTransactionFactory* GetTransactionFactory() OVERRIDE { | 42 virtual DnsTransactionFactory* GetTransactionFactory() OVERRIDE { |
| 40 return session_.get() ? factory_.get() : NULL; | 43 return session_.get() ? factory_.get() : NULL; |
| 41 } | 44 } |
| 42 | 45 |
| 46 virtual AddressSorter* GetAddressSorter() OVERRIDE { |
| 47 return address_sorter_.get(); |
| 48 } |
| 49 |
| 43 private: | 50 private: |
| 44 scoped_refptr<DnsSession> session_; | 51 scoped_refptr<DnsSession> session_; |
| 45 scoped_ptr<DnsTransactionFactory> factory_; | 52 scoped_ptr<DnsTransactionFactory> factory_; |
| 53 scoped_ptr<AddressSorter> address_sorter_; |
| 46 | 54 |
| 47 NetLog* net_log_; | 55 NetLog* net_log_; |
| 48 }; | 56 }; |
| 49 | 57 |
| 50 } // namespace | 58 } // namespace |
| 51 | 59 |
| 52 // static | 60 // static |
| 53 scoped_ptr<DnsClient> DnsClient::CreateClient(NetLog* net_log) { | 61 scoped_ptr<DnsClient> DnsClient::CreateClient(NetLog* net_log) { |
| 54 return scoped_ptr<DnsClient>(new DnsClientImpl(net_log)); | 62 return scoped_ptr<DnsClient>(new DnsClientImpl(net_log)); |
| 55 } | 63 } |
| 56 | 64 |
| 57 } // namespace net | 65 } // namespace net |
| 58 | 66 |
| OLD | NEW |