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
3 // found in the LICENSE file.
5 #include "net/dns/dns_client.h"
8 #include "base/rand_util.h"
9 #include "net/base/net_log.h"
10 #include "net/dns/address_sorter.h"
11 #include "net/dns/dns_config_service.h"
12 #include "net/dns/dns_session.h"
13 #include "net/dns/dns_socket_pool.h"
14 #include "net/dns/dns_transaction.h"
15 #include "net/socket/client_socket_factory.h"
21 class DnsClientImpl
: public DnsClient
{
23 explicit DnsClientImpl(NetLog
* net_log
)
24 : address_sorter_(AddressSorter::CreateAddressSorter()),
27 virtual void SetConfig(const DnsConfig
& config
) OVERRIDE
{
30 if (config
.IsValid()) {
31 ClientSocketFactory
* factory
= ClientSocketFactory::GetDefaultFactory();
32 scoped_ptr
<DnsSocketPool
> socket_pool(
33 config
.randomize_ports
? DnsSocketPool::CreateDefault(factory
)
34 : DnsSocketPool::CreateNull(factory
));
35 session_
= new DnsSession(config
,
37 base::Bind(&base::RandInt
),
39 factory_
= DnsTransactionFactory::CreateFactory(session_
.get());
43 virtual const DnsConfig
* GetConfig() const OVERRIDE
{
44 return session_
.get() ? &session_
->config() : NULL
;
47 virtual DnsTransactionFactory
* GetTransactionFactory() OVERRIDE
{
48 return session_
.get() ? factory_
.get() : NULL
;
51 virtual AddressSorter
* GetAddressSorter() OVERRIDE
{
52 return address_sorter_
.get();
56 scoped_refptr
<DnsSession
> session_
;
57 scoped_ptr
<DnsTransactionFactory
> factory_
;
58 scoped_ptr
<AddressSorter
> address_sorter_
;
66 scoped_ptr
<DnsClient
> DnsClient::CreateClient(NetLog
* net_log
) {
67 return scoped_ptr
<DnsClient
>(new DnsClientImpl(net_log
));