 Chromium Code Reviews
 Chromium Code Reviews Issue 214025:
  Make sure that the LoadLog does not get freed on the worker thread during req...  (Closed) 
  Base URL: svn://chrome-svn/chrome/trunk/src/
    
  
    Issue 214025:
  Make sure that the LoadLog does not get freed on the worker thread during req...  (Closed) 
  Base URL: svn://chrome-svn/chrome/trunk/src/| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 job_(NULL), | 66 job_(NULL), | 
| 67 callback_(callback), | 67 callback_(callback), | 
| 68 addresses_(addresses) { | 68 addresses_(addresses) { | 
| 69 } | 69 } | 
| 70 | 70 | 
| 71 // Mark the request as cancelled. | 71 // Mark the request as cancelled. | 
| 72 void MarkAsCancelled() { | 72 void MarkAsCancelled() { | 
| 73 job_ = NULL; | 73 job_ = NULL; | 
| 74 callback_ = NULL; | 74 callback_ = NULL; | 
| 75 addresses_ = NULL; | 75 addresses_ = NULL; | 
| 76 // Clear the LoadLog to make sure it won't be released later on the | |
| 
wtc
2009/09/21 18:14:12
Do you mean clearing the load log (i.e., emptying
 | |
| 77 // worker thread. See http://crbug.com/22272 | |
| 78 load_log_ = NULL; | |
| 76 } | 79 } | 
| 77 | 80 | 
| 78 bool was_cancelled() const { | 81 bool was_cancelled() const { | 
| 79 return callback_ == NULL; | 82 return callback_ == NULL; | 
| 80 } | 83 } | 
| 81 | 84 | 
| 82 void set_job(Job* job) { | 85 void set_job(Job* job) { | 
| 83 DCHECK(job != NULL); | 86 DCHECK(job != NULL); | 
| 84 // Identify which job the request is waiting on. | 87 // Identify which job the request is waiting on. | 
| 85 job_ = job; | 88 job_ = job; | 
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 HostResolver* resolver = resolver_; | 183 HostResolver* resolver = resolver_; | 
| 181 resolver_ = NULL; | 184 resolver_ = NULL; | 
| 182 | 185 | 
| 183 // Mark the job as cancelled, so when worker thread completes it will | 186 // Mark the job as cancelled, so when worker thread completes it will | 
| 184 // not try to post completion to origin loop. | 187 // not try to post completion to origin loop. | 
| 185 { | 188 { | 
| 186 AutoLock locked(origin_loop_lock_); | 189 AutoLock locked(origin_loop_lock_); | 
| 187 origin_loop_ = NULL; | 190 origin_loop_ = NULL; | 
| 188 } | 191 } | 
| 189 | 192 | 
| 190 // We don't have to do anything further to actually cancel the requests | 193 // We will call HostResolverImpl::CancelRequest(Request*) on each one | 
| 191 // that were attached to this job (since they are unreachable now). | 194 // in order to notify any observers, and also clear the LoadLog. | 
| 192 // But we will call HostResolverImpl::CancelRequest(Request*) on each one | |
| 193 // in order to notify any observers. | |
| 194 for (RequestsList::const_iterator it = requests_.begin(); | 195 for (RequestsList::const_iterator it = requests_.begin(); | 
| 195 it != requests_.end(); ++it) { | 196 it != requests_.end(); ++it) { | 
| 196 HostResolverImpl::Request* req = *it; | 197 HostResolverImpl::Request* req = *it; | 
| 197 if (!req->was_cancelled()) | 198 if (!req->was_cancelled()) | 
| 198 resolver->CancelRequest(req); | 199 resolver->CancelRequest(req); | 
| 199 } | 200 } | 
| 200 } | 201 } | 
| 201 | 202 | 
| 202 // Called from origin thread. | 203 // Called from origin thread. | 
| 203 bool was_cancelled() const { | 204 bool was_cancelled() const { | 
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 // TODO(eroman): temp hack for: http://crbug.com/18373 | 389 // TODO(eroman): temp hack for: http://crbug.com/18373 | 
| 389 // Because we destroy outstanding requests during Shutdown(), | 390 // Because we destroy outstanding requests during Shutdown(), | 
| 390 // |req_handle| is already cancelled. | 391 // |req_handle| is already cancelled. | 
| 391 LOG(ERROR) << "Called HostResolverImpl::CancelRequest() after Shutdown()."; | 392 LOG(ERROR) << "Called HostResolverImpl::CancelRequest() after Shutdown()."; | 
| 392 StackTrace().PrintBacktrace(); | 393 StackTrace().PrintBacktrace(); | 
| 393 return; | 394 return; | 
| 394 } | 395 } | 
| 395 Request* req = reinterpret_cast<Request*>(req_handle); | 396 Request* req = reinterpret_cast<Request*>(req_handle); | 
| 396 DCHECK(req); | 397 DCHECK(req); | 
| 397 DCHECK(req->job()); | 398 DCHECK(req->job()); | 
| 399 // Hold a reference to the request's load log as we are about to clear it. | |
| 
wtc
2009/09/21 18:14:12
Nit: it's not clear what "it" refers to here.  Do
 | |
| 400 scoped_refptr<LoadLog> load_log(req->load_log()); | |
| 398 // NULL out the fields of req, to mark it as cancelled. | 401 // NULL out the fields of req, to mark it as cancelled. | 
| 399 req->MarkAsCancelled(); | 402 req->MarkAsCancelled(); | 
| 400 OnCancelRequest(req->load_log(), req->id(), req->info()); | 403 OnCancelRequest(load_log, req->id(), req->info()); | 
| 401 } | 404 } | 
| 402 | 405 | 
| 403 void HostResolverImpl::AddObserver(Observer* observer) { | 406 void HostResolverImpl::AddObserver(Observer* observer) { | 
| 404 observers_.push_back(observer); | 407 observers_.push_back(observer); | 
| 405 } | 408 } | 
| 406 | 409 | 
| 407 void HostResolverImpl::RemoveObserver(Observer* observer) { | 410 void HostResolverImpl::RemoveObserver(Observer* observer) { | 
| 408 ObserversList::iterator it = | 411 ObserversList::iterator it = | 
| 409 std::find(observers_.begin(), observers_.end(), observer); | 412 std::find(observers_.begin(), observers_.end(), observer); | 
| 410 | 413 | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 } | 544 } | 
| 542 | 545 | 
| 543 LoadLog::EndEvent( | 546 LoadLog::EndEvent( | 
| 544 load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); | 547 load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); | 
| 545 } | 548 } | 
| 546 | 549 | 
| 547 LoadLog::EndEvent(load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL); | 550 LoadLog::EndEvent(load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL); | 
| 548 } | 551 } | 
| 549 | 552 | 
| 550 } // namespace net | 553 } // namespace net | 
| OLD | NEW |