| 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_BASE_ASYNC_HOST_RESOLVER_H_ | 5 #ifndef NET_BASE_ASYNC_HOST_RESOLVER_H_ |
| 6 #define NET_BASE_ASYNC_HOST_RESOLVER_H_ | 6 #define NET_BASE_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 <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 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/dns_transaction.h" | 16 #include "net/base/dns_transaction.h" |
| 17 #include "net/base/host_cache.h" |
| 17 #include "net/base/host_resolver.h" | 18 #include "net/base/host_resolver.h" |
| 18 #include "net/base/ip_endpoint.h" | 19 #include "net/base/ip_endpoint.h" |
| 19 #include "net/base/net_log.h" | 20 #include "net/base/net_log.h" |
| 20 #include "net/base/rand_callback.h" | 21 #include "net/base/rand_callback.h" |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| 23 | 24 |
| 24 class AddressesList; | 25 class AddressesList; |
| 25 class ClientSocketFactory; | 26 class ClientSocketFactory; |
| 26 | 27 |
| 27 class NET_API AsyncHostResolver | 28 class NET_API AsyncHostResolver |
| 28 : public HostResolver, | 29 : public HostResolver, |
| 29 public DnsTransaction::Delegate, | 30 public DnsTransaction::Delegate, |
| 30 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 31 NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 31 public: | 32 public: |
| 32 AsyncHostResolver(const IPEndPoint& dns_server, | 33 AsyncHostResolver(const IPEndPoint& dns_server, |
| 33 size_t max_transactions, | 34 size_t max_transactions, |
| 34 size_t max_pending_requests_, | 35 size_t max_pending_requests_, |
| 35 const RandIntCallback& rand_int, | 36 const RandIntCallback& rand_int, |
| 37 HostCache* cache, |
| 36 ClientSocketFactory* factory, | 38 ClientSocketFactory* factory, |
| 37 NetLog* net_log); | 39 NetLog* net_log); |
| 38 virtual ~AsyncHostResolver(); | 40 virtual ~AsyncHostResolver(); |
| 39 | 41 |
| 40 // HostResolver interface | 42 // HostResolver interface |
| 41 virtual int Resolve(const RequestInfo& info, | 43 virtual int Resolve(const RequestInfo& info, |
| 42 AddressList* addresses, | 44 AddressList* addresses, |
| 43 CompletionCallback* callback, | 45 CompletionCallback* callback, |
| 44 RequestHandle* out_req, | 46 RequestHandle* out_req, |
| 45 const BoundNetLog& source_net_log) OVERRIDE; | 47 const BoundNetLog& source_net_log) OVERRIDE; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 84 |
| 83 // Called when a request has just been started. | 85 // Called when a request has just been started. |
| 84 void OnStart(Request* request); | 86 void OnStart(Request* request); |
| 85 | 87 |
| 86 // Called when a request has just completed (before its callback is run). | 88 // Called when a request has just completed (before its callback is run). |
| 87 void OnFinish(Request* request, int result); | 89 void OnFinish(Request* request, int result); |
| 88 | 90 |
| 89 // Called when a request has been cancelled. | 91 // Called when a request has been cancelled. |
| 90 void OnCancel(Request* request); | 92 void OnCancel(Request* request); |
| 91 | 93 |
| 94 // Tries to serve request from cache. |
| 95 bool ServeFromCache(Request* request) const; |
| 96 |
| 92 // If there is an in-progress transaction for Request->key(), this will | 97 // If there is an in-progress transaction for Request->key(), this will |
| 93 // attach |request| to the respective list. | 98 // attach |request| to the respective list. |
| 94 bool AttachToRequestList(Request* request); | 99 bool AttachToRequestList(Request* request); |
| 95 | 100 |
| 96 // Will start a new transaction for |request|, will insert a new key in | 101 // Will start a new transaction for |request|, will insert a new key in |
| 97 // |requestlist_map_| and append |request| to the respective list. | 102 // |requestlist_map_| and append |request| to the respective list. |
| 98 int StartNewTransactionFor(Request* request); | 103 int StartNewTransactionFor(Request* request); |
| 99 | 104 |
| 100 // Will enqueue |request| in |pending_requests_|. | 105 // Will enqueue |request| in |pending_requests_|. |
| 101 int Enqueue(Request* request); | 106 int Enqueue(Request* request); |
| 102 | 107 |
| 103 // A helper used by Enqueue to insert |request| into |pending_requests_|. | 108 // A helper used by Enqueue to insert |request| into |pending_requests_|. |
| 104 Request* Insert(Request* request); | 109 Request* Insert(Request* request); |
| 105 | 110 |
| 106 // Returns the number of pending requests. | 111 // Returns the number of pending requests. |
| 107 size_t GetNumPending(); | 112 size_t GetNumPending() const; |
| 108 | 113 |
| 109 // Removes and returns a pointer to the lowest/highest priority request | 114 // Removes and returns a pointer to the lowest/highest priority request |
| 110 // from |pending_requests_|. | 115 // from |pending_requests_|. |
| 111 Request* RemoveLowest(); | 116 Request* RemoveLowest(); |
| 112 Request* RemoveHighest(); | 117 Request* RemoveHighest(); |
| 113 | 118 |
| 114 // Once a transaction has completed, called to start a new transaction if | 119 // Once a transaction has completed, called to start a new transaction if |
| 115 // there are pending requests. | 120 // there are pending requests. |
| 116 void ProcessPending(); | 121 void ProcessPending(); |
| 117 | 122 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 129 | 134 |
| 130 // Queues based on priority for putting pending requests. | 135 // Queues based on priority for putting pending requests. |
| 131 RequestList pending_requests_[NUM_PRIORITIES]; | 136 RequestList pending_requests_[NUM_PRIORITIES]; |
| 132 | 137 |
| 133 // DNS server to which queries will be setn. | 138 // DNS server to which queries will be setn. |
| 134 IPEndPoint dns_server_; | 139 IPEndPoint dns_server_; |
| 135 | 140 |
| 136 // Callback to be passed to DnsTransaction for generating DNS query ids. | 141 // Callback to be passed to DnsTransaction for generating DNS query ids. |
| 137 RandIntCallback rand_int_cb_; | 142 RandIntCallback rand_int_cb_; |
| 138 | 143 |
| 144 // Cache of host resolution results. |
| 145 scoped_ptr<HostCache> cache_; |
| 146 |
| 139 // Also passed to DnsTransaction; it's a dependency injection to aid | 147 // Also passed to DnsTransaction; it's a dependency injection to aid |
| 140 // testing, outside of unit tests, its value is always NULL. | 148 // testing, outside of unit tests, its value is always NULL. |
| 141 ClientSocketFactory* factory_; | 149 ClientSocketFactory* factory_; |
| 142 | 150 |
| 143 // The observers to notify when a request starts/ends. | 151 // The observers to notify when a request starts/ends. |
| 144 ObserverList<HostResolver::Observer> observers_; | 152 ObserverList<HostResolver::Observer> observers_; |
| 145 | 153 |
| 146 // Monotonically increasing ID number to assign to the next request. | 154 // Monotonically increasing ID number to assign to the next request. |
| 147 // Observers are the only consumers of this ID number. | 155 // Observers are the only consumers of this ID number. |
| 148 int next_request_id_; | 156 int next_request_id_; |
| 149 | 157 |
| 150 NetLog* net_log_; | 158 NetLog* net_log_; |
| 151 | 159 |
| 152 DISALLOW_COPY_AND_ASSIGN(AsyncHostResolver); | 160 DISALLOW_COPY_AND_ASSIGN(AsyncHostResolver); |
| 153 }; | 161 }; |
| 154 | 162 |
| 155 } // namespace net | 163 } // namespace net |
| 156 | 164 |
| 157 #endif // NET_BASE_ASYNC_HOST_RESOLVER_H_ | 165 #endif // NET_BASE_ASYNC_HOST_RESOLVER_H_ |
| OLD | NEW |