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 #include "net/base/host_resolver_impl.h" | 5 #include "net/base/host_resolver_impl.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <ws2tcpip.h> | 8 #include <ws2tcpip.h> |
9 #include <wspiapi.h> // Needed for Win2k compat. | 9 #include <wspiapi.h> // Needed for Win2k compat. |
10 #elif defined(OS_POSIX) | 10 #elif defined(OS_POSIX) |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 : public base::RefCountedThreadSafe<HostResolverImpl::Job> { | 142 : public base::RefCountedThreadSafe<HostResolverImpl::Job> { |
143 public: | 143 public: |
144 Job(HostResolverImpl* resolver, const Key& key) | 144 Job(HostResolverImpl* resolver, const Key& key) |
145 : key_(key), | 145 : key_(key), |
146 resolver_(resolver), | 146 resolver_(resolver), |
147 origin_loop_(MessageLoop::current()), | 147 origin_loop_(MessageLoop::current()), |
148 resolver_proc_(resolver->effective_resolver_proc()), | 148 resolver_proc_(resolver->effective_resolver_proc()), |
149 error_(OK) { | 149 error_(OK) { |
150 } | 150 } |
151 | 151 |
152 ~Job() { | |
153 // Free the requests attached to this job. | |
154 STLDeleteElements(&requests_); | |
155 } | |
156 | |
157 // Attaches a request to this job. The job takes ownership of |req| and will | 152 // Attaches a request to this job. The job takes ownership of |req| and will |
158 // take care to delete it. | 153 // take care to delete it. |
159 void AddRequest(Request* req) { | 154 void AddRequest(Request* req) { |
160 req->set_job(this); | 155 req->set_job(this); |
161 requests_.push_back(req); | 156 requests_.push_back(req); |
162 } | 157 } |
163 | 158 |
164 // Called from origin loop. | 159 // Called from origin loop. |
165 void Start() { | 160 void Start() { |
166 // Dispatch the job to a worker thread. | 161 // Dispatch the job to a worker thread. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 const Key& key() const { | 203 const Key& key() const { |
209 return key_; | 204 return key_; |
210 } | 205 } |
211 | 206 |
212 // Called from origin thread. | 207 // Called from origin thread. |
213 const RequestsList& requests() const { | 208 const RequestsList& requests() const { |
214 return requests_; | 209 return requests_; |
215 } | 210 } |
216 | 211 |
217 private: | 212 private: |
| 213 friend class base::RefCountedThreadSafe<HostResolverImpl::Job>; |
| 214 |
| 215 ~Job() { |
| 216 // Free the requests attached to this job. |
| 217 STLDeleteElements(&requests_); |
| 218 } |
| 219 |
218 void DoLookup() { | 220 void DoLookup() { |
219 // Running on the worker thread | 221 // Running on the worker thread |
220 error_ = ResolveAddrInfo(resolver_proc_, | 222 error_ = ResolveAddrInfo(resolver_proc_, |
221 key_.hostname, | 223 key_.hostname, |
222 key_.address_family, | 224 key_.address_family, |
223 &results_); | 225 &results_); |
224 | 226 |
225 Task* reply = NewRunnableMethod(this, &Job::OnLookupComplete); | 227 Task* reply = NewRunnableMethod(this, &Job::OnLookupComplete); |
226 | 228 |
227 // The origin loop could go away while we are trying to post to it, so we | 229 // The origin loop could go away while we are trying to post to it, so we |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 } | 554 } |
553 | 555 |
554 LoadLog::EndEvent( | 556 LoadLog::EndEvent( |
555 load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); | 557 load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); |
556 } | 558 } |
557 | 559 |
558 LoadLog::EndEvent(load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL); | 560 LoadLog::EndEvent(load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL); |
559 } | 561 } |
560 | 562 |
561 } // namespace net | 563 } // namespace net |
OLD | NEW |