| 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 "net/base/host_cache.h" | 12 #include "net/base/host_cache.h" |
| 12 #include "net/base/host_resolver.h" | 13 #include "net/base/host_resolver.h" |
| 13 #include "net/base/host_resolver_proc.h" | 14 #include "net/base/host_resolver_proc.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 | 17 |
| 17 // For each hostname that is requested, HostResolver creates a | 18 // For each hostname that is requested, HostResolver creates a |
| 18 // HostResolverImpl::Job. This job gets dispatched to a thread in the global | 19 // HostResolverImpl::Job. This job gets dispatched to a thread in the global |
| 19 // WorkerPool, where it runs SystemHostResolverProc(). If requests for that same | 20 // WorkerPool, where it runs SystemHostResolverProc(). If requests for that same |
| 20 // host are made while the job is already outstanding, then they are attached | 21 // host are made while the job is already outstanding, then they are attached |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 // | 35 // |
| 35 // | 36 // |
| 36 // When a HostResolverImpl::Job finishes its work in the threadpool, the | 37 // When a HostResolverImpl::Job finishes its work in the threadpool, the |
| 37 // callbacks of each waiting request are run on the origin thread. | 38 // callbacks of each waiting request are run on the origin thread. |
| 38 // | 39 // |
| 39 // Thread safety: This class is not threadsafe, and must only be called | 40 // Thread safety: This class is not threadsafe, and must only be called |
| 40 // from one thread! | 41 // from one thread! |
| 41 // | 42 // |
| 42 class HostResolverImpl : public HostResolver { | 43 class HostResolverImpl : public HostResolver { |
| 43 public: | 44 public: |
| 44 // Creates a HostResolver that caches up to |max_cache_entries| for | 45 // Creates a HostResolver that first uses the local cache |cache|, and then |
| 45 // |cache_duration_ms| milliseconds. |resolver_proc| is used to perform | 46 // falls back to |resolver_proc|. |
| 46 // the actual resolves; it must be thread-safe since it is run from | 47 // |
| 47 // multiple worker threads. If |resolver_proc| is NULL then the default | 48 // If |cache| is NULL, then no caching is used. Otherwise we take |
| 48 // host resolver procedure is used (which is SystemHostResolverProc except | 49 // ownership of the |cache| pointer, and will free at during destructor. |
| 49 // if overridden) | 50 // |
| 50 HostResolverImpl(HostResolverProc* resolver_proc, | 51 // |resolver_proc| is used to perform the actual resolves; it must be |
| 51 int max_cache_entries, | 52 // thread-safe since it is run from multiple worker threads. If |
| 52 int cache_duration_ms); | 53 // |resolver_proc| is NULL then the default host resolver procedure is |
| 54 // used (which is SystemHostResolverProc except if overridden). |
| 55 HostResolverImpl(HostResolverProc* resolver_proc, HostCache* cache); |
| 53 | 56 |
| 54 // HostResolver methods: | 57 // HostResolver methods: |
| 55 virtual int Resolve(const RequestInfo& info, | 58 virtual int Resolve(const RequestInfo& info, |
| 56 AddressList* addresses, | 59 AddressList* addresses, |
| 57 CompletionCallback* callback, | 60 CompletionCallback* callback, |
| 58 RequestHandle* out_req, | 61 RequestHandle* out_req, |
| 59 LoadLog* load_log); | 62 LoadLog* load_log); |
| 60 virtual void CancelRequest(RequestHandle req); | 63 virtual void CancelRequest(RequestHandle req); |
| 61 virtual void AddObserver(Observer* observer); | 64 virtual void AddObserver(Observer* observer); |
| 62 virtual void RemoveObserver(Observer* observer); | 65 virtual void RemoveObserver(Observer* observer); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 int request_id, | 113 int request_id, |
| 111 const RequestInfo& info, | 114 const RequestInfo& info, |
| 112 int error); | 115 int error); |
| 113 | 116 |
| 114 // Called when a request has been cancelled. | 117 // Called when a request has been cancelled. |
| 115 void OnCancelRequest(LoadLog* load_log, | 118 void OnCancelRequest(LoadLog* load_log, |
| 116 int request_id, | 119 int request_id, |
| 117 const RequestInfo& info); | 120 const RequestInfo& info); |
| 118 | 121 |
| 119 // Cache of host resolution results. | 122 // Cache of host resolution results. |
| 120 HostCache cache_; | 123 scoped_ptr<HostCache> cache_; |
| 121 | 124 |
| 122 // Map from hostname to outstanding job. | 125 // Map from hostname to outstanding job. |
| 123 JobMap jobs_; | 126 JobMap jobs_; |
| 124 | 127 |
| 125 // The job that OnJobComplete() is currently processing (needed in case | 128 // The job that OnJobComplete() is currently processing (needed in case |
| 126 // HostResolver gets deleted from within the callback). | 129 // HostResolver gets deleted from within the callback). |
| 127 scoped_refptr<Job> cur_completing_job_; | 130 scoped_refptr<Job> cur_completing_job_; |
| 128 | 131 |
| 129 // The observers to notify when a request starts/ends. | 132 // The observers to notify when a request starts/ends. |
| 130 ObserversList observers_; | 133 ObserversList observers_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 142 | 145 |
| 143 // TODO(eroman): temp hack for http://crbug.com/15513 | 146 // TODO(eroman): temp hack for http://crbug.com/15513 |
| 144 bool shutdown_; | 147 bool shutdown_; |
| 145 | 148 |
| 146 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); | 149 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); |
| 147 }; | 150 }; |
| 148 | 151 |
| 149 } // namespace net | 152 } // namespace net |
| 150 | 153 |
| 151 #endif // NET_BASE_HOST_RESOLVER_IMPL_H_ | 154 #endif // NET_BASE_HOST_RESOLVER_IMPL_H_ |
| OLD | NEW |