| 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_HOST_RESOLVER_IMPL_H_ | 5 #ifndef NET_BASE_HOST_RESOLVER_IMPL_H_ |
| 6 #define NET_BASE_HOST_RESOLVER_IMPL_H_ | 6 #define NET_BASE_HOST_RESOLVER_IMPL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // ERR_HOST_RESOLVER_QUEUE_TOO_LARGE. | 130 // ERR_HOST_RESOLVER_QUEUE_TOO_LARGE. |
| 131 void SetPoolConstraints(JobPoolIndex pool_index, | 131 void SetPoolConstraints(JobPoolIndex pool_index, |
| 132 size_t max_outstanding_jobs, | 132 size_t max_outstanding_jobs, |
| 133 size_t max_pending_requests); | 133 size_t max_pending_requests); |
| 134 | 134 |
| 135 // HostResolver methods: | 135 // HostResolver methods: |
| 136 virtual int Resolve(const RequestInfo& info, | 136 virtual int Resolve(const RequestInfo& info, |
| 137 AddressList* addresses, | 137 AddressList* addresses, |
| 138 CompletionCallback* callback, | 138 CompletionCallback* callback, |
| 139 RequestHandle* out_req, | 139 RequestHandle* out_req, |
| 140 const BoundNetLog& source_net_log); | 140 const BoundNetLog& source_net_log) OVERRIDE; |
| 141 virtual void CancelRequest(RequestHandle req); | 141 virtual int ResolveFromCache(const RequestInfo& info, |
| 142 virtual void AddObserver(HostResolver::Observer* observer); | 142 AddressList* addresses, |
| 143 virtual void RemoveObserver(HostResolver::Observer* observer); | 143 const BoundNetLog& source_net_log) OVERRIDE; |
| 144 virtual void CancelRequest(RequestHandle req) OVERRIDE; |
| 145 virtual void AddObserver(HostResolver::Observer* observer) OVERRIDE; |
| 146 virtual void RemoveObserver(HostResolver::Observer* observer) OVERRIDE; |
| 144 | 147 |
| 145 // Set address family, and disable IPv6 probe support. | 148 // Set address family, and disable IPv6 probe support. |
| 146 virtual void SetDefaultAddressFamily(AddressFamily address_family); | 149 virtual void SetDefaultAddressFamily(AddressFamily address_family) OVERRIDE; |
| 147 virtual AddressFamily GetDefaultAddressFamily() const; | 150 virtual AddressFamily GetDefaultAddressFamily() const OVERRIDE; |
| 148 | 151 |
| 149 virtual HostResolverImpl* GetAsHostResolverImpl(); | 152 virtual HostResolverImpl* GetAsHostResolverImpl() OVERRIDE; |
| 150 | 153 |
| 151 private: | 154 private: |
| 152 // Allow tests to access our innards for testing purposes. | 155 // Allow tests to access our innards for testing purposes. |
| 153 friend class LookupAttemptHostResolverProc; | 156 friend class LookupAttemptHostResolverProc; |
| 154 | 157 |
| 155 // Allow tests to access our innards for testing purposes. | 158 // Allow tests to access our innards for testing purposes. |
| 156 FRIEND_TEST_ALL_PREFIXES(HostResolverImplTest, MultipleAttempts); | 159 FRIEND_TEST_ALL_PREFIXES(HostResolverImplTest, MultipleAttempts); |
| 157 | 160 |
| 158 class Job; | 161 class Job; |
| 159 class JobPool; | 162 class JobPool; |
| 160 class IPv6ProbeJob; | 163 class IPv6ProbeJob; |
| 161 class Request; | 164 class Request; |
| 162 typedef std::vector<Request*> RequestsList; | 165 typedef std::vector<Request*> RequestsList; |
| 163 typedef HostCache::Key Key; | 166 typedef HostCache::Key Key; |
| 164 typedef std::map<Key, scoped_refptr<Job> > JobMap; | 167 typedef std::map<Key, scoped_refptr<Job> > JobMap; |
| 165 typedef std::vector<HostResolver::Observer*> ObserversList; | 168 typedef std::vector<HostResolver::Observer*> ObserversList; |
| 166 | 169 |
| 170 // Helper used by |Resolve()| and |ResolveFromCache()|. Performs IP |
| 171 // literal and cache lookup, returns OK if successfull, |
| 172 // ERR_NAME_NOT_RESOLVED if either hostname is invalid or IP literal is |
| 173 // incompatible, ERR_DNS_CACHE_MISS if entry was not found in cache. |
| 174 int ResolveHelper(int request_id, |
| 175 const Key& key, |
| 176 const RequestInfo& info, |
| 177 AddressList* addresses, |
| 178 const BoundNetLog& request_net_log, |
| 179 const BoundNetLog& source_net_log); |
| 180 |
| 181 // Tries to resolve |key| as an IP, returns true and sets |net_error| if |
| 182 // succeeds, returns false otherwise. |
| 183 bool ResolveAsIP(const Key& key, |
| 184 const RequestInfo& info, |
| 185 int* net_error, |
| 186 AddressList* addresses); |
| 187 |
| 188 // If |key| is not found in cache returns false, otherwise returns |
| 189 // true, sets |net_error| to the cached error code and fills |addresses| |
| 190 // if it is a positive entry. |
| 191 bool ServeFromCache(const Key& key, |
| 192 const RequestInfo& info, |
| 193 const BoundNetLog& request_net_log, |
| 194 int* net_error, |
| 195 AddressList* addresses); |
| 196 |
| 167 // Returns the HostResolverProc to use for this instance. | 197 // Returns the HostResolverProc to use for this instance. |
| 168 HostResolverProc* effective_resolver_proc() const { | 198 HostResolverProc* effective_resolver_proc() const { |
| 169 return resolver_proc_ ? | 199 return resolver_proc_ ? |
| 170 resolver_proc_.get() : HostResolverProc::GetDefault(); | 200 resolver_proc_.get() : HostResolverProc::GetDefault(); |
| 171 } | 201 } |
| 172 | 202 |
| 173 // Adds a job to outstanding jobs list. | 203 // Adds a job to outstanding jobs list. |
| 174 void AddOutstandingJob(Job* job); | 204 void AddOutstandingJob(Job* job); |
| 175 | 205 |
| 176 // Returns the outstanding job for |key|, or NULL if there is none. | 206 // Returns the outstanding job for |key|, or NULL if there is none. |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 HostResolverFlags additional_resolver_flags_; | 364 HostResolverFlags additional_resolver_flags_; |
| 335 | 365 |
| 336 NetLog* net_log_; | 366 NetLog* net_log_; |
| 337 | 367 |
| 338 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); | 368 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); |
| 339 }; | 369 }; |
| 340 | 370 |
| 341 } // namespace net | 371 } // namespace net |
| 342 | 372 |
| 343 #endif // NET_BASE_HOST_RESOLVER_IMPL_H_ | 373 #endif // NET_BASE_HOST_RESOLVER_IMPL_H_ |
| OLD | NEW |