Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_ASYNC_HOST_RESOLVER_H_ | 5 #ifndef NET_DNS_ASYNC_HOST_RESOLVER_H_ |
| 6 #define NET_DNS_ASYNC_HOST_RESOLVER_H_ | 6 #define NET_DNS_ASYNC_HOST_RESOLVER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <string> | |
| 12 #include <utility> | |
| 11 | 13 |
| 12 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
| 13 #include "net/base/address_family.h" | 15 #include "net/base/address_family.h" |
| 14 #include "net/base/host_cache.h" | 16 #include "net/base/host_cache.h" |
| 15 #include "net/base/host_resolver.h" | 17 #include "net/base/host_resolver.h" |
| 16 #include "net/base/ip_endpoint.h" | 18 #include "net/base/ip_endpoint.h" |
| 17 #include "net/base/net_log.h" | 19 #include "net/base/net_log.h" |
| 18 #include "net/base/rand_callback.h" | 20 #include "net/dns/dns_client.h" |
| 19 #include "net/dns/dns_transaction.h" | |
| 20 | 21 |
| 21 namespace net { | 22 namespace net { |
| 22 | 23 |
| 23 class ClientSocketFactory; | |
| 24 | |
| 25 class NET_EXPORT AsyncHostResolver | 24 class NET_EXPORT AsyncHostResolver |
| 26 : public HostResolver, | 25 : public HostResolver, |
| 27 public DnsTransaction::Delegate, | |
| 28 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 26 NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 29 public: | 27 public: |
| 30 AsyncHostResolver(const IPEndPoint& dns_server, | 28 AsyncHostResolver(size_t max_transactions, |
| 31 size_t max_transactions, | |
| 32 size_t max_pending_requests_, | 29 size_t max_pending_requests_, |
|
mmenke
2011/12/02 00:53:55
Know this was already here, but while you're modif
szym
2011/12/05 23:06:28
Done.
| |
| 33 const RandIntCallback& rand_int, | |
| 34 HostCache* cache, | 30 HostCache* cache, |
| 35 ClientSocketFactory* factory, | 31 DnsClient* client, |
| 36 NetLog* net_log); | 32 NetLog* net_log); |
| 37 virtual ~AsyncHostResolver(); | 33 virtual ~AsyncHostResolver(); |
| 38 | 34 |
| 39 // HostResolver interface | 35 // HostResolver interface |
| 40 virtual int Resolve(const RequestInfo& info, | 36 virtual int Resolve(const RequestInfo& info, |
| 41 AddressList* addresses, | 37 AddressList* addresses, |
| 42 const CompletionCallback& callback, | 38 const CompletionCallback& callback, |
| 43 RequestHandle* out_req, | 39 RequestHandle* out_req, |
| 44 const BoundNetLog& source_net_log) OVERRIDE; | 40 const BoundNetLog& source_net_log) OVERRIDE; |
| 45 virtual int ResolveFromCache(const RequestInfo& info, | 41 virtual int ResolveFromCache(const RequestInfo& info, |
| 46 AddressList* addresses, | 42 AddressList* addresses, |
| 47 const BoundNetLog& source_net_log) OVERRIDE; | 43 const BoundNetLog& source_net_log) OVERRIDE; |
| 48 virtual void CancelRequest(RequestHandle req_handle) OVERRIDE; | 44 virtual void CancelRequest(RequestHandle req_handle) OVERRIDE; |
| 49 virtual void SetDefaultAddressFamily(AddressFamily address_family) OVERRIDE; | 45 virtual void SetDefaultAddressFamily(AddressFamily address_family) OVERRIDE; |
| 50 virtual AddressFamily GetDefaultAddressFamily() const OVERRIDE; | 46 virtual AddressFamily GetDefaultAddressFamily() const OVERRIDE; |
| 51 virtual HostCache* GetHostCache() OVERRIDE; | 47 virtual HostCache* GetHostCache() OVERRIDE; |
| 52 | 48 |
| 53 // DnsTransaction::Delegate interface | 49 virtual void OnRequestComplete(DnsClient::Request* request, |
| 54 virtual void OnTransactionComplete( | 50 int result, |
| 55 int result, | 51 const DnsResponse* transaction); |
|
mmenke
2011/12/02 00:53:55
OVERRIDE
szym
2011/12/05 23:06:28
DnsTransaction no longer defines a Delegate interf
mmenke
2011/12/06 18:08:39
Ah, right. Don't think it needs to be virtual, ei
| |
| 56 const DnsTransaction* transaction, | |
| 57 const IPAddressList& ip_addresses) OVERRIDE; | |
| 58 | 52 |
| 59 private: | 53 private: |
| 60 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, QueuedLookup); | 54 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, QueuedLookup); |
| 61 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, CancelPendingLookup); | 55 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, CancelPendingLookup); |
| 62 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, | 56 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, |
| 63 ResolverDestructionCancelsLookups); | 57 ResolverDestructionCancelsLookups); |
| 64 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, | 58 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, |
| 65 OverflowQueueWithLowPriorityLookup); | 59 OverflowQueueWithLowPriorityLookup); |
| 66 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, | 60 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, |
| 67 OverflowQueueWithHighPriorityLookup); | 61 OverflowQueueWithHighPriorityLookup); |
| 68 | 62 |
| 69 class Request; | 63 class Request; |
| 70 | 64 |
| 71 typedef DnsTransaction::Key Key; | 65 typedef std::pair<std::string, uint16> Key; |
| 72 typedef std::list<Request*> RequestList; | 66 typedef std::list<Request*> RequestList; |
| 73 typedef std::list<const DnsTransaction*> TransactionList; | 67 typedef std::list<const DnsClient::Request*> TransactionList; |
| 74 typedef std::map<Key, RequestList> KeyRequestListMap; | 68 typedef std::map<Key, RequestList> KeyRequestListMap; |
| 75 | 69 |
| 76 // Create a new request for the incoming Resolve() call. | 70 // Create a new request for the incoming Resolve() call. |
| 77 Request* CreateNewRequest(const RequestInfo& info, | 71 Request* CreateNewRequest(const RequestInfo& info, |
| 78 const CompletionCallback& callback, | 72 const CompletionCallback& callback, |
| 79 AddressList* addresses, | 73 AddressList* addresses, |
| 80 const BoundNetLog& source_net_log); | 74 const BoundNetLog& source_net_log); |
| 81 | 75 |
| 82 // Called when a request has just been started. | 76 // Called when a request has just been started. |
| 83 void OnStart(Request* request); | 77 void OnStart(Request* request); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 111 Request* RemoveHighest(); | 105 Request* RemoveHighest(); |
| 112 | 106 |
| 113 // Once a transaction has completed, called to start a new transaction if | 107 // Once a transaction has completed, called to start a new transaction if |
| 114 // there are pending requests. | 108 // there are pending requests. |
| 115 void ProcessPending(); | 109 void ProcessPending(); |
| 116 | 110 |
| 117 // Maximum number of concurrent transactions. | 111 // Maximum number of concurrent transactions. |
| 118 size_t max_transactions_; | 112 size_t max_transactions_; |
| 119 | 113 |
| 120 // List of current transactions. | 114 // List of current transactions. |
| 121 TransactionList transactions_; | 115 TransactionList dns_requests_; |
|
mmenke
2011/12/02 00:53:55
I think overload requests to both mean requests to
| |
| 122 | 116 |
| 123 // A map from Key to a list of requests waiting for the Key to resolve. | 117 // A map from Key to a list of requests waiting for the Key to resolve. |
| 124 KeyRequestListMap requestlist_map_; | 118 KeyRequestListMap requestlist_map_; |
| 125 | 119 |
| 126 // Maximum number of pending requests. | 120 // Maximum number of pending requests. |
| 127 size_t max_pending_requests_; | 121 size_t max_pending_requests_; |
| 128 | 122 |
| 129 // Queues based on priority for putting pending requests. | 123 // Queues based on priority for putting pending requests. |
| 130 RequestList pending_requests_[NUM_PRIORITIES]; | 124 RequestList pending_requests_[NUM_PRIORITIES]; |
| 131 | 125 |
| 132 // DNS server to which queries will be setn. | |
| 133 IPEndPoint dns_server_; | |
| 134 | |
| 135 // Callback to be passed to DnsTransaction for generating DNS query ids. | |
| 136 RandIntCallback rand_int_cb_; | |
| 137 | |
| 138 // Cache of host resolution results. | 126 // Cache of host resolution results. |
| 139 scoped_ptr<HostCache> cache_; | 127 scoped_ptr<HostCache> cache_; |
| 140 | 128 |
| 141 // Also passed to DnsTransaction; it's a dependency injection to aid | 129 DnsClient* client_; |
| 142 // testing, outside of unit tests, its value is always NULL. | |
| 143 ClientSocketFactory* factory_; | |
| 144 | 130 |
| 145 NetLog* net_log_; | 131 NetLog* net_log_; |
| 146 | 132 |
| 147 DISALLOW_COPY_AND_ASSIGN(AsyncHostResolver); | 133 DISALLOW_COPY_AND_ASSIGN(AsyncHostResolver); |
| 148 }; | 134 }; |
| 149 | 135 |
| 150 } // namespace net | 136 } // namespace net |
| 151 | 137 |
| 152 #endif // NET_DNS_ASYNC_HOST_RESOLVER_H_ | 138 #endif // NET_DNS_ASYNC_HOST_RESOLVER_H_ |
| OLD | NEW |