 Chromium Code Reviews
 Chromium Code Reviews Issue 9190031:
  DnsClient refactoring + features (timeout, suffix search, server rotation).  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 9190031:
  DnsClient refactoring + features (timeout, suffix search, server rotation).  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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> | 11 #include <string> | 
| 12 #include <utility> | 12 #include <utility> | 
| 13 | 13 | 
| 14 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" | 
| 15 #include "net/base/address_family.h" | 15 #include "net/base/address_family.h" | 
| 16 #include "net/base/host_cache.h" | 16 #include "net/base/host_cache.h" | 
| 17 #include "net/base/host_resolver.h" | 17 #include "net/base/host_resolver.h" | 
| 18 #include "net/base/ip_endpoint.h" | 18 #include "net/base/ip_endpoint.h" | 
| 19 #include "net/base/net_log.h" | 19 #include "net/base/net_log.h" | 
| 20 #include "net/dns/dns_client.h" | 20 #include "net/dns/dns_transaction.h" | 
| 21 | 21 | 
| 22 namespace net { | 22 namespace net { | 
| 23 | 23 | 
| 24 class NET_EXPORT AsyncHostResolver | 24 class NET_EXPORT AsyncHostResolver | 
| 25 : public HostResolver, | 25 : public HostResolver, | 
| 26 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 26 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 
| 27 public: | 27 public: | 
| 28 AsyncHostResolver(size_t max_dns_requests, | 28 AsyncHostResolver(size_t max_dns_requests, | 
| 29 size_t max_pending_requests, | 29 size_t max_pending_requests, | 
| 30 HostCache* cache, | 30 HostCache* cache, | 
| 31 DnsClient* client, | 31 scoped_ptr<DnsTransactionFactory> client, | 
| 32 NetLog* net_log); | 32 NetLog* net_log); | 
| 33 virtual ~AsyncHostResolver(); | 33 virtual ~AsyncHostResolver(); | 
| 34 | 34 | 
| 35 // HostResolver interface | 35 // HostResolver interface | 
| 36 virtual int Resolve(const RequestInfo& info, | 36 virtual int Resolve(const RequestInfo& info, | 
| 37 AddressList* addresses, | 37 AddressList* addresses, | 
| 38 const CompletionCallback& callback, | 38 const CompletionCallback& callback, | 
| 39 RequestHandle* out_req, | 39 RequestHandle* out_req, | 
| 40 const BoundNetLog& source_net_log) OVERRIDE; | 40 const BoundNetLog& source_net_log) OVERRIDE; | 
| 41 virtual int ResolveFromCache(const RequestInfo& info, | 41 virtual int ResolveFromCache(const RequestInfo& info, | 
| 42 AddressList* addresses, | 42 AddressList* addresses, | 
| 43 const BoundNetLog& source_net_log) OVERRIDE; | 43 const BoundNetLog& source_net_log) OVERRIDE; | 
| 44 virtual void CancelRequest(RequestHandle req_handle) OVERRIDE; | 44 virtual void CancelRequest(RequestHandle req_handle) OVERRIDE; | 
| 45 virtual void SetDefaultAddressFamily(AddressFamily address_family) OVERRIDE; | 45 virtual void SetDefaultAddressFamily(AddressFamily address_family) OVERRIDE; | 
| 46 virtual AddressFamily GetDefaultAddressFamily() const OVERRIDE; | 46 virtual AddressFamily GetDefaultAddressFamily() const OVERRIDE; | 
| 47 virtual HostCache* GetHostCache() OVERRIDE; | 47 virtual HostCache* GetHostCache() OVERRIDE; | 
| 48 | 48 | 
| 49 void OnDnsRequestComplete(DnsClient::Request* request, | 49 void OnDnsTransactionComplete(DnsTransaction* transaction, | 
| 50 int result, | 50 int result, | 
| 51 const DnsResponse* transaction); | 51 const DnsResponse* response); | 
| 52 | 52 | 
| 53 private: | 53 private: | 
| 54 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, QueuedLookup); | 54 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, QueuedLookup); | 
| 55 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, CancelPendingLookup); | 55 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, CancelPendingLookup); | 
| 56 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, | 56 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, | 
| 57 ResolverDestructionCancelsLookups); | 57 ResolverDestructionCancelsLookups); | 
| 58 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, | 58 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, | 
| 59 OverflowQueueWithLowPriorityLookup); | 59 OverflowQueueWithLowPriorityLookup); | 
| 60 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, | 60 FRIEND_TEST_ALL_PREFIXES(AsyncHostResolverTest, | 
| 61 OverflowQueueWithHighPriorityLookup); | 61 OverflowQueueWithHighPriorityLookup); | 
| 62 | 62 | 
| 63 class Request; | 63 class Request; | 
| 64 | 64 | 
| 65 typedef std::pair<std::string, uint16> Key; | 65 typedef std::pair<std::string, uint16> Key; | 
| 66 typedef std::list<Request*> RequestList; | 66 typedef std::list<Request*> RequestList; | 
| 67 typedef std::list<const DnsClient::Request*> DnsRequestList; | 67 typedef std::list<const DnsTransaction*> DnsTransactionList; | 
| 68 typedef std::map<Key, RequestList> KeyRequestListMap; | 68 typedef std::map<Key, RequestList> KeyRequestListMap; | 
| 69 | 69 | 
| 70 // Create a new request for the incoming Resolve() call. | 70 // Create a new request for the incoming Resolve() call. | 
| 71 Request* CreateNewRequest(const RequestInfo& info, | 71 Request* CreateNewRequest(const RequestInfo& info, | 
| 72 const CompletionCallback& callback, | 72 const CompletionCallback& callback, | 
| 73 AddressList* addresses, | 73 AddressList* addresses, | 
| 74 const BoundNetLog& source_net_log); | 74 const BoundNetLog& source_net_log); | 
| 75 | 75 | 
| 76 // Called when a request has just been started. | 76 // Called when a request has just been started. | 
| 77 void OnStart(Request* request); | 77 void OnStart(Request* request); | 
| (...skipping 24 matching lines...) Expand all Loading... | |
| 102 // Removes and returns a pointer to the lowest/highest priority request | 102 // Removes and returns a pointer to the lowest/highest priority request | 
| 103 // from |pending_requests_|. | 103 // from |pending_requests_|. | 
| 104 Request* RemoveLowest(); | 104 Request* RemoveLowest(); | 
| 105 Request* RemoveHighest(); | 105 Request* RemoveHighest(); | 
| 106 | 106 | 
| 107 // 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 | 
| 108 // there are pending requests. | 108 // there are pending requests. | 
| 109 void ProcessPending(); | 109 void ProcessPending(); | 
| 110 | 110 | 
| 111 // Maximum number of concurrent DNS requests. | 111 // Maximum number of concurrent DNS requests. | 
| 112 size_t max_dns_requests_; | 112 size_t max_dns_requests_; | 
| 
mmenke
2012/01/19 17:24:47
nit:  max_dns_transactions
 | |
| 113 | 113 | 
| 114 // List of current DNS requests. | 114 // List of current DNS requests. | 
| 115 DnsRequestList dns_requests_; | 115 DnsTransactionList dns_requests_; | 
| 
mmenke
2012/01/19 17:24:47
nit:  dns_transactions_
 | |
| 116 | 116 | 
| 117 // 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. | 
| 118 KeyRequestListMap requestlist_map_; | 118 KeyRequestListMap requestlist_map_; | 
| 119 | 119 | 
| 120 // Maximum number of pending requests. | 120 // Maximum number of pending requests. | 
| 121 size_t max_pending_requests_; | 121 size_t max_pending_requests_; | 
| 122 | 122 | 
| 123 // Queues based on priority for putting pending requests. | 123 // Queues based on priority for putting pending requests. | 
| 124 RequestList pending_requests_[NUM_PRIORITIES]; | 124 RequestList pending_requests_[NUM_PRIORITIES]; | 
| 125 | 125 | 
| 126 // Cache of host resolution results. | 126 // Cache of host resolution results. | 
| 127 scoped_ptr<HostCache> cache_; | 127 scoped_ptr<HostCache> cache_; | 
| 128 | 128 | 
| 129 DnsClient* client_; | 129 scoped_ptr<DnsTransactionFactory> client_; | 
| 130 | 130 | 
| 131 NetLog* net_log_; | 131 NetLog* net_log_; | 
| 132 | 132 | 
| 133 DISALLOW_COPY_AND_ASSIGN(AsyncHostResolver); | 133 DISALLOW_COPY_AND_ASSIGN(AsyncHostResolver); | 
| 134 }; | 134 }; | 
| 135 | 135 | 
| 136 } // namespace net | 136 } // namespace net | 
| 137 | 137 | 
| 138 #endif // NET_DNS_ASYNC_HOST_RESOLVER_H_ | 138 #endif // NET_DNS_ASYNC_HOST_RESOLVER_H_ | 
| OLD | NEW |