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_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_H_ |
6 #define NET_URL_REQUEST_URL_REQUEST_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 // indicating what's wrong with the certificate. | 189 // indicating what's wrong with the certificate. |
190 // If |fatal| is true then the host in question demands a higher level | 190 // If |fatal| is true then the host in question demands a higher level |
191 // of security (due e.g. to HTTP Strict Transport Security, user | 191 // of security (due e.g. to HTTP Strict Transport Security, user |
192 // preference, or built-in policy). In this case, errors must not be | 192 // preference, or built-in policy). In this case, errors must not be |
193 // bypassable by the user. | 193 // bypassable by the user. |
194 virtual void OnSSLCertificateError(URLRequest* request, | 194 virtual void OnSSLCertificateError(URLRequest* request, |
195 const SSLInfo& ssl_info, | 195 const SSLInfo& ssl_info, |
196 bool fatal); | 196 bool fatal); |
197 | 197 |
198 // After calling Start(), the delegate will receive an OnResponseStarted | 198 // After calling Start(), the delegate will receive an OnResponseStarted |
199 // callback when the request has completed. If an error occurred, the | 199 // callback when the request has completed. |net_error| will be set to OK |
200 // request->status() will be set. On success, all redirects have been | 200 // or an actual net error. On success, all redirects have been |
201 // followed and the final response is beginning to arrive. At this point, | 201 // followed and the final response is beginning to arrive. At this point, |
202 // meta data about the response is available, including for example HTTP | 202 // meta data about the response is available, including for example HTTP |
203 // response headers if this is a request for a HTTP resource. | 203 // response headers if this is a request for a HTTP resource. |
204 virtual void OnResponseStarted(URLRequest* request) = 0; | 204 virtual void OnResponseStarted(URLRequest* request, int net_error); |
205 // Deprecated. | |
206 virtual void OnResponseStarted(URLRequest* request); | |
205 | 207 |
206 // Called when the a Read of the response body is completed after an | 208 // Called when the a Read of the response body is completed after an |
207 // IO_PENDING status from a Read() call. | 209 // IO_PENDING status from a Read() call. |
208 // The data read is filled into the buffer which the caller passed | 210 // The data read is filled into the buffer which the caller passed |
209 // to Read() previously. | 211 // to Read() previously. |
210 // | 212 // |
211 // If an error occurred, request->status() will contain the error, | 213 // If an error occurred, |bytes_read| will be set to the error. |
212 // and bytes read will be -1. | |
213 virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0; | 214 virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0; |
214 | 215 |
216 // Used to call OnResponseStarted(). There are two the same methods. The one | |
217 // that has |net_error| in arguments is a new one. This method is used to | |
218 // distinguish whether clients have already overridden new OnResponseStarted | |
219 // and call that one instead of old one without |net_error|. | |
220 // | |
221 // The method will be removed as soon as all clients are modified. | |
222 void NotifyOnResponseStarted(URLRequest* request, int net_error); | |
223 | |
215 protected: | 224 protected: |
216 virtual ~Delegate() {} | 225 virtual ~Delegate() {} |
226 | |
227 private: | |
228 // Used to distinguish whether modified a method is overridden by clients. | |
229 bool implemented_; | |
217 }; | 230 }; |
218 | 231 |
219 // If destroyed after Start() has been called but while IO is pending, | 232 // If destroyed after Start() has been called but while IO is pending, |
220 // then the request will be effectively canceled and the delegate | 233 // then the request will be effectively canceled and the delegate |
221 // will not have any more of its methods called. | 234 // will not have any more of its methods called. |
222 ~URLRequest() override; | 235 ~URLRequest() override; |
223 | 236 |
224 // Changes the default cookie policy from allowing all cookies to blocking all | 237 // Changes the default cookie policy from allowing all cookies to blocking all |
225 // cookies. Embedders that want to implement a more flexible policy should | 238 // cookies. Embedders that want to implement a more flexible policy should |
226 // change the default to blocking all cookies, and provide a NetworkDelegate | 239 // change the default to blocking all cookies, and provide a NetworkDelegate |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 void SetLoadFlags(int flags); | 530 void SetLoadFlags(int flags); |
518 | 531 |
519 // Returns true if the request is "pending" (i.e., if Start() has been called, | 532 // Returns true if the request is "pending" (i.e., if Start() has been called, |
520 // and the response has not yet been called). | 533 // and the response has not yet been called). |
521 bool is_pending() const { return is_pending_; } | 534 bool is_pending() const { return is_pending_; } |
522 | 535 |
523 // Returns true if the request is in the process of redirecting to a new | 536 // Returns true if the request is in the process of redirecting to a new |
524 // URL but has not yet initiated the new request. | 537 // URL but has not yet initiated the new request. |
525 bool is_redirecting() const { return is_redirecting_; } | 538 bool is_redirecting() const { return is_redirecting_; } |
526 | 539 |
527 // Returns the error status of the request. | |
528 const URLRequestStatus& status() const { return status_; } | |
529 | |
530 // Returns a globally unique identifier for this request. | 540 // Returns a globally unique identifier for this request. |
531 uint64_t identifier() const { return identifier_; } | 541 uint64_t identifier() const { return identifier_; } |
532 | 542 |
533 // This method is called to start the request. The delegate will receive | 543 // This method is called to start the request. The delegate will receive |
534 // a OnResponseStarted callback when the request is started. The request | 544 // a OnResponseStarted callback when the request is started. The request |
535 // must have a delegate set before this method is called. | 545 // must have a delegate set before this method is called. |
536 void Start(); | 546 void Start(); |
537 | 547 |
538 // This method may be called at any time after Start() has been called to | 548 // This method may be called at any time after Start() has been called to |
539 // cancel the request. This method may be called many times, and it has | 549 // cancel the request. This method may be called many times, and it has |
540 // no effect once the response has completed. It is guaranteed that no | 550 // no effect once the response has completed. It is guaranteed that no |
541 // methods of the delegate will be called after the request has been | 551 // methods of the delegate will be called after the request has been |
542 // cancelled, except that this may call the delegate's OnReadCompleted() | 552 // cancelled, except that this may call the delegate's OnReadCompleted() |
543 // during the call to Cancel itself. | 553 // during the call to Cancel itself. Returns |ERR_ABORTED| or other net error |
544 void Cancel(); | 554 // if there was one. |
555 int Cancel(); | |
545 | 556 |
546 // Cancels the request and sets the error to |error| (see net_error_list.h | 557 // Cancels the request and sets the error to |error| (see net_error_list.h |
547 // for values). | 558 // for values). Returns set error. |
548 void CancelWithError(int error); | 559 int CancelWithError(int error); |
mmenke
2016/08/26 19:36:48
Can we just make these void? Some things that can
maksims (do not use this acc)
2016/08/29 12:30:35
Well, It might, but I'm not 100% sure.. I just wan
| |
549 | 560 |
550 // Cancels the request and sets the error to |error| (see net_error_list.h | 561 // Cancels the request and sets the error to |error| (see net_error_list.h |
551 // for values) and attaches |ssl_info| as the SSLInfo for that request. This | 562 // for values) and attaches |ssl_info| as the SSLInfo for that request. This |
552 // is useful to attach a certificate and certificate error to a canceled | 563 // is useful to attach a certificate and certificate error to a canceled |
553 // request. | 564 // request. |
554 void CancelWithSSLError(int error, const SSLInfo& ssl_info); | 565 void CancelWithSSLError(int error, const SSLInfo& ssl_info); |
555 | 566 |
556 // Read initiates an asynchronous read from the response, and must only | 567 // Read initiates an asynchronous read from the response, and must only |
557 // be called after the OnResponseStarted callback is received with a | 568 // be called after the OnResponseStarted callback is received with a net::OK. |
558 // successful status. | 569 // If data is available, length and the data will be returned immediately. |
mmenke
2016/08/26 19:36:48
I'd mention net error on failure up here instead,
maksims (do not use this acc)
2016/08/29 12:30:35
I didn't get it.
| |
559 // If data is available, Read will return true, and the data and length will | 570 // If data is not available, Read returns net::ERR_IO_PENDING, and an |
560 // be returned immediately. If data is not available, Read returns false, | 571 // asynchronous Read is initiated.The Read is finished when the caller |
mmenke
2016/08/26 19:36:48
Space after period.
maksims (do not use this acc)
2016/08/29 12:30:36
Done.
| |
561 // and an asynchronous Read is initiated. The Read is finished when | 572 // receives the OnReadComplete callback. Unless the request was |
562 // the caller receives the OnReadComplete callback. Unless the request was | |
563 // cancelled, OnReadComplete will always be called, even if the read failed. | 573 // cancelled, OnReadComplete will always be called, even if the read failed. |
574 // A value of 0 indicates that there is no more data available to read from | |
575 // the stream. | |
mmenke
2016/08/26 19:36:48
Suggest removing the last sentence, and just modif
maksims (do not use this acc)
2016/08/29 12:30:35
Done.
| |
576 // | |
577 // If an error occurs during synchronous read, net error is | |
578 // returned immediately, otherwise OnReadComplete callback will be called with | |
mmenke
2016/08/26 19:36:48
otherwise -> If an error occurs asynchronously,
maksims (do not use this acc)
2016/08/29 12:30:36
Done.
| |
579 // |net_error| set to an actual error. | |
mmenke
2016/08/26 19:36:48
"|net_error| set to an actual error" -> "the net e
maksims (do not use this acc)
2016/08/29 12:30:36
Done.
| |
564 // | 580 // |
565 // The buf parameter is a buffer to receive the data. If the operation | 581 // The buf parameter is a buffer to receive the data. If the operation |
566 // completes asynchronously, the implementation will reference the buffer | 582 // completes asynchronously, the implementation will reference the buffer |
567 // until OnReadComplete is called. The buffer must be at least max_bytes in | 583 // until OnReadComplete is called. The buffer must be at least max_bytes in |
568 // length. | 584 // length. |
569 // | 585 // |
570 // The max_bytes parameter is the maximum number of bytes to read. | 586 // The max_bytes parameter is the maximum number of bytes to read. |
571 // | 587 int Read(IOBuffer* buf, int max_bytes); |
572 // The bytes_read parameter is an output parameter containing the | 588 // Deprecated. |
573 // the number of bytes read. A value of 0 indicates that there is no | |
574 // more data available to read from the stream. | |
575 // | |
576 // If a read error occurs, Read returns false and the request->status | |
577 // will be set to an error. | |
578 bool Read(IOBuffer* buf, int max_bytes, int* bytes_read); | 589 bool Read(IOBuffer* buf, int max_bytes, int* bytes_read); |
579 | 590 |
580 // If this request is being cached by the HTTP cache, stop subsequent caching. | 591 // If this request is being cached by the HTTP cache, stop subsequent caching. |
581 // Note that this method has no effect on other (simultaneous or not) requests | 592 // Note that this method has no effect on other (simultaneous or not) requests |
582 // for the same resource. The typical example is a request that results in | 593 // for the same resource. The typical example is a request that results in |
583 // the data being stored to disk (downloaded instead of rendered) so we don't | 594 // the data being stored to disk (downloaded instead of rendered) so we don't |
584 // want to store it twice. | 595 // want to store it twice. |
585 void StopCaching(); | 596 void StopCaching(); |
586 | 597 |
587 // This method may be called to follow a redirect that was deferred in | 598 // This method may be called to follow a redirect that was deferred in |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 // the more general response_info() is available, even though it is a subset. | 652 // the more general response_info() is available, even though it is a subset. |
642 const HostPortPair& proxy_server() const { | 653 const HostPortPair& proxy_server() const { |
643 return proxy_server_; | 654 return proxy_server_; |
644 } | 655 } |
645 | 656 |
646 // Gets the connection attempts made in the process of servicing this | 657 // Gets the connection attempts made in the process of servicing this |
647 // URLRequest. Only guaranteed to be valid if called after the request fails | 658 // URLRequest. Only guaranteed to be valid if called after the request fails |
648 // or after the response headers are received. | 659 // or after the response headers are received. |
649 void GetConnectionAttempts(ConnectionAttempts* out) const; | 660 void GetConnectionAttempts(ConnectionAttempts* out) const; |
650 | 661 |
662 // Returns the error status of the request. | |
663 // Do not use! Going to be protected! | |
664 const URLRequestStatus& status() const { return status_; } | |
mmenke
2016/08/26 19:36:48
Note that we could make this private, and friend c
maksims (do not use this acc)
2016/08/29 12:30:35
I'll consider this as well.
| |
665 | |
651 protected: | 666 protected: |
652 // Allow the URLRequestJob class to control the is_pending() flag. | 667 // Allow the URLRequestJob class to control the is_pending() flag. |
653 void set_is_pending(bool value) { is_pending_ = value; } | 668 void set_is_pending(bool value) { is_pending_ = value; } |
654 | 669 |
655 // Allow the URLRequestJob class to set our status too. | 670 // Allow the URLRequestJob class to set our status too. |
656 void set_status(URLRequestStatus status); | 671 void set_status(URLRequestStatus status); |
657 | 672 |
658 // Allow the URLRequestJob to redirect this request. Returns OK if | 673 // Allow the URLRequestJob to redirect this request. Returns OK if |
659 // successful, otherwise an error code is returned. | 674 // successful, otherwise an error code is returned. |
660 int Redirect(const RedirectInfo& redirect_info); | 675 int Redirect(const RedirectInfo& redirect_info); |
661 | 676 |
662 // Called by URLRequestJob to allow interception when a redirect occurs. | 677 // Called by URLRequestJob to allow interception when a redirect occurs. |
663 void NotifyReceivedRedirect(const RedirectInfo& redirect_info, | 678 void NotifyReceivedRedirect(const RedirectInfo& redirect_info, |
664 bool* defer_redirect); | 679 bool* defer_redirect); |
665 | 680 |
666 // Allow an interceptor's URLRequestJob to restart this request. | 681 // Allow an interceptor's URLRequestJob to restart this request. |
667 // Should only be called if the original job has not started a response. | 682 // Should only be called if the original job has not started a response. |
668 void Restart(); | 683 void Restart(); |
669 | 684 |
670 private: | 685 private: |
671 friend class URLRequestJob; | 686 friend class URLRequestJob; |
672 friend class URLRequestContext; | 687 friend class URLRequestContext; |
673 | 688 |
689 // Temporarily for testing purposes. | |
mmenke
2016/08/26 19:36:48
Suggest this:
// For testing purposes.
// TODO(ma
maksims (do not use this acc)
2016/08/29 12:30:35
Done.
| |
690 friend class TestNetworkDelegate; | |
691 | |
674 // URLRequests are always created by calling URLRequestContext::CreateRequest. | 692 // URLRequests are always created by calling URLRequestContext::CreateRequest. |
675 // | 693 // |
676 // If no network delegate is passed in, will use the ones from the | 694 // If no network delegate is passed in, will use the ones from the |
677 // URLRequestContext. | 695 // URLRequestContext. |
678 URLRequest(const GURL& url, | 696 URLRequest(const GURL& url, |
679 RequestPriority priority, | 697 RequestPriority priority, |
680 Delegate* delegate, | 698 Delegate* delegate, |
681 const URLRequestContext* context, | 699 const URLRequestContext* context, |
682 NetworkDelegate* network_delegate); | 700 NetworkDelegate* network_delegate); |
683 | 701 |
(...skipping 11 matching lines...) Expand all Loading... | |
695 // happens when following a HTTP redirect. | 713 // happens when following a HTTP redirect. |
696 void RestartWithJob(URLRequestJob* job); | 714 void RestartWithJob(URLRequestJob* job); |
697 void PrepareToRestart(); | 715 void PrepareToRestart(); |
698 | 716 |
699 // Detaches the job from this request in preparation for this object going | 717 // Detaches the job from this request in preparation for this object going |
700 // away or the job being replaced. The job will not call us back when it has | 718 // away or the job being replaced. The job will not call us back when it has |
701 // been orphaned. | 719 // been orphaned. |
702 void OrphanJob(); | 720 void OrphanJob(); |
703 | 721 |
704 // Cancels the request and set the error and ssl info for this request to the | 722 // Cancels the request and set the error and ssl info for this request to the |
705 // passed values. | 723 // passed values. Returns the error that was set. |
706 void DoCancel(int error, const SSLInfo& ssl_info); | 724 int DoCancel(int error, const SSLInfo& ssl_info); |
707 | 725 |
708 // Called by the URLRequestJob when the headers are received, before any other | 726 // Called by the URLRequestJob when the headers are received, before any other |
709 // method, to allow caching of load timing information. | 727 // method, to allow caching of load timing information. |
710 void OnHeadersComplete(); | 728 void OnHeadersComplete(); |
711 | 729 |
712 // Notifies the network delegate that the request has been completed. | 730 // Notifies the network delegate that the request has been completed. |
713 // This does not imply a successful completion. Also a canceled request is | 731 // This does not imply a successful completion. Also a canceled request is |
714 // considered completed. | 732 // considered completed. |
715 void NotifyRequestCompleted(); | 733 void NotifyRequestCompleted(); |
716 | 734 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
847 | 865 |
848 // The proxy server used for this request, if any. | 866 // The proxy server used for this request, if any. |
849 HostPortPair proxy_server_; | 867 HostPortPair proxy_server_; |
850 | 868 |
851 DISALLOW_COPY_AND_ASSIGN(URLRequest); | 869 DISALLOW_COPY_AND_ASSIGN(URLRequest); |
852 }; | 870 }; |
853 | 871 |
854 } // namespace net | 872 } // namespace net |
855 | 873 |
856 #endif // NET_URL_REQUEST_URL_REQUEST_H_ | 874 #endif // NET_URL_REQUEST_URL_REQUEST_H_ |
OLD | NEW |