1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "net/url_request/url_request_job_tracker.h" 6 7 #include <algorithm> 8 9 #include "base/logging.h" 10 #include "net/url_request/url_request_job.h" 11 12 namespace net { 13 14 URLRequestJobTracker g_url_request_job_tracker; 15 16 URLRequestJobTracker::URLRequestJobTracker() { 17 } 18 19 URLRequestJobTracker::~URLRequestJobTracker() { 20 DLOG_IF(WARNING, !active_jobs_.empty()) << 21 "Leaking " << active_jobs_.size() << " URLRequestJob object(s), this " 22 "could be because the URLRequest forgot to free it (bad), or if the " 23 "program was terminated while a request was active (normal)."; 24 } 25 26 void URLRequestJobTracker::AddNewJob(URLRequestJob* job) { 27 active_jobs_.push_back(job); 28 FOR_EACH_OBSERVER(JobObserver, observers_, OnJobAdded(job)); 29 } 30 31 void URLRequestJobTracker::RemoveJob(URLRequestJob* job) { 32 JobList::iterator iter = std::find(active_jobs_.begin(), active_jobs_.end(), 33 job); 34 if (iter == active_jobs_.end()) { 35 NOTREACHED() << "Removing a non-active job"; 36 return; 37 } 38 active_jobs_.erase(iter); 39 40 FOR_EACH_OBSERVER(JobObserver, observers_, OnJobRemoved(job)); 41 } 42 43 void URLRequestJobTracker::OnJobDone(URLRequestJob* job, 44 const URLRequestStatus& status) { 45 FOR_EACH_OBSERVER(JobObserver, observers_, OnJobDone(job, status)); 46 } 47 48 void URLRequestJobTracker::OnJobRedirect(URLRequestJob* job, 49 const GURL& location, 50 int status_code) { 51 FOR_EACH_OBSERVER(JobObserver, observers_, 52 OnJobRedirect(job, location, status_code)); 53 } 54 55 void URLRequestJobTracker::OnBytesRead(URLRequestJob* job, 56 const char* buf, 57 int byte_count) { 58 FOR_EACH_OBSERVER(JobObserver, observers_, 59 OnBytesRead(job, buf, byte_count)); 60 } 61 62 } // namespace net 63