| 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 #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" |
| 12 #include "net/url_request/url_request_status.h" | 12 #include "net/url_request/url_request_status.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 class URLRequestJob; | 15 class URLRequestJob; |
| 16 } // namespace net | 16 } // namespace net |
| 17 | 17 |
| 18 class GURL; | 18 class GURL; |
| 19 | 19 |
| 20 // This class maintains a list of active URLRequestJobs for debugging purposes. | 20 // This class maintains a list of active URLRequestJobs for debugging purposes. |
| 21 // This allows us to warn on leaked jobs and also allows an observer to track | 21 // This allows us to warn on leaked jobs and also allows an observer to track |
| 22 // what is happening, for example, for the network status monitor. | 22 // what is happening, for example, for the network status monitor. |
| 23 // | 23 // |
| 24 // NOTE: URLRequest is single-threaded, so this class should only be used on | 24 // NOTE: net::URLRequest is single-threaded, so this class should only be used |
| 25 // the same thread where all of the application's URLRequest calls are made. | 25 // onthe same thread where all of the application's net::URLRequest calls are |
| 26 // made. |
| 26 // | 27 // |
| 27 class URLRequestJobTracker { | 28 class URLRequestJobTracker { |
| 28 public: | 29 public: |
| 29 typedef std::vector<net::URLRequestJob*> JobList; | 30 typedef std::vector<net::URLRequestJob*> JobList; |
| 30 typedef JobList::const_iterator JobIterator; | 31 typedef JobList::const_iterator JobIterator; |
| 31 | 32 |
| 32 // The observer's methods are called on the thread that called AddObserver. | 33 // The observer's methods are called on the thread that called AddObserver. |
| 33 class JobObserver { | 34 class JobObserver { |
| 34 public: | 35 public: |
| 35 // Called after the given job has been added to the list | 36 // Called after the given job has been added to the list |
| (...skipping 19 matching lines...) Expand all Loading... |
| 55 virtual void OnBytesRead(net::URLRequestJob* job, const char* buf, | 56 virtual void OnBytesRead(net::URLRequestJob* job, const char* buf, |
| 56 int byte_count) = 0; | 57 int byte_count) = 0; |
| 57 | 58 |
| 58 virtual ~JobObserver() {} | 59 virtual ~JobObserver() {} |
| 59 }; | 60 }; |
| 60 | 61 |
| 61 URLRequestJobTracker(); | 62 URLRequestJobTracker(); |
| 62 ~URLRequestJobTracker(); | 63 ~URLRequestJobTracker(); |
| 63 | 64 |
| 64 // adds or removes an observer from the list. note, these methods should | 65 // adds or removes an observer from the list. note, these methods should |
| 65 // only be called on the same thread where URLRequest objects are used. | 66 // only be called on the same thread where net::URLRequest objects are used. |
| 66 void AddObserver(JobObserver* observer) { | 67 void AddObserver(JobObserver* observer) { |
| 67 observers_.AddObserver(observer); | 68 observers_.AddObserver(observer); |
| 68 } | 69 } |
| 69 void RemoveObserver(JobObserver* observer) { | 70 void RemoveObserver(JobObserver* observer) { |
| 70 observers_.RemoveObserver(observer); | 71 observers_.RemoveObserver(observer); |
| 71 } | 72 } |
| 72 | 73 |
| 73 // adds or removes the job from the active list, should be called by the | 74 // adds or removes the job from the active list, should be called by the |
| 74 // job constructor and destructor. Note: don't use "AddJob" since that | 75 // job constructor and destructor. Note: don't use "AddJob" since that |
| 75 // is #defined by windows.h :( | 76 // is #defined by windows.h :( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 93 } | 94 } |
| 94 | 95 |
| 95 private: | 96 private: |
| 96 ObserverList<JobObserver> observers_; | 97 ObserverList<JobObserver> observers_; |
| 97 JobList active_jobs_; | 98 JobList active_jobs_; |
| 98 }; | 99 }; |
| 99 | 100 |
| 100 extern URLRequestJobTracker g_url_request_job_tracker; | 101 extern URLRequestJobTracker g_url_request_job_tracker; |
| 101 | 102 |
| 102 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_TRACKER_H_ | 103 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_TRACKER_H_ |
| OLD | NEW |