| OLD | NEW |
| 1 // Copyright (c) 2006-2008 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 #ifndef NET_URL_REQUEST_URL_REQUEST_JOB_TRACKER_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_JOB_TRACKER_H_ |
| 6 #define NET_URL_REQUEST_URL_REQUEST_JOB_TRACKER_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_JOB_TRACKER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 // Called when the given job has completed, before notifying the request | 38 // Called when the given job has completed, before notifying the request |
| 39 virtual void OnJobDone(URLRequestJob* job, | 39 virtual void OnJobDone(URLRequestJob* job, |
| 40 const URLRequestStatus& status) = 0; | 40 const URLRequestStatus& status) = 0; |
| 41 | 41 |
| 42 // Called when the given job is about to follow a redirect to the given | 42 // Called when the given job is about to follow a redirect to the given |
| 43 // new URL. The redirect type is given in status_code | 43 // new URL. The redirect type is given in status_code |
| 44 virtual void OnJobRedirect(URLRequestJob* job, const GURL& location, | 44 virtual void OnJobRedirect(URLRequestJob* job, const GURL& location, |
| 45 int status_code) = 0; | 45 int status_code) = 0; |
| 46 | 46 |
| 47 // Called when a new chunk of bytes has been read for the given job. The | 47 // Called when a new chunk of unfiltered bytes has been read for |
| 48 // byte count is the number of bytes for that read event only. | 48 // the given job. |byte_count| is the number of bytes for that |
| 49 virtual void OnBytesRead(URLRequestJob* job, int byte_count) = 0; | 49 // read event only. |buf| is a pointer to the data buffer that |
| 50 // contains those bytes. The data in |buf| is only valid for the |
| 51 // duration of the OnBytesRead callback. |
| 52 virtual void OnBytesRead(URLRequestJob* job, const char* buf, |
| 53 int byte_count) = 0; |
| 50 | 54 |
| 51 virtual ~JobObserver() {} | 55 virtual ~JobObserver() {} |
| 52 }; | 56 }; |
| 53 | 57 |
| 54 URLRequestJobTracker(); | 58 URLRequestJobTracker(); |
| 55 ~URLRequestJobTracker(); | 59 ~URLRequestJobTracker(); |
| 56 | 60 |
| 57 // adds or removes an observer from the list. note, these methods should | 61 // adds or removes an observer from the list. note, these methods should |
| 58 // only be called on the same thread where URLRequest objects are used. | 62 // only be called on the same thread where URLRequest objects are used. |
| 59 void AddObserver(JobObserver* observer) { | 63 void AddObserver(JobObserver* observer) { |
| 60 observers_.AddObserver(observer); | 64 observers_.AddObserver(observer); |
| 61 } | 65 } |
| 62 void RemoveObserver(JobObserver* observer) { | 66 void RemoveObserver(JobObserver* observer) { |
| 63 observers_.RemoveObserver(observer); | 67 observers_.RemoveObserver(observer); |
| 64 } | 68 } |
| 65 | 69 |
| 66 // adds or removes the job from the active list, should be called by the | 70 // adds or removes the job from the active list, should be called by the |
| 67 // job constructor and destructor. Note: don't use "AddJob" since that | 71 // job constructor and destructor. Note: don't use "AddJob" since that |
| 68 // is #defined by windows.h :( | 72 // is #defined by windows.h :( |
| 69 void AddNewJob(URLRequestJob* job); | 73 void AddNewJob(URLRequestJob* job); |
| 70 void RemoveJob(URLRequestJob* job); | 74 void RemoveJob(URLRequestJob* job); |
| 71 | 75 |
| 72 // Job status change notifications | 76 // Job status change notifications |
| 73 void OnJobDone(URLRequestJob* job, const URLRequestStatus& status); | 77 void OnJobDone(URLRequestJob* job, const URLRequestStatus& status); |
| 74 void OnJobRedirect(URLRequestJob* job, const GURL& location, | 78 void OnJobRedirect(URLRequestJob* job, const GURL& location, |
| 75 int status_code); | 79 int status_code); |
| 76 | 80 |
| 77 // Bytes read notifications. | 81 // Bytes read notifications. |
| 78 void OnBytesRead(URLRequestJob* job, int byte_count); | 82 void OnBytesRead(URLRequestJob* job, const char* buf, int byte_count); |
| 79 | 83 |
| 80 // allows iteration over all active jobs | 84 // allows iteration over all active jobs |
| 81 JobIterator begin() const { | 85 JobIterator begin() const { |
| 82 return active_jobs_.begin(); | 86 return active_jobs_.begin(); |
| 83 } | 87 } |
| 84 JobIterator end() const { | 88 JobIterator end() const { |
| 85 return active_jobs_.end(); | 89 return active_jobs_.end(); |
| 86 } | 90 } |
| 87 | 91 |
| 88 private: | 92 private: |
| 89 ObserverList<JobObserver> observers_; | 93 ObserverList<JobObserver> observers_; |
| 90 JobList active_jobs_; | 94 JobList active_jobs_; |
| 91 }; | 95 }; |
| 92 | 96 |
| 93 extern URLRequestJobTracker g_url_request_job_tracker; | 97 extern URLRequestJobTracker g_url_request_job_tracker; |
| 94 | 98 |
| 95 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_TRACKER_H_ | 99 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_TRACKER_H_ |
| OLD | NEW |