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