| 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     // TODO(maksims): Remove this; | 
 |  207     virtual void OnResponseStarted(URLRequest* request); | 
|  205  |  208  | 
|  206     // Called when the a Read of the response body is completed after an |  209     // Called when the a Read of the response body is completed after an | 
|  207     // IO_PENDING status from a Read() call. |  210     // IO_PENDING status from a Read() call. | 
|  208     // The data read is filled into the buffer which the caller passed |  211     // The data read is filled into the buffer which the caller passed | 
|  209     // to Read() previously. |  212     // to Read() previously. | 
|  210     // |  213     // | 
|  211     // If an error occurred, request->status() will contain the error, |  214     // 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; |  215     virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0; | 
|  214  |  216  | 
|  215    protected: |  217    protected: | 
|  216     virtual ~Delegate() {} |  218     virtual ~Delegate() {} | 
|  217   }; |  219   }; | 
|  218  |  220  | 
|  219   // If destroyed after Start() has been called but while IO is pending, |  221   // If destroyed after Start() has been called but while IO is pending, | 
|  220   // then the request will be effectively canceled and the delegate |  222   // then the request will be effectively canceled and the delegate | 
|  221   // will not have any more of its methods called. |  223   // will not have any more of its methods called. | 
|  222   ~URLRequest() override; |  224   ~URLRequest() override; | 
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  517   void SetLoadFlags(int flags); |  519   void SetLoadFlags(int flags); | 
|  518  |  520  | 
|  519   // Returns true if the request is "pending" (i.e., if Start() has been called, |  521   // Returns true if the request is "pending" (i.e., if Start() has been called, | 
|  520   // and the response has not yet been called). |  522   // and the response has not yet been called). | 
|  521   bool is_pending() const { return is_pending_; } |  523   bool is_pending() const { return is_pending_; } | 
|  522  |  524  | 
|  523   // Returns true if the request is in the process of redirecting to a new |  525   // Returns true if the request is in the process of redirecting to a new | 
|  524   // URL but has not yet initiated the new request. |  526   // URL but has not yet initiated the new request. | 
|  525   bool is_redirecting() const { return is_redirecting_; } |  527   bool is_redirecting() const { return is_redirecting_; } | 
|  526  |  528  | 
|  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. |  529   // Returns a globally unique identifier for this request. | 
|  531   uint64_t identifier() const { return identifier_; } |  530   uint64_t identifier() const { return identifier_; } | 
|  532  |  531  | 
|  533   // This method is called to start the request.  The delegate will receive |  532   // This method is called to start the request.  The delegate will receive | 
|  534   // a OnResponseStarted callback when the request is started.  The request |  533   // a OnResponseStarted callback when the request is started.  The request | 
|  535   // must have a delegate set before this method is called. |  534   // must have a delegate set before this method is called. | 
|  536   void Start(); |  535   void Start(); | 
|  537  |  536  | 
|  538   // This method may be called at any time after Start() has been called to |  537   // 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 |  538   // 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 |  539   // 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 |  540   // methods of the delegate will be called after the request has been | 
|  542   // cancelled, except that this may call the delegate's OnReadCompleted() |  541   // cancelled, except that this may call the delegate's OnReadCompleted() | 
|  543   // during the call to Cancel itself. |  542   // during the call to Cancel itself. Returns |ERR_ABORTED| or other net error | 
|  544   void Cancel(); |  543   // if there was one. | 
 |  544   int Cancel(); | 
|  545  |  545  | 
|  546   // Cancels the request and sets the error to |error| (see net_error_list.h |  546   // Cancels the request and sets the error to |error|, unless the request | 
|  547   // for values). |  547   // already failed with another error code (see net_error_list.h). Returns | 
|  548   void CancelWithError(int error); |  548   // final network error code. | 
 |  549   int CancelWithError(int error); | 
|  549  |  550  | 
|  550   // Cancels the request and sets the error to |error| (see net_error_list.h |  551   // 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 |  552   // 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 |  553   // is useful to attach a certificate and certificate error to a canceled | 
|  553   // request. |  554   // request. | 
|  554   void CancelWithSSLError(int error, const SSLInfo& ssl_info); |  555   void CancelWithSSLError(int error, const SSLInfo& ssl_info); | 
|  555  |  556  | 
|  556   // Read initiates an asynchronous read from the response, and must only |  557   //  Read initiates an asynchronous read from the response, and must only be | 
|  557   // be called after the OnResponseStarted callback is received with a |  558   // called after the OnResponseStarted callback is received with a net::OK. If | 
|  558   // successful status. |  559   // data is available, length and the data will be returned immediately. If the | 
|  559   // If data is available, Read will return true, and the data and length will |  560   // request has failed, an error code will be returned. If data is not yet | 
|  560   // be returned immediately.  If data is not available, Read returns false, |  561   // available, Read returns net::ERR_IO_PENDING, and the Delegate's | 
|  561   // and an asynchronous Read is initiated.  The Read is finished when |  562   // OnReadComplete method will be called asynchronously with the result of the | 
|  562   // the caller receives the OnReadComplete callback.  Unless the request was |  563   // read, unless the URLRequest is canceled. | 
|  563   // cancelled, OnReadComplete will always be called, even if the read failed. |  | 
|  564   // |  564   // | 
|  565   // The buf parameter is a buffer to receive the data.  If the operation |  565   // The |buf| parameter is a buffer to receive the data. If the operation | 
|  566   // completes asynchronously, the implementation will reference the buffer |  566   // completes asynchronously, the implementation will reference the buffer | 
|  567   // until OnReadComplete is called.  The buffer must be at least max_bytes in |  567   // until OnReadComplete is called. The buffer must be at least |max_bytes| in | 
|  568   // length. |  568   // length. | 
|  569   // |  569   // | 
|  570   // The max_bytes parameter is the maximum number of bytes to read. |  570   // The |max_bytes| parameter is the maximum number of bytes to read. | 
|  571   // |  571   int Read(IOBuffer* buf, int max_bytes); | 
|  572   // The bytes_read parameter is an output parameter containing the |  572   // Deprecated. | 
|  573   // the number of bytes read.  A value of 0 indicates that there is no |  573   // TODO(maksims): Remove this. | 
|  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); |  574   bool Read(IOBuffer* buf, int max_bytes, int* bytes_read); | 
|  579  |  575  | 
|  580   // If this request is being cached by the HTTP cache, stop subsequent caching. |  576   // 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 |  577   // 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 |  578   // 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 |  579   // the data being stored to disk (downloaded instead of rendered) so we don't | 
|  584   // want to store it twice. |  580   // want to store it twice. | 
|  585   void StopCaching(); |  581   void StopCaching(); | 
|  586  |  582  | 
|  587   // This method may be called to follow a redirect that was deferred in |  583   // 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. |  637   // the more general response_info() is available, even though it is a subset. | 
|  642   const HostPortPair& proxy_server() const { |  638   const HostPortPair& proxy_server() const { | 
|  643     return proxy_server_; |  639     return proxy_server_; | 
|  644   } |  640   } | 
|  645  |  641  | 
|  646   // Gets the connection attempts made in the process of servicing this |  642   // Gets the connection attempts made in the process of servicing this | 
|  647   // URLRequest. Only guaranteed to be valid if called after the request fails |  643   // URLRequest. Only guaranteed to be valid if called after the request fails | 
|  648   // or after the response headers are received. |  644   // or after the response headers are received. | 
|  649   void GetConnectionAttempts(ConnectionAttempts* out) const; |  645   void GetConnectionAttempts(ConnectionAttempts* out) const; | 
|  650  |  646  | 
 |  647   // Returns the error status of the request. | 
 |  648   // Do not use! Going to be protected! | 
 |  649   const URLRequestStatus& status() const { return status_; } | 
 |  650  | 
|  651  protected: |  651  protected: | 
|  652   // Allow the URLRequestJob class to control the is_pending() flag. |  652   // Allow the URLRequestJob class to control the is_pending() flag. | 
|  653   void set_is_pending(bool value) { is_pending_ = value; } |  653   void set_is_pending(bool value) { is_pending_ = value; } | 
|  654  |  654  | 
|  655   // Allow the URLRequestJob class to set our status too. |  655   // Allow the URLRequestJob class to set our status too. | 
|  656   void set_status(URLRequestStatus status); |  656   void set_status(URLRequestStatus status); | 
|  657  |  657  | 
|  658   // Allow the URLRequestJob to redirect this request.  Returns OK if |  658   // Allow the URLRequestJob to redirect this request.  Returns OK if | 
|  659   // successful, otherwise an error code is returned. |  659   // successful, otherwise an error code is returned. | 
|  660   int Redirect(const RedirectInfo& redirect_info); |  660   int Redirect(const RedirectInfo& redirect_info); | 
|  661  |  661  | 
|  662   // Called by URLRequestJob to allow interception when a redirect occurs. |  662   // Called by URLRequestJob to allow interception when a redirect occurs. | 
|  663   void NotifyReceivedRedirect(const RedirectInfo& redirect_info, |  663   void NotifyReceivedRedirect(const RedirectInfo& redirect_info, | 
|  664                               bool* defer_redirect); |  664                               bool* defer_redirect); | 
|  665  |  665  | 
|  666   // Allow an interceptor's URLRequestJob to restart this request. |  666   // Allow an interceptor's URLRequestJob to restart this request. | 
|  667   // Should only be called if the original job has not started a response. |  667   // Should only be called if the original job has not started a response. | 
|  668   void Restart(); |  668   void Restart(); | 
|  669  |  669  | 
|  670  private: |  670  private: | 
|  671   friend class URLRequestJob; |  671   friend class URLRequestJob; | 
|  672   friend class URLRequestContext; |  672   friend class URLRequestContext; | 
|  673  |  673  | 
 |  674   // For testing purposes. | 
 |  675   // TODO(maksims): Remove this. | 
 |  676   friend class TestNetworkDelegate; | 
 |  677  | 
|  674   // URLRequests are always created by calling URLRequestContext::CreateRequest. |  678   // URLRequests are always created by calling URLRequestContext::CreateRequest. | 
|  675   // |  679   // | 
|  676   // If no network delegate is passed in, will use the ones from the |  680   // If no network delegate is passed in, will use the ones from the | 
|  677   // URLRequestContext. |  681   // URLRequestContext. | 
|  678   URLRequest(const GURL& url, |  682   URLRequest(const GURL& url, | 
|  679              RequestPriority priority, |  683              RequestPriority priority, | 
|  680              Delegate* delegate, |  684              Delegate* delegate, | 
|  681              const URLRequestContext* context, |  685              const URLRequestContext* context, | 
|  682              NetworkDelegate* network_delegate); |  686              NetworkDelegate* network_delegate); | 
|  683  |  687  | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
|  695   // happens when following a HTTP redirect. |  699   // happens when following a HTTP redirect. | 
|  696   void RestartWithJob(URLRequestJob* job); |  700   void RestartWithJob(URLRequestJob* job); | 
|  697   void PrepareToRestart(); |  701   void PrepareToRestart(); | 
|  698  |  702  | 
|  699   // Detaches the job from this request in preparation for this object going |  703   // 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 |  704   // away or the job being replaced. The job will not call us back when it has | 
|  701   // been orphaned. |  705   // been orphaned. | 
|  702   void OrphanJob(); |  706   void OrphanJob(); | 
|  703  |  707  | 
|  704   // Cancels the request and set the error and ssl info for this request to the |  708   // Cancels the request and set the error and ssl info for this request to the | 
|  705   // passed values. |  709   // passed values. Returns the error that was set. | 
|  706   void DoCancel(int error, const SSLInfo& ssl_info); |  710   int DoCancel(int error, const SSLInfo& ssl_info); | 
|  707  |  711  | 
|  708   // Called by the URLRequestJob when the headers are received, before any other |  712   // Called by the URLRequestJob when the headers are received, before any other | 
|  709   // method, to allow caching of load timing information. |  713   // method, to allow caching of load timing information. | 
|  710   void OnHeadersComplete(); |  714   void OnHeadersComplete(); | 
|  711  |  715  | 
|  712   // Notifies the network delegate that the request has been completed. |  716   // Notifies the network delegate that the request has been completed. | 
|  713   // This does not imply a successful completion. Also a canceled request is |  717   // This does not imply a successful completion. Also a canceled request is | 
|  714   // considered completed. |  718   // considered completed. | 
|  715   void NotifyRequestCompleted(); |  719   void NotifyRequestCompleted(); | 
|  716  |  720  | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  847  |  851  | 
|  848   // The proxy server used for this request, if any. |  852   // The proxy server used for this request, if any. | 
|  849   HostPortPair proxy_server_; |  853   HostPortPair proxy_server_; | 
|  850  |  854  | 
|  851   DISALLOW_COPY_AND_ASSIGN(URLRequest); |  855   DISALLOW_COPY_AND_ASSIGN(URLRequest); | 
|  852 }; |  856 }; | 
|  853  |  857  | 
|  854 }  // namespace net |  858 }  // namespace net | 
|  855  |  859  | 
|  856 #endif  // NET_URL_REQUEST_URL_REQUEST_H_ |  860 #endif  // NET_URL_REQUEST_URL_REQUEST_H_ | 
| OLD | NEW |