Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "net/base/host_cache.h" | 11 #include "net/base/host_cache.h" |
| 12 #include "net/base/host_resolver.h" | 12 #include "net/base/host_resolver.h" |
| 13 #include "net/base/host_resolver_proc.h" | 13 #include "net/base/host_resolver_proc.h" |
| 14 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 | 16 |
| 17 // For each hostname that is requested, HostResolver creates a | 17 // For each hostname that is requested, HostResolver creates a |
| 18 // HostResolverImpl::Job. This job gets dispatched to a thread in the global | 18 // HostResolverImpl::Job. This job gets dispatched to a thread in the global |
| 19 // WorkerPool, where it runs SystemHostResolverProc(). If requests for that same | 19 // WorkerPool, where it runs SystemHostResolverProc(). If requests for that same |
| 20 // host are made while the job is already outstanding, then they are attached | 20 // host are made while the job is already outstanding, then they are attached |
| 21 // to the existing job rather than creating a new one. This avoids doing | 21 // to the existing job rather than creating a new one. This avoids doing |
| 22 // parallel resolves for the same host. | 22 // parallel resolves for the same host. |
| 23 // | 23 // |
| 24 // The way these classes fit together is illustrated by: | 24 // The way these classes fit together is illustrated by: |
| 25 // | 25 // |
| 26 // | 26 // |
| 27 // +----------- HostResolverImpl -------------+ | 27 // +----------- HostResolverImpl -------------+ |
| 28 // | | | | 28 // | | | |
| 29 // Job Job Job | 29 // Job Job Job |
| 30 // (for host1) (for host2) (for hostX) | 30 // (for host1, fam1) (for host2, fam2) (for hostx, famx) |
| 31 // / | | / | | / | | | 31 // / | | / | | / | | |
| 32 // Request ... Request Request ... Request Request ... Request | 32 // Request ... Request Request ... Request Request ... Request |
| 33 // (port1) (port2) (port3) (port4) (port5) (portX) | 33 // (port1) (port2) (port3) (port4) (port5) (portX) |
| 34 // | 34 // |
| 35 // | 35 // |
| 36 // When a HostResolverImpl::Job finishes its work in the threadpool, the | 36 // When a HostResolverImpl::Job finishes its work in the threadpool, the |
| 37 // callbacks of each waiting request are run on the origin thread. | 37 // callbacks of each waiting request are run on the origin thread. |
| 38 // | 38 // |
| 39 // Thread safety: This class is not threadsafe, and must only be called | 39 // Thread safety: This class is not threadsafe, and must only be called |
| 40 // from one thread! | 40 // from one thread! |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 63 RequestHandle* out_req, | 63 RequestHandle* out_req, |
| 64 LoadLog* load_log); | 64 LoadLog* load_log); |
| 65 virtual void CancelRequest(RequestHandle req); | 65 virtual void CancelRequest(RequestHandle req); |
| 66 virtual void AddObserver(Observer* observer); | 66 virtual void AddObserver(Observer* observer); |
| 67 virtual void RemoveObserver(Observer* observer); | 67 virtual void RemoveObserver(Observer* observer); |
| 68 virtual HostCache* GetHostCache(); | 68 virtual HostCache* GetHostCache(); |
| 69 | 69 |
| 70 // TODO(eroman): temp hack for http://crbug.com/15513 | 70 // TODO(eroman): temp hack for http://crbug.com/15513 |
| 71 virtual void Shutdown(); | 71 virtual void Shutdown(); |
| 72 | 72 |
| 73 // Prevents returning IPv6 addresses from Resolve(). | |
| 74 // The default is to allow IPv6 results. | |
| 75 virtual void DisableIPv6(bool disable_ipv6) { | |
| 76 disable_ipv6_ = disable_ipv6; | |
| 77 } | |
| 78 | |
| 73 private: | 79 private: |
| 74 class Job; | 80 class Job; |
| 75 class Request; | 81 class Request; |
| 76 typedef std::vector<Request*> RequestsList; | 82 typedef std::vector<Request*> RequestsList; |
| 77 typedef base::hash_map<std::string, scoped_refptr<Job> > JobMap; | 83 typedef HostCache::Key Key; |
| 84 typedef std::map<Key, scoped_refptr<Job> > JobMap; | |
| 78 typedef std::vector<Observer*> ObserversList; | 85 typedef std::vector<Observer*> ObserversList; |
| 79 | 86 |
| 80 // Returns the HostResolverProc to use for this instance. | 87 // Returns the HostResolverProc to use for this instance. |
| 81 HostResolverProc* effective_resolver_proc() const { | 88 HostResolverProc* effective_resolver_proc() const { |
| 82 return resolver_proc_ ? | 89 return resolver_proc_ ? |
| 83 resolver_proc_.get() : HostResolverProc::GetDefault(); | 90 resolver_proc_.get() : HostResolverProc::GetDefault(); |
| 84 } | 91 } |
| 85 | 92 |
| 86 // Adds a job to outstanding jobs list. | 93 // Adds a job to outstanding jobs list. |
| 87 void AddOutstandingJob(Job* job); | 94 void AddOutstandingJob(Job* job); |
| 88 | 95 |
| 89 // Returns the outstanding job for |hostname|, or NULL if there is none. | 96 // Returns the outstanding job for |key|, or NULL if there is none. |
| 90 Job* FindOutstandingJob(const std::string& hostname); | 97 Job* FindOutstandingJob(const Key& key); |
| 91 | 98 |
| 92 // Removes |job| from the outstanding jobs list. | 99 // Removes |job| from the outstanding jobs list. |
| 93 void RemoveOutstandingJob(Job* job); | 100 void RemoveOutstandingJob(Job* job); |
| 94 | 101 |
| 95 // Callback for when |job| has completed with |error| and |addrlist|. | 102 // Callback for when |job| has completed with |error| and |addrlist|. |
| 96 void OnJobComplete(Job* job, int error, const AddressList& addrlist); | 103 void OnJobComplete(Job* job, int error, const AddressList& addrlist); |
| 97 | 104 |
| 98 // Called when a request has just been started. | 105 // Called when a request has just been started. |
| 99 void OnStartRequest(LoadLog* load_log, | 106 void OnStartRequest(LoadLog* load_log, |
| 100 int request_id, | 107 int request_id, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 125 ObserversList observers_; | 132 ObserversList observers_; |
| 126 | 133 |
| 127 // Monotonically increasing ID number to assign to the next request. | 134 // Monotonically increasing ID number to assign to the next request. |
| 128 // Observers are the only consumers of this ID number. | 135 // Observers are the only consumers of this ID number. |
| 129 int next_request_id_; | 136 int next_request_id_; |
| 130 | 137 |
| 131 // The procedure to use for resolving host names. This will be NULL, except | 138 // The procedure to use for resolving host names. This will be NULL, except |
| 132 // in the case of unit-tests which inject custom host resolving behaviors. | 139 // in the case of unit-tests which inject custom host resolving behaviors. |
| 133 scoped_refptr<HostResolverProc> resolver_proc_; | 140 scoped_refptr<HostResolverProc> resolver_proc_; |
| 134 | 141 |
| 142 // Set to true if only IPv4 address are to be returned by Resolve(). | |
| 143 bool disable_ipv6_; | |
|
Lorenzo Colitti
2009/10/21 23:14:08
Instead, why not make this be "int desired_address
eroman
2009/10/21 23:32:07
Done.
See proposed change here: http://codereview
| |
| 144 | |
| 135 // TODO(eroman): temp hack for http://crbug.com/15513 | 145 // TODO(eroman): temp hack for http://crbug.com/15513 |
| 136 bool shutdown_; | 146 bool shutdown_; |
| 137 | 147 |
| 138 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); | 148 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); |
| 139 }; | 149 }; |
| 140 | 150 |
| 141 } // namespace net | 151 } // namespace net |
| 142 | 152 |
| 143 #endif // NET_BASE_HOST_RESOLVER_IMPL_H_ | 153 #endif // NET_BASE_HOST_RESOLVER_IMPL_H_ |
| OLD | NEW |