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