| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BASE_NETWORK_DELEGATE_H_ | 5 #ifndef NET_BASE_NETWORK_DELEGATE_H_ |
| 6 #define NET_BASE_NETWORK_DELEGATE_H_ | 6 #define NET_BASE_NETWORK_DELEGATE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 }; | 43 }; |
| 44 typedef base::Callback<void(AuthRequiredResponse)> AuthCallback; | 44 typedef base::Callback<void(AuthRequiredResponse)> AuthCallback; |
| 45 | 45 |
| 46 virtual ~NetworkDelegate() {} | 46 virtual ~NetworkDelegate() {} |
| 47 | 47 |
| 48 // Notification interface called by the network stack. Note that these | 48 // Notification interface called by the network stack. Note that these |
| 49 // functions mostly forward to the private virtuals. They also add some sanity | 49 // functions mostly forward to the private virtuals. They also add some sanity |
| 50 // checking on parameters. See the corresponding virtuals for explanations of | 50 // checking on parameters. See the corresponding virtuals for explanations of |
| 51 // the methods and their arguments. | 51 // the methods and their arguments. |
| 52 int NotifyBeforeURLRequest(URLRequest* request, | 52 int NotifyBeforeURLRequest(URLRequest* request, |
| 53 OldCompletionCallback* callback, | 53 const CompletionCallback& callback, |
| 54 GURL* new_url); | 54 GURL* new_url); |
| 55 int NotifyBeforeSendHeaders(URLRequest* request, | 55 int NotifyBeforeSendHeaders(URLRequest* request, |
| 56 OldCompletionCallback* callback, | 56 const CompletionCallback& callback, |
| 57 HttpRequestHeaders* headers); | 57 HttpRequestHeaders* headers); |
| 58 void NotifySendHeaders(URLRequest* request, | 58 void NotifySendHeaders(URLRequest* request, |
| 59 const HttpRequestHeaders& headers); | 59 const HttpRequestHeaders& headers); |
| 60 int NotifyHeadersReceived( | 60 int NotifyHeadersReceived( |
| 61 URLRequest* request, | 61 URLRequest* request, |
| 62 OldCompletionCallback* callback, | 62 const CompletionCallback& callback, |
| 63 HttpResponseHeaders* original_response_headers, | 63 HttpResponseHeaders* original_response_headers, |
| 64 scoped_refptr<HttpResponseHeaders>* override_response_headers); | 64 scoped_refptr<HttpResponseHeaders>* override_response_headers); |
| 65 void NotifyBeforeRedirect(URLRequest* request, | 65 void NotifyBeforeRedirect(URLRequest* request, |
| 66 const GURL& new_location); | 66 const GURL& new_location); |
| 67 void NotifyResponseStarted(URLRequest* request); | 67 void NotifyResponseStarted(URLRequest* request); |
| 68 void NotifyRawBytesRead(const URLRequest& request, int bytes_read); | 68 void NotifyRawBytesRead(const URLRequest& request, int bytes_read); |
| 69 void NotifyCompleted(URLRequest* request); | 69 void NotifyCompleted(URLRequest* request); |
| 70 void NotifyURLRequestDestroyed(URLRequest* request); | 70 void NotifyURLRequestDestroyed(URLRequest* request); |
| 71 void NotifyPACScriptError(int line_number, const string16& error); | 71 void NotifyPACScriptError(int line_number, const string16& error); |
| 72 AuthRequiredResponse NotifyAuthRequired(URLRequest* request, | 72 AuthRequiredResponse NotifyAuthRequired(URLRequest* request, |
| 73 const AuthChallengeInfo& auth_info, | 73 const AuthChallengeInfo& auth_info, |
| 74 const AuthCallback& callback, | 74 const AuthCallback& callback, |
| 75 AuthCredentials* credentials); | 75 AuthCredentials* credentials); |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 // This is the interface for subclasses of NetworkDelegate to implement. This | 78 // This is the interface for subclasses of NetworkDelegate to implement. This |
| 79 // member functions will be called by the respective public notification | 79 // member functions will be called by the respective public notification |
| 80 // member function, which will perform basic sanity checking. | 80 // member function, which will perform basic sanity checking. |
| 81 | 81 |
| 82 // Called before a request is sent. Allows the delegate to rewrite the URL | 82 // Called before a request is sent. Allows the delegate to rewrite the URL |
| 83 // being fetched by modifying |new_url|. |callback| and |new_url| are valid | 83 // being fetched by modifying |new_url|. |callback| and |new_url| are valid |
| 84 // only until OnURLRequestDestroyed is called for this request. Returns a net | 84 // only until OnURLRequestDestroyed is called for this request. Returns a net |
| 85 // status code, generally either OK to continue with the request or | 85 // status code, generally either OK to continue with the request or |
| 86 // ERR_IO_PENDING if the result is not ready yet. A status code other than OK | 86 // ERR_IO_PENDING if the result is not ready yet. A status code other than OK |
| 87 // and ERR_IO_PENDING will cancel the request and report the status code as | 87 // and ERR_IO_PENDING will cancel the request and report the status code as |
| 88 // the reason. | 88 // the reason. |
| 89 virtual int OnBeforeURLRequest(URLRequest* request, | 89 virtual int OnBeforeURLRequest(URLRequest* request, |
| 90 OldCompletionCallback* callback, | 90 const CompletionCallback& callback, |
| 91 GURL* new_url) = 0; | 91 GURL* new_url) = 0; |
| 92 | 92 |
| 93 // Called right before the HTTP headers are sent. Allows the delegate to | 93 // Called right before the HTTP headers are sent. Allows the delegate to |
| 94 // read/write |headers| before they get sent out. |callback| and |headers| are | 94 // read/write |headers| before they get sent out. |callback| and |headers| are |
| 95 // valid only until OnURLRequestDestroyed is called for this request. | 95 // valid only until OnURLRequestDestroyed is called for this request. |
| 96 // Returns a net status code. | 96 // Returns a net status code. |
| 97 virtual int OnBeforeSendHeaders(URLRequest* request, | 97 virtual int OnBeforeSendHeaders(URLRequest* request, |
| 98 OldCompletionCallback* callback, | 98 const CompletionCallback& callback, |
| 99 HttpRequestHeaders* headers) = 0; | 99 HttpRequestHeaders* headers) = 0; |
| 100 | 100 |
| 101 // Called right before the HTTP request(s) are being sent to the network. | 101 // Called right before the HTTP request(s) are being sent to the network. |
| 102 virtual void OnSendHeaders(URLRequest* request, | 102 virtual void OnSendHeaders(URLRequest* request, |
| 103 const HttpRequestHeaders& headers) = 0; | 103 const HttpRequestHeaders& headers) = 0; |
| 104 | 104 |
| 105 // Called for HTTP requests when the headers have been received. Returns a net | 105 // Called for HTTP requests when the headers have been received. Returns a net |
| 106 // status code, generally either OK to continue with the request or | 106 // status code, generally either OK to continue with the request or |
| 107 // ERR_IO_PENDING if the result is not ready yet. A status code other than OK | 107 // ERR_IO_PENDING if the result is not ready yet. A status code other than OK |
| 108 // and ERR_IO_PENDING will cancel the request and report the status code as | 108 // and ERR_IO_PENDING will cancel the request and report the status code as |
| 109 // the reason. | 109 // the reason. |
| 110 // |original_response_headers| contains the headers as received over the | 110 // |original_response_headers| contains the headers as received over the |
| 111 // network, these must not be modified. |override_response_headers| can be set | 111 // network, these must not be modified. |override_response_headers| can be set |
| 112 // to new values, that should be considered as overriding | 112 // to new values, that should be considered as overriding |
| 113 // |original_response_headers|. | 113 // |original_response_headers|. |
| 114 virtual int OnHeadersReceived( | 114 virtual int OnHeadersReceived( |
| 115 URLRequest* request, | 115 URLRequest* request, |
| 116 OldCompletionCallback* callback, | 116 const CompletionCallback& callback, |
| 117 HttpResponseHeaders* original_response_headers, | 117 HttpResponseHeaders* original_response_headers, |
| 118 scoped_refptr<HttpResponseHeaders>* override_response_headers) = 0; | 118 scoped_refptr<HttpResponseHeaders>* override_response_headers) = 0; |
| 119 | 119 |
| 120 // Called right after a redirect response code was received. | 120 // Called right after a redirect response code was received. |
| 121 virtual void OnBeforeRedirect(URLRequest* request, | 121 virtual void OnBeforeRedirect(URLRequest* request, |
| 122 const GURL& new_location) = 0; | 122 const GURL& new_location) = 0; |
| 123 | 123 |
| 124 // This corresponds to URLRequestDelegate::OnResponseStarted. | 124 // This corresponds to URLRequestDelegate::OnResponseStarted. |
| 125 virtual void OnResponseStarted(URLRequest* request) = 0; | 125 virtual void OnResponseStarted(URLRequest* request) = 0; |
| 126 | 126 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 virtual AuthRequiredResponse OnAuthRequired( | 158 virtual AuthRequiredResponse OnAuthRequired( |
| 159 URLRequest* request, | 159 URLRequest* request, |
| 160 const AuthChallengeInfo& auth_info, | 160 const AuthChallengeInfo& auth_info, |
| 161 const AuthCallback& callback, | 161 const AuthCallback& callback, |
| 162 AuthCredentials* credentials) = 0; | 162 AuthCredentials* credentials) = 0; |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 } // namespace net | 165 } // namespace net |
| 166 | 166 |
| 167 #endif // NET_BASE_NETWORK_DELEGATE_H_ | 167 #endif // NET_BASE_NETWORK_DELEGATE_H_ |
| OLD | NEW |