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 #ifndef NET_DNS_DNS_CLIENT_H_ | 5 #ifndef NET_DNS_DNS_CLIENT_H_ |
6 #define NET_DNS_DNS_CLIENT_H_ | 6 #define NET_DNS_DNS_CLIENT_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
| 11 #include "net/base/rand_callback.h" |
11 | 12 |
12 namespace net { | 13 namespace net { |
13 | 14 |
14 class AddressSorter; | 15 class AddressSorter; |
| 16 class ClientSocketFactory; |
15 struct DnsConfig; | 17 struct DnsConfig; |
16 class DnsTransactionFactory; | 18 class DnsTransactionFactory; |
17 class NetLog; | 19 class NetLog; |
18 | 20 |
19 // Convenience wrapper which allows easy injection of DnsTransaction into | 21 // Convenience wrapper which allows easy injection of DnsTransaction into |
20 // HostResolverImpl. Pointers returned by the Get* methods are only guaranteed | 22 // HostResolverImpl. Pointers returned by the Get* methods are only guaranteed |
21 // to remain valid until next time SetConfig is called. | 23 // to remain valid until next time SetConfig is called. |
22 class NET_EXPORT DnsClient { | 24 class NET_EXPORT DnsClient { |
23 public: | 25 public: |
24 virtual ~DnsClient() {} | 26 virtual ~DnsClient() {} |
25 | 27 |
26 // Destroys the current DnsTransactionFactory and creates a new one | 28 // Destroys the current DnsTransactionFactory and creates a new one |
27 // according to |config|, unless it is invalid or has |unhandled_options|. | 29 // according to |config|, unless it is invalid or has |unhandled_options|. |
28 virtual void SetConfig(const DnsConfig& config) = 0; | 30 virtual void SetConfig(const DnsConfig& config) = 0; |
29 | 31 |
30 // Returns NULL if the current config is not valid. | 32 // Returns NULL if the current config is not valid. |
31 virtual const DnsConfig* GetConfig() const = 0; | 33 virtual const DnsConfig* GetConfig() const = 0; |
32 | 34 |
33 // Returns NULL if the current config is not valid. | 35 // Returns NULL if the current config is not valid. |
34 virtual DnsTransactionFactory* GetTransactionFactory() = 0; | 36 virtual DnsTransactionFactory* GetTransactionFactory() = 0; |
35 | 37 |
36 // Returns NULL if the current config is not valid. | 38 // Returns NULL if the current config is not valid. |
37 virtual AddressSorter* GetAddressSorter() = 0; | 39 virtual AddressSorter* GetAddressSorter() = 0; |
38 | 40 |
39 // Creates default client. | 41 // Creates default client. |
40 static std::unique_ptr<DnsClient> CreateClient(NetLog* net_log); | 42 static std::unique_ptr<DnsClient> CreateClient(NetLog* net_log); |
| 43 |
| 44 // Creates a client for testing. Allows using a mock ClientSocketFactory and |
| 45 // a deterministic random number generator. |socket_factory| must outlive |
| 46 // the returned DnsClient. |
| 47 static std::unique_ptr<DnsClient> CreateClientForTesting( |
| 48 NetLog* net_log, |
| 49 ClientSocketFactory* socket_factory, |
| 50 const RandIntCallback& rand_int_callback); |
41 }; | 51 }; |
42 | 52 |
43 } // namespace net | 53 } // namespace net |
44 | 54 |
45 #endif // NET_DNS_DNS_CLIENT_H_ | 55 #endif // NET_DNS_DNS_CLIENT_H_ |
46 | 56 |
OLD | NEW |