| 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 "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "net/base/host_cache.h" | 12 #include "net/base/host_cache.h" |
| 13 #include "net/base/host_resolver.h" | 13 #include "net/base/host_resolver.h" |
| 14 #include "net/base/host_resolver_proc.h" | 14 #include "net/base/host_resolver_proc.h" |
| 15 #include "net/base/net_log.h" |
| 15 #include "net/base/network_change_notifier.h" | 16 #include "net/base/network_change_notifier.h" |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 | 19 |
| 19 // For each hostname that is requested, HostResolver creates a | 20 // For each hostname that is requested, HostResolver creates a |
| 20 // HostResolverImpl::Job. This job gets dispatched to a thread in the global | 21 // HostResolverImpl::Job. This job gets dispatched to a thread in the global |
| 21 // WorkerPool, where it runs SystemHostResolverProc(). If requests for that same | 22 // WorkerPool, where it runs SystemHostResolverProc(). If requests for that same |
| 22 // host are made while the job is already outstanding, then they are attached | 23 // host are made while the job is already outstanding, then they are attached |
| 23 // to the existing job rather than creating a new one. This avoids doing | 24 // to the existing job rather than creating a new one. This avoids doing |
| 24 // parallel resolves for the same host. | 25 // parallel resolves for the same host. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 HostResolverImpl(HostResolverProc* resolver_proc, | 77 HostResolverImpl(HostResolverProc* resolver_proc, |
| 77 HostCache* cache, | 78 HostCache* cache, |
| 78 NetworkChangeNotifier* notifier, | 79 NetworkChangeNotifier* notifier, |
| 79 size_t max_jobs); | 80 size_t max_jobs); |
| 80 | 81 |
| 81 // HostResolver methods: | 82 // HostResolver methods: |
| 82 virtual int Resolve(const RequestInfo& info, | 83 virtual int Resolve(const RequestInfo& info, |
| 83 AddressList* addresses, | 84 AddressList* addresses, |
| 84 CompletionCallback* callback, | 85 CompletionCallback* callback, |
| 85 RequestHandle* out_req, | 86 RequestHandle* out_req, |
| 86 LoadLog* load_log); | 87 const BoundNetLog& net_log); |
| 87 virtual void CancelRequest(RequestHandle req); | 88 virtual void CancelRequest(RequestHandle req); |
| 88 virtual void AddObserver(HostResolver::Observer* observer); | 89 virtual void AddObserver(HostResolver::Observer* observer); |
| 89 virtual void RemoveObserver(HostResolver::Observer* observer); | 90 virtual void RemoveObserver(HostResolver::Observer* observer); |
| 90 | 91 |
| 91 virtual void SetDefaultAddressFamily(AddressFamily address_family) { | 92 virtual void SetDefaultAddressFamily(AddressFamily address_family) { |
| 92 default_address_family_ = address_family; | 93 default_address_family_ = address_family; |
| 93 } | 94 } |
| 94 | 95 |
| 95 virtual HostResolverImpl* GetAsHostResolverImpl() { return this; } | 96 virtual HostResolverImpl* GetAsHostResolverImpl() { return this; } |
| 96 | 97 |
| 97 // TODO(eroman): hack for http://crbug.com/15513 | 98 // TODO(eroman): hack for http://crbug.com/15513 |
| 98 void Shutdown(); | 99 void Shutdown(); |
| 99 | 100 |
| 100 // Returns the cache this resolver uses, or NULL if caching is disabled. | 101 // Returns the cache this resolver uses, or NULL if caching is disabled. |
| 101 HostCache* cache() { return cache_.get(); } | 102 HostCache* cache() { return cache_.get(); } |
| 102 | 103 |
| 103 // Clears the request trace log. | 104 // Clears the request trace log. |
| 104 void ClearRequestsTrace(); | 105 void ClearRequestsTrace(); |
| 105 | 106 |
| 106 // Starts/ends capturing requests to a trace log. | 107 // Starts/ends capturing requests to a trace log. |
| 107 void EnableRequestsTracing(bool enable); | 108 void EnableRequestsTracing(bool enable); |
| 108 | 109 |
| 109 bool IsRequestsTracingEnabled() const; | 110 bool IsRequestsTracingEnabled() const; |
| 110 | 111 |
| 111 // Returns a copy of the requests trace log, or NULL if there is none. | 112 // Gets a copy of the requests trace log. |
| 112 scoped_refptr<LoadLog> GetRequestsTrace(); | 113 bool GetRequestsTrace(std::vector<NetLog::Entry>* entries); |
| 113 | 114 |
| 114 // Applies a set of constraints for requests that belong to the specified | 115 // Applies a set of constraints for requests that belong to the specified |
| 115 // pool. NOTE: Don't call this after requests have been already been started. | 116 // pool. NOTE: Don't call this after requests have been already been started. |
| 116 // | 117 // |
| 117 // |pool_index| -- Specifies which pool these constraints should be applied | 118 // |pool_index| -- Specifies which pool these constraints should be applied |
| 118 // to. | 119 // to. |
| 119 // |max_outstanding_jobs| -- How many concurrent jobs are allowed for this | 120 // |max_outstanding_jobs| -- How many concurrent jobs are allowed for this |
| 120 // pool. | 121 // pool. |
| 121 // |max_pending_requests| -- How many requests can be enqueued for this pool | 122 // |max_pending_requests| -- How many requests can be enqueued for this pool |
| 122 // before we start dropping requests. Dropped | 123 // before we start dropping requests. Dropped |
| (...skipping 30 matching lines...) Expand all Loading... |
| 153 // Returns the outstanding job for |key|, or NULL if there is none. | 154 // Returns the outstanding job for |key|, or NULL if there is none. |
| 154 Job* FindOutstandingJob(const Key& key); | 155 Job* FindOutstandingJob(const Key& key); |
| 155 | 156 |
| 156 // Removes |job| from the outstanding jobs list. | 157 // Removes |job| from the outstanding jobs list. |
| 157 void RemoveOutstandingJob(Job* job); | 158 void RemoveOutstandingJob(Job* job); |
| 158 | 159 |
| 159 // Callback for when |job| has completed with |error| and |addrlist|. | 160 // Callback for when |job| has completed with |error| and |addrlist|. |
| 160 void OnJobComplete(Job* job, int error, const AddressList& addrlist); | 161 void OnJobComplete(Job* job, int error, const AddressList& addrlist); |
| 161 | 162 |
| 162 // Called when a request has just been started. | 163 // Called when a request has just been started. |
| 163 void OnStartRequest(LoadLog* load_log, | 164 void OnStartRequest(const BoundNetLog& net_log, |
| 164 int request_id, | 165 int request_id, |
| 165 const RequestInfo& info); | 166 const RequestInfo& info); |
| 166 | 167 |
| 167 // Called when a request has just completed (before its callback is run). | 168 // Called when a request has just completed (before its callback is run). |
| 168 void OnFinishRequest(LoadLog* load_log, | 169 void OnFinishRequest(const BoundNetLog& net_log, |
| 169 int request_id, | 170 int request_id, |
| 170 const RequestInfo& info, | 171 const RequestInfo& info, |
| 171 int error); | 172 int error); |
| 172 | 173 |
| 173 // Called when a request has been cancelled. | 174 // Called when a request has been cancelled. |
| 174 void OnCancelRequest(LoadLog* load_log, | 175 void OnCancelRequest(const BoundNetLog& net_log, |
| 175 int request_id, | 176 int request_id, |
| 176 const RequestInfo& info); | 177 const RequestInfo& info); |
| 177 | 178 |
| 178 // NetworkChangeNotifier::Observer methods: | 179 // NetworkChangeNotifier::Observer methods: |
| 179 virtual void OnIPAddressChanged(); | 180 virtual void OnIPAddressChanged(); |
| 180 | 181 |
| 181 // Returns true if the constraints for |pool| are met, and a new job can be | 182 // Returns true if the constraints for |pool| are met, and a new job can be |
| 182 // created for this pool. | 183 // created for this pool. |
| 183 bool CanCreateJobForPool(const JobPool& pool) const; | 184 bool CanCreateJobForPool(const JobPool& pool) const; |
| 184 | 185 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 NetworkChangeNotifier* const network_change_notifier_; | 246 NetworkChangeNotifier* const network_change_notifier_; |
| 246 | 247 |
| 247 scoped_refptr<RequestsTrace> requests_trace_; | 248 scoped_refptr<RequestsTrace> requests_trace_; |
| 248 | 249 |
| 249 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); | 250 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); |
| 250 }; | 251 }; |
| 251 | 252 |
| 252 } // namespace net | 253 } // namespace net |
| 253 | 254 |
| 254 #endif // NET_BASE_HOST_RESOLVER_IMPL_H_ | 255 #endif // NET_BASE_HOST_RESOLVER_IMPL_H_ |
| OLD | NEW |