blob: 632d0a38f47729549093abfc7631310ca3997536 [file] [log] [blame]
Ben Murdochc407dc52010-07-29 17:14:53 +01001// Copyright (c) 2010 The Chromium Authors. All rights reserved.
Patrick Scottc7f5f852010-02-04 10:37:17 -05002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Patrick Scottc7f5f852010-02-04 10:37:17 -05005#include "net/url_request/url_request_job_tracker.h"
6
Kristian Monsen21d179b2011-05-11 20:53:37 +01007#include <algorithm>
8
Patrick Scottc7f5f852010-02-04 10:37:17 -05009#include "base/logging.h"
10#include "net/url_request/url_request_job.h"
11
Kristian Monsen21d179b2011-05-11 20:53:37 +010012namespace net {
13
Patrick Scottc7f5f852010-02-04 10:37:17 -050014URLRequestJobTracker g_url_request_job_tracker;
15
16URLRequestJobTracker::URLRequestJobTracker() {
17}
18
19URLRequestJobTracker::~URLRequestJobTracker() {
Kristian Monsendc0f95d2011-06-09 11:47:42 +010020 DLOG_IF(WARNING, !active_jobs_.empty()) <<
Kristian Monsen21d179b2011-05-11 20:53:37 +010021 "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).";
Patrick Scottc7f5f852010-02-04 10:37:17 -050024}
25
26void URLRequestJobTracker::AddNewJob(URLRequestJob* job) {
27 active_jobs_.push_back(job);
28 FOR_EACH_OBSERVER(JobObserver, observers_, OnJobAdded(job));
29}
30
31void 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
43void URLRequestJobTracker::OnJobDone(URLRequestJob* job,
44 const URLRequestStatus& status) {
45 FOR_EACH_OBSERVER(JobObserver, observers_, OnJobDone(job, status));
46}
47
48void 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
55void URLRequestJobTracker::OnBytesRead(URLRequestJob* job,
Ben Murdochc407dc52010-07-29 17:14:53 +010056 const char* buf,
Patrick Scottc7f5f852010-02-04 10:37:17 -050057 int byte_count) {
58 FOR_EACH_OBSERVER(JobObserver, observers_,
Ben Murdochc407dc52010-07-29 17:14:53 +010059 OnBytesRead(job, buf, byte_count));
Patrick Scottc7f5f852010-02-04 10:37:17 -050060}
Kristian Monsen21d179b2011-05-11 20:53:37 +010061
62} // namespace net