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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 job_(NULL), | 68 job_(NULL), |
69 callback_(callback), | 69 callback_(callback), |
70 addresses_(addresses) { | 70 addresses_(addresses) { |
71 } | 71 } |
72 | 72 |
73 // Mark the request as cancelled. | 73 // Mark the request as cancelled. |
74 void MarkAsCancelled() { | 74 void MarkAsCancelled() { |
75 job_ = NULL; | 75 job_ = NULL; |
76 callback_ = NULL; | 76 callback_ = NULL; |
77 addresses_ = NULL; | 77 addresses_ = NULL; |
78 // Clear the LoadLog to make sure it won't be released later on the | |
79 // worker thread. See http://crbug.com/22272 | |
80 load_log_ = NULL; | |
81 } | 78 } |
82 | 79 |
83 bool was_cancelled() const { | 80 bool was_cancelled() const { |
84 return callback_ == NULL; | 81 return callback_ == NULL; |
85 } | 82 } |
86 | 83 |
87 void set_job(Job* job) { | 84 void set_job(Job* job) { |
88 DCHECK(job != NULL); | 85 DCHECK(job != NULL); |
89 // Identify which job the request is waiting on. | 86 // Identify which job the request is waiting on. |
90 job_ = job; | 87 job_ = job; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 resolver_ = NULL; | 183 resolver_ = NULL; |
187 | 184 |
188 // Mark the job as cancelled, so when worker thread completes it will | 185 // Mark the job as cancelled, so when worker thread completes it will |
189 // not try to post completion to origin loop. | 186 // not try to post completion to origin loop. |
190 { | 187 { |
191 AutoLock locked(origin_loop_lock_); | 188 AutoLock locked(origin_loop_lock_); |
192 origin_loop_ = NULL; | 189 origin_loop_ = NULL; |
193 } | 190 } |
194 | 191 |
195 // We will call HostResolverImpl::CancelRequest(Request*) on each one | 192 // We will call HostResolverImpl::CancelRequest(Request*) on each one |
196 // in order to notify any observers, and also clear the LoadLog. | 193 // in order to notify any observers. |
197 for (RequestsList::const_iterator it = requests_.begin(); | 194 for (RequestsList::const_iterator it = requests_.begin(); |
198 it != requests_.end(); ++it) { | 195 it != requests_.end(); ++it) { |
199 HostResolverImpl::Request* req = *it; | 196 HostResolverImpl::Request* req = *it; |
200 if (!req->was_cancelled()) | 197 if (!req->was_cancelled()) |
201 resolver->CancelRequest(req); | 198 resolver->CancelRequest(req); |
202 } | 199 } |
203 } | 200 } |
204 | 201 |
205 // Called from origin thread. | 202 // Called from origin thread. |
206 bool was_cancelled() const { | 203 bool was_cancelled() const { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 // TODO(eroman): temp hack for: http://crbug.com/18373 | 400 // TODO(eroman): temp hack for: http://crbug.com/18373 |
404 // Because we destroy outstanding requests during Shutdown(), | 401 // Because we destroy outstanding requests during Shutdown(), |
405 // |req_handle| is already cancelled. | 402 // |req_handle| is already cancelled. |
406 LOG(ERROR) << "Called HostResolverImpl::CancelRequest() after Shutdown()."; | 403 LOG(ERROR) << "Called HostResolverImpl::CancelRequest() after Shutdown()."; |
407 StackTrace().PrintBacktrace(); | 404 StackTrace().PrintBacktrace(); |
408 return; | 405 return; |
409 } | 406 } |
410 Request* req = reinterpret_cast<Request*>(req_handle); | 407 Request* req = reinterpret_cast<Request*>(req_handle); |
411 DCHECK(req); | 408 DCHECK(req); |
412 DCHECK(req->job()); | 409 DCHECK(req->job()); |
413 // Hold a reference to the request's load log as we are about to clear it. | |
414 scoped_refptr<LoadLog> load_log(req->load_log()); | |
415 // NULL out the fields of req, to mark it as cancelled. | 410 // NULL out the fields of req, to mark it as cancelled. |
416 req->MarkAsCancelled(); | 411 req->MarkAsCancelled(); |
417 OnCancelRequest(load_log, req->id(), req->info()); | 412 OnCancelRequest(req->load_log(), req->id(), req->info()); |
418 } | 413 } |
419 | 414 |
420 void HostResolverImpl::AddObserver(Observer* observer) { | 415 void HostResolverImpl::AddObserver(Observer* observer) { |
421 observers_.push_back(observer); | 416 observers_.push_back(observer); |
422 } | 417 } |
423 | 418 |
424 void HostResolverImpl::RemoveObserver(Observer* observer) { | 419 void HostResolverImpl::RemoveObserver(Observer* observer) { |
425 ObserversList::iterator it = | 420 ObserversList::iterator it = |
426 std::find(observers_.begin(), observers_.end(), observer); | 421 std::find(observers_.begin(), observers_.end(), observer); |
427 | 422 |
(...skipping 30 matching lines...) Expand all Loading... |
458 } | 453 } |
459 | 454 |
460 void HostResolverImpl::RemoveOutstandingJob(Job* job) { | 455 void HostResolverImpl::RemoveOutstandingJob(Job* job) { |
461 JobMap::iterator it = jobs_.find(job->key()); | 456 JobMap::iterator it = jobs_.find(job->key()); |
462 DCHECK(it != jobs_.end()); | 457 DCHECK(it != jobs_.end()); |
463 DCHECK_EQ(it->second.get(), job); | 458 DCHECK_EQ(it->second.get(), job); |
464 jobs_.erase(it); | 459 jobs_.erase(it); |
465 } | 460 } |
466 | 461 |
467 void HostResolverImpl::OnJobComplete(Job* job, | 462 void HostResolverImpl::OnJobComplete(Job* job, |
468 int error, | 463 int error, |
469 const AddressList& addrlist) { | 464 const AddressList& addrlist) { |
470 RemoveOutstandingJob(job); | 465 RemoveOutstandingJob(job); |
471 | 466 |
472 // Write result to the cache. | 467 // Write result to the cache. |
473 cache_.Set(job->key(), error, addrlist, base::TimeTicks::Now()); | 468 cache_.Set(job->key(), error, addrlist, base::TimeTicks::Now()); |
474 | 469 |
475 // Make a note that we are executing within OnJobComplete() in case the | 470 // Make a note that we are executing within OnJobComplete() in case the |
476 // HostResolver is deleted by a callback invocation. | 471 // HostResolver is deleted by a callback invocation. |
477 DCHECK(!cur_completing_job_); | 472 DCHECK(!cur_completing_job_); |
478 cur_completing_job_ = job; | 473 cur_completing_job_ = job; |
479 | 474 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 } | 552 } |
558 | 553 |
559 LoadLog::EndEvent( | 554 LoadLog::EndEvent( |
560 load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); | 555 load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); |
561 } | 556 } |
562 | 557 |
563 LoadLog::EndEvent(load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL); | 558 LoadLog::EndEvent(load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL); |
564 } | 559 } |
565 | 560 |
566 } // namespace net | 561 } // namespace net |
OLD | NEW |