Revert 208429 "Disable AutofillQueryXmlParserTest.ParseAutofillF..."
[chromium-blink-merge.git] / net / dns / dns_socket_pool.h
blob6bfe474d6a91c9251e6228838e0c46e76bc4dca8
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 #ifndef NET_DNS_DNS_SOCKET_POOL_H_
6 #define NET_DNS_DNS_SOCKET_POOL_H_
8 #include <vector>
10 #include "base/memory/scoped_ptr.h"
11 #include "net/base/net_export.h"
12 #include "net/base/net_log.h"
14 namespace net {
16 class ClientSocketFactory;
17 class DatagramClientSocket;
18 class IPEndPoint;
19 class NetLog;
20 class StreamSocket;
22 // A DnsSocketPool is an abstraction layer around a ClientSocketFactory that
23 // allows preallocation, reuse, or other strategies to manage sockets connected
24 // to DNS servers.
25 class NET_EXPORT_PRIVATE DnsSocketPool {
26 public:
27 virtual ~DnsSocketPool() { }
29 // Creates a DnsSocketPool that implements the default strategy for managing
30 // sockets. (This varies by platform; see DnsSocketPoolImpl in
31 // dns_socket_pool.cc for details.)
32 static scoped_ptr<DnsSocketPool> CreateDefault(
33 ClientSocketFactory* factory);
35 // Creates a DnsSocketPool that implements a "null" strategy -- no sockets are
36 // preallocated, allocation requests are satisfied by calling the factory
37 // directly, and returned sockets are deleted immediately.
38 static scoped_ptr<DnsSocketPool> CreateNull(
39 ClientSocketFactory* factory);
41 // Initializes the DnsSocketPool. |nameservers| is the list of nameservers
42 // for which the DnsSocketPool will manage sockets; |net_log| is the NetLog
43 // used when constructing sockets with the factory.
45 // Initialize may not be called more than once, and must be called before
46 // calling AllocateSocket or FreeSocket.
47 virtual void Initialize(
48 const std::vector<IPEndPoint>* nameservers,
49 NetLog* net_log) = 0;
51 // Allocates a socket that is already connected to the nameserver referenced
52 // by |server_index|. May return a scoped_ptr to NULL if no sockets are
53 // available to reuse and the factory fails to produce a socket (or produces
54 // one on which Connect fails).
55 virtual scoped_ptr<DatagramClientSocket> AllocateSocket(
56 unsigned server_index) = 0;
58 // Frees a socket allocated by AllocateSocket. |server_index| must be the
59 // same index passed to AllocateSocket.
60 virtual void FreeSocket(
61 unsigned server_index,
62 scoped_ptr<DatagramClientSocket> socket) = 0;
64 // Creates a StreamSocket from the factory for a transaction over TCP. These
65 // sockets are not pooled.
66 scoped_ptr<StreamSocket> CreateTCPSocket(
67 unsigned server_index,
68 const NetLog::Source& source);
70 protected:
71 DnsSocketPool(ClientSocketFactory* socket_factory);
73 void InitializeInternal(
74 const std::vector<IPEndPoint>* nameservers,
75 NetLog* net_log);
77 scoped_ptr<DatagramClientSocket> CreateConnectedSocket(
78 unsigned server_index);
80 private:
81 ClientSocketFactory* socket_factory_;
82 NetLog* net_log_;
83 const std::vector<IPEndPoint>* nameservers_;
84 bool initialized_;
86 DISALLOW_COPY_AND_ASSIGN(DnsSocketPool);
89 } // namespace net
91 #endif // NET_DNS_DNS_SOCKET_POOL_H_