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_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_JOB_H_ |
6 #define NET_URL_REQUEST_URL_REQUEST_JOB_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_JOB_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 virtual void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers); | 58 virtual void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers); |
59 | 59 |
60 // If any error occurs while starting the Job, NotifyStartError should be | 60 // If any error occurs while starting the Job, NotifyStartError should be |
61 // called. | 61 // called. |
62 // This helps ensure that all errors follow more similar notification code | 62 // This helps ensure that all errors follow more similar notification code |
63 // paths, which should simplify testing. | 63 // paths, which should simplify testing. |
64 virtual void Start() = 0; | 64 virtual void Start() = 0; |
65 | 65 |
66 // This function MUST somehow call NotifyDone/NotifyCanceled or some requests | 66 // This function MUST somehow call NotifyDone/NotifyCanceled or some requests |
67 // will get leaked. Certain callers use that message to know when they can | 67 // will get leaked. Certain callers use that message to know when they can |
68 // delete their URLRequest object, even when doing a cancel. The default Kill | 68 // delete their net::URLRequest object, even when doing a cancel. The default |
69 // implementation calls NotifyCanceled, so it is recommended that subclasses | 69 // Kill implementation calls NotifyCanceled, so it is recommended that |
70 // call URLRequestJob::Kill() after doing any additional work. | 70 // subclasses call URLRequestJob::Kill() after doing any additional work. |
71 // | 71 // |
72 // The job should endeavor to stop working as soon as is convenient, but must | 72 // The job should endeavor to stop working as soon as is convenient, but must |
73 // not send and complete notifications from inside this function. Instead, | 73 // not send and complete notifications from inside this function. Instead, |
74 // complete notifications (including "canceled") should be sent from a | 74 // complete notifications (including "canceled") should be sent from a |
75 // callback run from the message loop. | 75 // callback run from the message loop. |
76 // | 76 // |
77 // The job is not obliged to immediately stop sending data in response to | 77 // The job is not obliged to immediately stop sending data in response to |
78 // this call, nor is it obliged to fail with "canceled" unless not all data | 78 // this call, nor is it obliged to fail with "canceled" unless not all data |
79 // was sent as a result. A typical case would be where the job is almost | 79 // was sent as a result. A typical case would be where the job is almost |
80 // complete and can succeed before the canceled notification can be | 80 // complete and can succeed before the canceled notification can be |
81 // dispatched (from the message loop). | 81 // dispatched (from the message loop). |
82 // | 82 // |
83 // The job should be prepared to receive multiple calls to kill it, but only | 83 // The job should be prepared to receive multiple calls to kill it, but only |
84 // one notification must be issued. | 84 // one notification must be issued. |
85 virtual void Kill(); | 85 virtual void Kill(); |
86 | 86 |
87 // Called to detach the request from this Job. Results in the Job being | 87 // Called to detach the request from this Job. Results in the Job being |
88 // killed off eventually. The job must not use the request pointer any more. | 88 // killed off eventually. The job must not use the request pointer any more. |
89 void DetachRequest(); | 89 void DetachRequest(); |
90 | 90 |
91 // Called to read post-filtered data from this Job, returning the number of | 91 // Called to read post-filtered data from this Job, returning the number of |
92 // bytes read, 0 when there is no more data, or -1 if there was an error. | 92 // bytes read, 0 when there is no more data, or -1 if there was an error. |
93 // This is just the backend for URLRequest::Read, see that function for more | 93 // This is just the backend for net::URLRequest::Read, see that function for |
94 // info. | 94 // more info. |
95 bool Read(net::IOBuffer* buf, int buf_size, int* bytes_read); | 95 bool Read(net::IOBuffer* buf, int buf_size, int* bytes_read); |
96 | 96 |
97 // Stops further caching of this request, if any. For more info, see | 97 // Stops further caching of this request, if any. For more info, see |
98 // URLRequest::StopCaching(). | 98 // net::URLRequest::StopCaching(). |
99 virtual void StopCaching(); | 99 virtual void StopCaching(); |
100 | 100 |
101 // Called to fetch the current load state for the job. | 101 // Called to fetch the current load state for the job. |
102 virtual net::LoadState GetLoadState() const; | 102 virtual net::LoadState GetLoadState() const; |
103 | 103 |
104 // Called to get the upload progress in bytes. | 104 // Called to get the upload progress in bytes. |
105 virtual uint64 GetUploadProgress() const; | 105 virtual uint64 GetUploadProgress() const; |
106 | 106 |
107 // Called to fetch the charset for this request. Only makes sense for some | 107 // Called to fetch the charset for this request. Only makes sense for some |
108 // types of requests. Returns true on success. Calling this on a type that | 108 // types of requests. Returns true on success. Calling this on a type that |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // | 150 // |
151 // The caller is responsible for following the redirect by setting up an | 151 // The caller is responsible for following the redirect by setting up an |
152 // appropriate replacement Job. Note that the redirected location may be | 152 // appropriate replacement Job. Note that the redirected location may be |
153 // invalid, the caller should be sure it can handle this. | 153 // invalid, the caller should be sure it can handle this. |
154 // | 154 // |
155 // The default implementation inspects the response_info_. | 155 // The default implementation inspects the response_info_. |
156 virtual bool IsRedirectResponse(GURL* location, int* http_status_code); | 156 virtual bool IsRedirectResponse(GURL* location, int* http_status_code); |
157 | 157 |
158 // Called to determine if it is okay to redirect this job to the specified | 158 // Called to determine if it is okay to redirect this job to the specified |
159 // location. This may be used to implement protocol-specific restrictions. | 159 // location. This may be used to implement protocol-specific restrictions. |
160 // If this function returns false, then the URLRequest will fail reporting | 160 // If this function returns false, then the net::URLRequest will fail |
161 // net::ERR_UNSAFE_REDIRECT. | 161 // reporting net::ERR_UNSAFE_REDIRECT. |
162 virtual bool IsSafeRedirect(const GURL& location); | 162 virtual bool IsSafeRedirect(const GURL& location); |
163 | 163 |
164 // Called to determine if this response is asking for authentication. Only | 164 // Called to determine if this response is asking for authentication. Only |
165 // makes sense for some types of requests. The caller is responsible for | 165 // makes sense for some types of requests. The caller is responsible for |
166 // obtaining the credentials passing them to SetAuth. | 166 // obtaining the credentials passing them to SetAuth. |
167 virtual bool NeedsAuth(); | 167 virtual bool NeedsAuth(); |
168 | 168 |
169 // Fills the authentication info with the server's response. | 169 // Fills the authentication info with the server's response. |
170 virtual void GetAuthChallengeInfo( | 170 virtual void GetAuthChallengeInfo( |
171 scoped_refptr<net::AuthChallengeInfo>* auth_info); | 171 scoped_refptr<net::AuthChallengeInfo>* auth_info); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // a glorified set_status, but also does internal state checking and | 233 // a glorified set_status, but also does internal state checking and |
234 // job tracking. It should be called once per request, when the job is | 234 // job tracking. It should be called once per request, when the job is |
235 // finished doing all IO. | 235 // finished doing all IO. |
236 void NotifyDone(const URLRequestStatus& status); | 236 void NotifyDone(const URLRequestStatus& status); |
237 | 237 |
238 // Some work performed by NotifyDone must be completed on a separate task | 238 // Some work performed by NotifyDone must be completed on a separate task |
239 // so as to avoid re-entering the delegate. This method exists to perform | 239 // so as to avoid re-entering the delegate. This method exists to perform |
240 // that work. | 240 // that work. |
241 void CompleteNotifyDone(); | 241 void CompleteNotifyDone(); |
242 | 242 |
243 // Used as an asynchronous callback for Kill to notify the URLRequest that | 243 // Used as an asynchronous callback for Kill to notify the net::URLRequest |
244 // we were canceled. | 244 // that we were canceled. |
245 void NotifyCanceled(); | 245 void NotifyCanceled(); |
246 | 246 |
247 // Notifies the job the request should be restarted. | 247 // Notifies the job the request should be restarted. |
248 // Should only be called if the job has not started a resposne. | 248 // Should only be called if the job has not started a resposne. |
249 void NotifyRestartRequired(); | 249 void NotifyRestartRequired(); |
250 | 250 |
251 // Called to read raw (pre-filtered) data from this Job. | 251 // Called to read raw (pre-filtered) data from this Job. |
252 // If returning true, data was read from the job. buf will contain | 252 // If returning true, data was read from the job. buf will contain |
253 // the data, and bytes_read will receive the number of bytes read. | 253 // the data, and bytes_read will receive the number of bytes read. |
254 // If returning true, and bytes_read is returned as 0, there is no | 254 // If returning true, and bytes_read is returned as 0, there is no |
255 // additional data to be read. | 255 // additional data to be read. |
256 // If returning false, an error occurred or an async IO is now pending. | 256 // If returning false, an error occurred or an async IO is now pending. |
257 // If async IO is pending, the status of the request will be | 257 // If async IO is pending, the status of the request will be |
258 // URLRequestStatus::IO_PENDING, and buf must remain available until the | 258 // URLRequestStatus::IO_PENDING, and buf must remain available until the |
259 // operation is completed. See comments on URLRequest::Read for more info. | 259 // operation is completed. See comments on net::URLRequest::Read for more |
| 260 // info. |
260 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); | 261 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); |
261 | 262 |
262 // Informs the filter that data has been read into its buffer | 263 // Informs the filter that data has been read into its buffer |
263 void FilteredDataRead(int bytes_read); | 264 void FilteredDataRead(int bytes_read); |
264 | 265 |
265 // Reads filtered data from the request. Returns true if successful, | 266 // Reads filtered data from the request. Returns true if successful, |
266 // false otherwise. Note, if there is not enough data received to | 267 // false otherwise. Note, if there is not enough data received to |
267 // return data, this call can issue a new async IO request under | 268 // return data, this call can issue a new async IO request under |
268 // the hood. | 269 // the hood. |
269 bool ReadFilteredData(int *bytes_read); | 270 bool ReadFilteredData(int *bytes_read); |
(...skipping 21 matching lines...) Expand all Loading... |
291 // Whether the job is doing performance profiling | 292 // Whether the job is doing performance profiling |
292 bool is_profiling_; | 293 bool is_profiling_; |
293 | 294 |
294 // Contains IO performance measurement when profiling is enabled. | 295 // Contains IO performance measurement when profiling is enabled. |
295 scoped_ptr<URLRequestJobMetrics> metrics_; | 296 scoped_ptr<URLRequestJobMetrics> metrics_; |
296 | 297 |
297 // The number of bytes read before passing to the filter. | 298 // The number of bytes read before passing to the filter. |
298 int prefilter_bytes_read_; | 299 int prefilter_bytes_read_; |
299 // The number of bytes read after passing through the filter. | 300 // The number of bytes read after passing through the filter. |
300 int postfilter_bytes_read_; | 301 int postfilter_bytes_read_; |
301 // True when (we believe) the content in this URLRequest was compressible. | 302 // True when (we believe) the content in this net::URLRequest was |
| 303 // compressible. |
302 bool is_compressible_content_; | 304 bool is_compressible_content_; |
303 // True when the content in this URLRequest was compressed. | 305 // True when the content in this net::URLRequest was compressed. |
304 bool is_compressed_; | 306 bool is_compressed_; |
305 | 307 |
306 private: | 308 private: |
307 // Size of filter input buffers used by this class. | 309 // Size of filter input buffers used by this class. |
308 static const int kFilterBufSize; | 310 static const int kFilterBufSize; |
309 | 311 |
310 // When data filtering is enabled, this function is used to read data | 312 // When data filtering is enabled, this function is used to read data |
311 // for the filter. Returns true if raw data was read. Returns false if | 313 // for the filter. Returns true if raw data was read. Returns false if |
312 // an error occurred (or we are waiting for IO to complete). | 314 // an error occurred (or we are waiting for IO to complete). |
313 bool ReadRawDataForFilter(int *bytes_read); | 315 bool ReadRawDataForFilter(int *bytes_read); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 int observed_packet_count_; | 422 int observed_packet_count_; |
421 | 423 |
422 DISALLOW_COPY_AND_ASSIGN(URLRequestJob); | 424 DISALLOW_COPY_AND_ASSIGN(URLRequestJob); |
423 }; | 425 }; |
424 | 426 |
425 } // namespace net | 427 } // namespace net |
426 | 428 |
427 typedef net::URLRequestJob URLRequestJob; | 429 typedef net::URLRequestJob URLRequestJob; |
428 | 430 |
429 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_H_ | 431 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_H_ |
OLD | NEW |