OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/power_monitor/power_observer.h" | 17 #include "base/power_monitor/power_observer.h" |
18 #include "net/base/host_port_pair.h" | 18 #include "net/base/host_port_pair.h" |
19 #include "net/base/load_states.h" | 19 #include "net/base/load_states.h" |
20 #include "net/base/net_errors.h" | |
20 #include "net/base/net_export.h" | 21 #include "net/base/net_export.h" |
21 #include "net/base/request_priority.h" | 22 #include "net/base/request_priority.h" |
22 #include "net/base/upload_progress.h" | 23 #include "net/base/upload_progress.h" |
23 #include "net/cookies/canonical_cookie.h" | 24 #include "net/cookies/canonical_cookie.h" |
24 #include "net/socket/connection_attempts.h" | 25 #include "net/socket/connection_attempts.h" |
25 #include "net/url_request/redirect_info.h" | 26 #include "net/url_request/redirect_info.h" |
26 #include "net/url_request/url_request.h" | 27 #include "net/url_request/url_request.h" |
27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
28 | 29 |
29 namespace net { | 30 namespace net { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 | 270 |
270 // Delegates to URLRequest::Delegate. | 271 // Delegates to URLRequest::Delegate. |
271 bool CanEnablePrivacyMode() const; | 272 bool CanEnablePrivacyMode() const; |
272 | 273 |
273 // Notifies the job that the network is about to be used. | 274 // Notifies the job that the network is about to be used. |
274 void NotifyBeforeNetworkStart(bool* defer); | 275 void NotifyBeforeNetworkStart(bool* defer); |
275 | 276 |
276 // Notifies the job that headers have been received. | 277 // Notifies the job that headers have been received. |
277 void NotifyHeadersComplete(); | 278 void NotifyHeadersComplete(); |
278 | 279 |
279 // Notifies the request that the job has completed a Read operation. | |
280 void NotifyReadComplete(int bytes_read); | |
281 | |
282 // Notifies the request that a start error has occurred. | 280 // Notifies the request that a start error has occurred. |
283 void NotifyStartError(const URLRequestStatus& status); | 281 void NotifyStartError(const URLRequestStatus& status); |
284 | 282 |
285 // NotifyDone marks when we are done with a request. It is really | |
286 // a glorified set_status, but also does internal state checking and | |
287 // job tracking. It should be called once per request, when the job is | |
288 // finished doing all IO. | |
289 void NotifyDone(const URLRequestStatus& status); | |
290 | |
291 // Some work performed by NotifyDone must be completed on a separate task | |
292 // so as to avoid re-entering the delegate. This method exists to perform | |
293 // that work. | |
294 void CompleteNotifyDone(); | |
295 | |
296 // Used as an asynchronous callback for Kill to notify the URLRequest | 283 // Used as an asynchronous callback for Kill to notify the URLRequest |
297 // that we were canceled. | 284 // that we were canceled. |
298 void NotifyCanceled(); | 285 void NotifyCanceled(); |
299 | 286 |
300 // Notifies the job the request should be restarted. | 287 // Notifies the job the request should be restarted. |
301 // Should only be called if the job has not started a response. | 288 // Should only be called if the job has not started a response. |
302 void NotifyRestartRequired(); | 289 void NotifyRestartRequired(); |
303 | 290 |
304 // See corresponding functions in url_request.h. | 291 // See corresponding functions in url_request.h. |
305 void OnCallToDelegate(); | 292 void OnCallToDelegate(); |
306 void OnCallToDelegateComplete(); | 293 void OnCallToDelegateComplete(); |
307 | 294 |
308 // Called to read raw (pre-filtered) data from this Job. | 295 // Called to read raw (pre-filtered) data from this Job. Reads at most |
309 // If returning true, data was read from the job. buf will contain | 296 // |buf_size| bytes into |buf|. |
310 // the data, and bytes_read will receive the number of bytes read. | 297 // Possible return values: |
311 // If returning true, and bytes_read is returned as 0, there is no | 298 // >= 0: Read completed synchronously. Return value is the number of bytes |
312 // additional data to be read. | 299 // read. |
mmenke
2015/10/22 18:58:11
Maybe add "0 means eof"?
xunjieli
2015/10/23 13:43:08
Done.
| |
313 // If returning false, an error occurred or an async IO is now pending. | 300 // ERR_IO_PENDING: Read pending asynchronously. |
314 // If async IO is pending, the status of the request will be | 301 // When the read completes, |ReadRawDataComplete| should be |
315 // URLRequestStatus::IO_PENDING, and buf must remain available until the | 302 // called. |
316 // operation is completed. See comments on URLRequest::Read for more | 303 // Any other ERR_: Read failed synchronously. |
mmenke
2015/10/22 18:58:11
Maybe: Something like: "Any other negative numbe
xunjieli
2015/10/23 13:43:08
Done.
| |
317 // info. | 304 // This method might hold onto a reference to |buf| until it completes or is |
318 virtual bool ReadRawData(IOBuffer* buf, int buf_size, int *bytes_read); | 305 // cancelled using the refcount on |buf|. |
Randy Smith (Not in Mondays)
2015/10/22 20:38:45
nit, suggestion: I find this sentence a bit confus
xunjieli
2015/10/23 13:43:08
Done.
| |
306 virtual int ReadRawData(IOBuffer* buf, int buf_size); | |
319 | 307 |
320 // Called to tell the job that a filter has successfully reached the end of | 308 // Called to tell the job that a filter has successfully reached the end of |
321 // the stream. | 309 // the stream. |
322 virtual void DoneReading(); | 310 virtual void DoneReading(); |
323 | 311 |
324 // Called to tell the job that the body won't be read because it's a redirect. | 312 // Called to tell the job that the body won't be read because it's a redirect. |
325 // This is needed so that redirect headers can be cached even though their | 313 // This is needed so that redirect headers can be cached even though their |
326 // bodies are never read. | 314 // bodies are never read. |
327 virtual void DoneReadingRedirectResponse(); | 315 virtual void DoneReadingRedirectResponse(); |
328 | 316 |
329 // Informs the filter that data has been read into its buffer | 317 // Reads filtered data from the request. Returns OK if immediately successful, |
330 void FilteredDataRead(int bytes_read); | 318 // ERR_IO_PENDING if the request couldn't complete synchronously, and some |
331 | 319 // other error code if the request failed synchronously. Note that this |
332 // Reads filtered data from the request. Returns true if successful, | 320 // function can issue new asynchronous requests if needed, in which case it |
333 // false otherwise. Note, if there is not enough data received to | 321 // returns ERR_IO_PENDING. If this method completes synchronously, |
334 // return data, this call can issue a new async IO request under | 322 // |*bytes_read| is the number of bytes output by the filter chain if this |
335 // the hood. | 323 // method returns OK, or zero if this method returns an error. |
336 bool ReadFilteredData(int *bytes_read); | 324 Error ReadFilteredData(int* bytes_read); |
337 | 325 |
338 // Whether the response is being filtered in this job. | 326 // Whether the response is being filtered in this job. |
339 // Only valid after NotifyHeadersComplete() has been called. | 327 // Only valid after NotifyHeadersComplete() has been called. |
340 bool HasFilter() { return filter_ != NULL; } | 328 bool HasFilter() { return filter_ != NULL; } |
341 | 329 |
342 // At or near destruction time, a derived class may request that the filters | 330 // At or near destruction time, a derived class may request that the filters |
343 // be destroyed so that statistics can be gathered while the derived class is | 331 // be destroyed so that statistics can be gathered while the derived class is |
344 // still present to assist in calculations. This is used by URLRequestHttpJob | 332 // still present to assist in calculations. This is used by URLRequestHttpJob |
345 // to get SDCH to emit stats. | 333 // to get SDCH to emit stats. |
346 void DestroyFilters(); | 334 void DestroyFilters(); |
(...skipping 11 matching lines...) Expand all Loading... | |
358 void SetProxyServer(const HostPortPair& proxy_server); | 346 void SetProxyServer(const HostPortPair& proxy_server); |
359 | 347 |
360 // The number of bytes read before passing to the filter. This value reflects | 348 // The number of bytes read before passing to the filter. This value reflects |
361 // bytes read even when there is no filter. | 349 // bytes read even when there is no filter. |
362 int64 prefilter_bytes_read() const { return prefilter_bytes_read_; } | 350 int64 prefilter_bytes_read() const { return prefilter_bytes_read_; } |
363 | 351 |
364 // The number of bytes read after passing through the filter. This value | 352 // The number of bytes read after passing through the filter. This value |
365 // reflects bytes read even when there is no filter. | 353 // reflects bytes read even when there is no filter. |
366 int64 postfilter_bytes_read() const { return postfilter_bytes_read_; } | 354 int64 postfilter_bytes_read() const { return postfilter_bytes_read_; } |
367 | 355 |
356 // Turns an integer result code as from |ReadRawData| into an Error and a | |
mmenke
2015/10/22 18:58:11
Suggest "Turns an integer result code as from" ->
xunjieli
2015/10/23 13:43:08
Done.
| |
357 // count of bytes read. The semantics are: | |
358 // |result| >= 0: |*error| == OK, |*count| == |result| | |
359 // |result| < 0: |*error| = |result|, |*count| == 0 | |
360 static void ConvertResultToError(int result, Error* error, int* count); | |
361 | |
362 // Completion callback for raw reads. See |ReadRawData| for details. | |
363 // |bytes_read| is either >= 0 to indicate a successful read and count of | |
364 // bytes read, or < 0 to indicate an error. | |
365 void ReadRawDataComplete(int bytes_read); | |
366 | |
368 // The request that initiated this job. This value MAY BE NULL if the | 367 // The request that initiated this job. This value MAY BE NULL if the |
369 // request was released by DetachRequest(). | 368 // request was released by DetachRequest(). |
370 URLRequest* request_; | 369 URLRequest* request_; |
371 | 370 |
372 private: | 371 private: |
373 // When data filtering is enabled, this function is used to read data | 372 // When data filtering is enabled, this function is used to read data |
374 // for the filter. Returns true if raw data was read. Returns false if | 373 // for the filter. Returns true if raw data was read. Returns false if |
375 // an error occurred (or we are waiting for IO to complete). | 374 // an error occurred (or we are waiting for IO to complete). |
mmenke
2015/10/22 18:58:11
This comment is no longer accurate
xunjieli
2015/10/23 13:43:08
Done.
| |
376 bool ReadRawDataForFilter(int *bytes_read); | 375 Error ReadRawDataForFilter(int* bytes_read); |
376 | |
377 // Informs the filter that data has been read into its buffer. | |
Randy Smith (Not in Mondays)
2015/10/22 20:38:45
nit, suggestion: "Inform the filter chain" or "Inf
xunjieli
2015/10/23 13:43:08
Done.
| |
378 void PushInputToFilter(int bytes_read); | |
377 | 379 |
378 // Invokes ReadRawData and records bytes read if the read completes | 380 // Invokes ReadRawData and records bytes read if the read completes |
379 // synchronously. | 381 // synchronously. |
380 bool ReadRawDataHelper(IOBuffer* buf, int buf_size, int* bytes_read); | 382 Error ReadRawDataHelper(IOBuffer* buf, int buf_size, int* bytes_read); |
381 | 383 |
382 // Called in response to a redirect that was not canceled to follow the | 384 // Called in response to a redirect that was not canceled to follow the |
383 // redirect. The current job will be replaced with a new job loading the | 385 // redirect. The current job will be replaced with a new job loading the |
384 // given redirect destination. | 386 // given redirect destination. |
385 void FollowRedirect(const RedirectInfo& redirect_info); | 387 void FollowRedirect(const RedirectInfo& redirect_info); |
386 | 388 |
387 // Called after every raw read. If |bytes_read| is > 0, this indicates | 389 // Called after every raw read. If |bytes_read| is > 0, this indicates |
388 // a successful read of |bytes_read| unfiltered bytes. If |bytes_read| | 390 // a successful read of |bytes_read| unfiltered bytes. If |bytes_read| |
389 // is 0, this indicates that there is no additional data to read. If | 391 // is 0, this indicates that there is no additional data to read. If |
390 // |bytes_read| is < 0, an error occurred and no bytes were read. | 392 // |bytes_read| is < 0, an error occurred and no bytes were read. |
mmenke
2015/10/22 18:58:11
This comment needs to be updated.
xunjieli
2015/10/23 13:43:08
Done.
| |
391 void OnRawReadComplete(int bytes_read); | 393 void GatherRawReadStats(Error error, int bytes_read); |
392 | 394 |
393 // Updates the profiling info and notifies observers that an additional | 395 // Updates the profiling info and notifies observers that an additional |
394 // |bytes_read| unfiltered bytes have been read for this job. | 396 // |bytes_read| unfiltered bytes have been read for this job. |
395 void RecordBytesRead(int bytes_read); | 397 void RecordBytesRead(int bytes_read); |
396 | 398 |
397 // Called to query whether there is data available in the filter to be read | 399 // Called to query whether there is data available in the filter to be read |
398 // out. | 400 // out. |
399 bool FilterHasData(); | 401 bool FilterHasData(); |
400 | 402 |
403 // NotifyDone marks when we are done with a request. It is really | |
404 // a glorified set_status, but also does internal state checking and | |
405 // job tracking. It should be called once per request, when the job is | |
406 // finished doing all IO. | |
mmenke
2015/10/22 18:58:11
nit: --"we"
xunjieli
2015/10/23 13:43:08
Done.
| |
407 void NotifyDone(const URLRequestStatus& status); | |
408 | |
409 // Some work performed by NotifyDone must be completed on a separate task so | |
mmenke
2015/10/22 18:58:11
suggest "on a separate task" -> "asynchronously"
xunjieli
2015/10/23 13:43:08
Done.
| |
410 // as to avoid re-entering URLRequest::Delegate. This method exists to | |
411 // perform that work. | |
mmenke
2015/10/22 18:58:11
"exists to perform" -> "performs"
xunjieli
2015/10/23 13:43:08
Done.
| |
412 void CompleteNotifyDone(); | |
413 | |
401 // Subclasses may implement this method to record packet arrival times. | 414 // Subclasses may implement this method to record packet arrival times. |
402 // The default implementation does nothing. Only invoked when bytes have been | 415 // The default implementation does nothing. Only invoked when bytes have been |
403 // read since the last invocation. | 416 // read since the last invocation. |
404 virtual void UpdatePacketReadTimes(); | 417 virtual void UpdatePacketReadTimes(); |
405 | 418 |
406 // Computes a new RedirectInfo based on receiving a redirect response of | 419 // Computes a new RedirectInfo based on receiving a redirect response of |
407 // |location| and |http_status_code|. | 420 // |location| and |http_status_code|. |
408 RedirectInfo ComputeRedirectInfo(const GURL& location, int http_status_code); | 421 RedirectInfo ComputeRedirectInfo(const GURL& location, int http_status_code); |
409 | 422 |
410 // Notify the network delegate that more bytes have been received or sent over | 423 // Notify the network delegate that more bytes have been received or sent over |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 int64_t last_notified_total_sent_bytes_; | 475 int64_t last_notified_total_sent_bytes_; |
463 | 476 |
464 base::WeakPtrFactory<URLRequestJob> weak_factory_; | 477 base::WeakPtrFactory<URLRequestJob> weak_factory_; |
465 | 478 |
466 DISALLOW_COPY_AND_ASSIGN(URLRequestJob); | 479 DISALLOW_COPY_AND_ASSIGN(URLRequestJob); |
467 }; | 480 }; |
468 | 481 |
469 } // namespace net | 482 } // namespace net |
470 | 483 |
471 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_H_ | 484 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_H_ |
OLD | NEW |