Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Side by Side Diff: net/base/network_delegate.h

Issue 734263003: Move data reduction proxy logic out of chrome and android webview network delegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_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 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 const base::FilePath& path) const; 103 const base::FilePath& path) const;
104 bool CanThrottleRequest(const URLRequest& request) const; 104 bool CanThrottleRequest(const URLRequest& request) const;
105 bool CanEnablePrivacyMode(const GURL& url, 105 bool CanEnablePrivacyMode(const GURL& url,
106 const GURL& first_party_for_cookies) const; 106 const GURL& first_party_for_cookies) const;
107 107
108 bool CancelURLRequestWithPolicyViolatingReferrerHeader( 108 bool CancelURLRequestWithPolicyViolatingReferrerHeader(
109 const URLRequest& request, 109 const URLRequest& request,
110 const GURL& target_url, 110 const GURL& target_url,
111 const GURL& referrer_url) const; 111 const GURL& referrer_url) const;
112 112
113 private:
114 // This is the interface for subclasses of NetworkDelegate to implement. These 113 // This is the interface for subclasses of NetworkDelegate to implement. These
115 // member functions will be called by the respective public notification 114 // member functions will be called by the respective public notification
116 // member function, which will perform basic sanity checking. 115 // member function, which will perform basic sanity checking.
117 116
118 // Called before a request is sent. Allows the delegate to rewrite the URL 117 // Called before a request is sent. Allows the delegate to rewrite the URL
119 // being fetched by modifying |new_url|. If set, the URL must be valid. The 118 // being fetched by modifying |new_url|. If set, the URL must be valid. The
120 // reference fragment from the original URL is not automatically appended to 119 // reference fragment from the original URL is not automatically appended to
121 // |new_url|; callers are responsible for copying the reference fragment if 120 // |new_url|; callers are responsible for copying the reference fragment if
122 // desired. 121 // desired.
123 // |callback| and |new_url| are valid only until OnURLRequestDestroyed is 122 // |callback| and |new_url| are valid only until OnURLRequestDestroyed is
124 // called for this request. Returns a net status code, generally either OK to 123 // called for this request. Returns a net status code, generally either OK to
125 // continue with the request or ERR_IO_PENDING if the result is not ready yet. 124 // continue with the request or ERR_IO_PENDING if the result is not ready yet.
126 // A status code other than OK and ERR_IO_PENDING will cancel the request and 125 // A status code other than OK and ERR_IO_PENDING will cancel the request and
127 // report the status code as the reason. 126 // report the status code as the reason.
128 // 127 //
129 // The default implementation returns OK (continue with request). 128 // The default implementation returns OK (continue with request).
130 virtual int OnBeforeURLRequest(URLRequest* request, 129 virtual int OnBeforeURLRequest(URLRequest* request,
131 const CompletionCallback& callback, 130 const CompletionCallback& callback,
132 GURL* new_url); 131 GURL* new_url) = 0;
133 132
134 // Called as the proxy is being resolved for |url|. Allows the delegate to 133 // Called as the proxy is being resolved for |url|. Allows the delegate to
135 // override the proxy resolution decision made by ProxyService. The delegate 134 // override the proxy resolution decision made by ProxyService. The delegate
136 // may override the decision by modifying the ProxyInfo |result|. 135 // may override the decision by modifying the ProxyInfo |result|.
137 virtual void OnResolveProxy(const GURL& url, 136 virtual void OnResolveProxy(const GURL& url,
138 int load_flags, 137 int load_flags,
139 const ProxyService& proxy_service, 138 const ProxyService& proxy_service,
140 ProxyInfo* result); 139 ProxyInfo* result) = 0;
141 140
142 // Called when use of |bad_proxy| fails due to |net_error|. |net_error| is 141 // Called when use of |bad_proxy| fails due to |net_error|. |net_error| is
143 // the network error encountered, if any, and OK if the fallback was 142 // the network error encountered, if any, and OK if the fallback was
144 // for a reason other than a network error (e.g. the proxy service was 143 // for a reason other than a network error (e.g. the proxy service was
145 // explicitly directed to skip a proxy). 144 // explicitly directed to skip a proxy).
146 virtual void OnProxyFallback(const ProxyServer& bad_proxy, 145 virtual void OnProxyFallback(const ProxyServer& bad_proxy,
147 int net_error); 146 int net_error) = 0;
148 147
149 // Called right before the HTTP headers are sent. Allows the delegate to 148 // Called right before the HTTP headers are sent. Allows the delegate to
150 // read/write |headers| before they get sent out. |callback| and |headers| are 149 // read/write |headers| before they get sent out. |callback| and |headers| are
151 // valid only until OnCompleted or OnURLRequestDestroyed is called for this 150 // valid only until OnCompleted or OnURLRequestDestroyed is called for this
152 // request. 151 // request.
153 // See OnBeforeURLRequest for return value description. Returns OK by default. 152 // See OnBeforeURLRequest for return value description. Returns OK by default.
154 virtual int OnBeforeSendHeaders(URLRequest* request, 153 virtual int OnBeforeSendHeaders(URLRequest* request,
155 const CompletionCallback& callback, 154 const CompletionCallback& callback,
156 HttpRequestHeaders* headers); 155 HttpRequestHeaders* headers) = 0;
157 156
158 // Called after a proxy connection. Allows the delegate to read/write 157 // Called after a proxy connection. Allows the delegate to read/write
159 // |headers| before they get sent out. |headers| is valid only until 158 // |headers| before they get sent out. |headers| is valid only until
160 // OnCompleted or OnURLRequestDestroyed is called for this request. 159 // OnCompleted or OnURLRequestDestroyed is called for this request.
161 virtual void OnBeforeSendProxyHeaders(URLRequest* request, 160 virtual void OnBeforeSendProxyHeaders(URLRequest* request,
162 const ProxyInfo& proxy_info, 161 const ProxyInfo& proxy_info,
163 HttpRequestHeaders* headers); 162 HttpRequestHeaders* headers) = 0;
164 163
165 // Called right before the HTTP request(s) are being sent to the network. 164 // Called right before the HTTP request(s) are being sent to the network.
166 // |headers| is only valid until OnCompleted or OnURLRequestDestroyed is 165 // |headers| is only valid until OnCompleted or OnURLRequestDestroyed is
167 // called for this request. 166 // called for this request.
168 virtual void OnSendHeaders(URLRequest* request, 167 virtual void OnSendHeaders(URLRequest* request,
169 const HttpRequestHeaders& headers); 168 const HttpRequestHeaders& headers) = 0;
170 169
171 // Called for HTTP requests when the headers have been received. 170 // Called for HTTP requests when the headers have been received.
172 // |original_response_headers| contains the headers as received over the 171 // |original_response_headers| contains the headers as received over the
173 // network, these must not be modified. |override_response_headers| can be set 172 // network, these must not be modified. |override_response_headers| can be set
174 // to new values, that should be considered as overriding 173 // to new values, that should be considered as overriding
175 // |original_response_headers|. 174 // |original_response_headers|.
176 // If the response is a redirect, and the Location response header value is 175 // If the response is a redirect, and the Location response header value is
177 // identical to |allowed_unsafe_redirect_url|, then the redirect is never 176 // identical to |allowed_unsafe_redirect_url|, then the redirect is never
178 // blocked and the reference fragment is not copied from the original URL 177 // blocked and the reference fragment is not copied from the original URL
179 // to the redirection target. 178 // to the redirection target.
180 // 179 //
181 // |callback|, |original_response_headers|, and |override_response_headers| 180 // |callback|, |original_response_headers|, and |override_response_headers|
182 // are only valid until OnURLRequestDestroyed is called for this request. 181 // are only valid until OnURLRequestDestroyed is called for this request.
183 // See OnBeforeURLRequest for return value description. Returns OK by default. 182 // See OnBeforeURLRequest for return value description. Returns OK by default.
184 virtual int OnHeadersReceived( 183 virtual int OnHeadersReceived(
185 URLRequest* request, 184 URLRequest* request,
186 const CompletionCallback& callback, 185 const CompletionCallback& callback,
187 const HttpResponseHeaders* original_response_headers, 186 const HttpResponseHeaders* original_response_headers,
188 scoped_refptr<HttpResponseHeaders>* override_response_headers, 187 scoped_refptr<HttpResponseHeaders>* override_response_headers,
189 GURL* allowed_unsafe_redirect_url); 188 GURL* allowed_unsafe_redirect_url) = 0;
190 189
191 // Called right after a redirect response code was received. 190 // Called right after a redirect response code was received.
192 // |new_location| is only valid until OnURLRequestDestroyed is called for this 191 // |new_location| is only valid until OnURLRequestDestroyed is called for this
193 // request. 192 // request.
194 virtual void OnBeforeRedirect(URLRequest* request, 193 virtual void OnBeforeRedirect(URLRequest* request,
195 const GURL& new_location); 194 const GURL& new_location) = 0;
196 195
197 // This corresponds to URLRequestDelegate::OnResponseStarted. 196 // This corresponds to URLRequestDelegate::OnResponseStarted.
198 virtual void OnResponseStarted(URLRequest* request); 197 virtual void OnResponseStarted(URLRequest* request) = 0;
199 198
200 // Called every time we read raw bytes. 199 // Called every time we read raw bytes.
201 virtual void OnRawBytesRead(const URLRequest& request, int bytes_read); 200 virtual void OnRawBytesRead(const URLRequest& request, int bytes_read) = 0;
202 201
203 // Indicates that the URL request has been completed or failed. 202 // Indicates that the URL request has been completed or failed.
204 // |started| indicates whether the request has been started. If false, 203 // |started| indicates whether the request has been started. If false,
205 // some information like the socket address is not available. 204 // some information like the socket address is not available.
206 virtual void OnCompleted(URLRequest* request, bool started); 205 virtual void OnCompleted(URLRequest* request, bool started) = 0;
207 206
208 // Called when an URLRequest is being destroyed. Note that the request is 207 // Called when an URLRequest is being destroyed. Note that the request is
209 // being deleted, so it's not safe to call any methods that may result in 208 // being deleted, so it's not safe to call any methods that may result in
210 // a virtual method call. 209 // a virtual method call.
211 virtual void OnURLRequestDestroyed(URLRequest* request); 210 virtual void OnURLRequestDestroyed(URLRequest* request) = 0;
212 211
213 // Corresponds to ProxyResolverJSBindings::OnError. 212 // Corresponds to ProxyResolverJSBindings::OnError.
214 virtual void OnPACScriptError(int line_number, 213 virtual void OnPACScriptError(int line_number,
215 const base::string16& error); 214 const base::string16& error) = 0;
216 215
217 // Called when a request receives an authentication challenge 216 // Called when a request receives an authentication challenge
218 // specified by |auth_info|, and is unable to respond using cached 217 // specified by |auth_info|, and is unable to respond using cached
219 // credentials. |callback| and |credentials| must be non-NULL, and must 218 // credentials. |callback| and |credentials| must be non-NULL, and must
220 // be valid until OnURLRequestDestroyed is called for |request|. 219 // be valid until OnURLRequestDestroyed is called for |request|.
221 // 220 //
222 // The following return values are allowed: 221 // The following return values are allowed:
223 // - AUTH_REQUIRED_RESPONSE_NO_ACTION: |auth_info| is observed, but 222 // - AUTH_REQUIRED_RESPONSE_NO_ACTION: |auth_info| is observed, but
224 // no action is being taken on it. 223 // no action is being taken on it.
225 // - AUTH_REQUIRED_RESPONSE_SET_AUTH: |credentials| is filled in with 224 // - AUTH_REQUIRED_RESPONSE_SET_AUTH: |credentials| is filled in with
226 // a username and password, which should be used in a response to 225 // a username and password, which should be used in a response to
227 // |auth_info|. 226 // |auth_info|.
228 // - AUTH_REQUIRED_RESPONSE_CANCEL_AUTH: The authentication challenge 227 // - AUTH_REQUIRED_RESPONSE_CANCEL_AUTH: The authentication challenge
229 // should not be attempted. 228 // should not be attempted.
230 // - AUTH_REQUIRED_RESPONSE_IO_PENDING: The action will be decided 229 // - AUTH_REQUIRED_RESPONSE_IO_PENDING: The action will be decided
231 // asynchronously. |callback| will be invoked when the decision is made, 230 // asynchronously. |callback| will be invoked when the decision is made,
232 // and one of the other AuthRequiredResponse values will be passed in with 231 // and one of the other AuthRequiredResponse values will be passed in with
233 // the same semantics as described above. 232 // the same semantics as described above.
234 virtual AuthRequiredResponse OnAuthRequired( 233 virtual AuthRequiredResponse OnAuthRequired(
235 URLRequest* request, 234 URLRequest* request,
236 const AuthChallengeInfo& auth_info, 235 const AuthChallengeInfo& auth_info,
237 const AuthCallback& callback, 236 const AuthCallback& callback,
238 AuthCredentials* credentials); 237 AuthCredentials* credentials) = 0;
239 238
240 // Called when reading cookies to allow the network delegate to block access 239 // Called when reading cookies to allow the network delegate to block access
241 // to the cookie. This method will never be invoked when 240 // to the cookie. This method will never be invoked when
242 // LOAD_DO_NOT_SEND_COOKIES is specified. 241 // LOAD_DO_NOT_SEND_COOKIES is specified.
243 virtual bool OnCanGetCookies(const URLRequest& request, 242 virtual bool OnCanGetCookies(const URLRequest& request,
244 const CookieList& cookie_list); 243 const CookieList& cookie_list) = 0;
245 244
246 // Called when a cookie is set to allow the network delegate to block access 245 // Called when a cookie is set to allow the network delegate to block access
247 // to the cookie. This method will never be invoked when 246 // to the cookie. This method will never be invoked when
248 // LOAD_DO_NOT_SAVE_COOKIES is specified. 247 // LOAD_DO_NOT_SAVE_COOKIES is specified.
249 virtual bool OnCanSetCookie(const URLRequest& request, 248 virtual bool OnCanSetCookie(const URLRequest& request,
250 const std::string& cookie_line, 249 const std::string& cookie_line,
251 CookieOptions* options); 250 CookieOptions* options) = 0;
252 251
253 // Called when a file access is attempted to allow the network delegate to 252 // Called when a file access is attempted to allow the network delegate to
254 // allow or block access to the given file path. Returns true if access is 253 // allow or block access to the given file path. Returns true if access is
255 // allowed. 254 // allowed.
256 virtual bool OnCanAccessFile(const URLRequest& request, 255 virtual bool OnCanAccessFile(const URLRequest& request,
257 const base::FilePath& path) const; 256 const base::FilePath& path) const = 0;
258 257
259 // Returns true if the given request may be rejected when the 258 // Returns true if the given request may be rejected when the
260 // URLRequestThrottlerManager believes the server servicing the 259 // URLRequestThrottlerManager believes the server servicing the
261 // request is overloaded or down. 260 // request is overloaded or down.
262 virtual bool OnCanThrottleRequest(const URLRequest& request) const; 261 virtual bool OnCanThrottleRequest(const URLRequest& request) const = 0;
263 262
264 // Returns true if the given |url| has to be requested over connection that 263 // Returns true if the given |url| has to be requested over connection that
265 // is not tracked by the server. Usually is false, unless user privacy 264 // is not tracked by the server. Usually is false, unless user privacy
266 // settings block cookies from being get or set. 265 // settings block cookies from being get or set.
267 virtual bool OnCanEnablePrivacyMode( 266 virtual bool OnCanEnablePrivacyMode(
268 const GURL& url, 267 const GURL& url,
269 const GURL& first_party_for_cookies) const; 268 const GURL& first_party_for_cookies) const = 0;
270 269
271 // Called before a SocketStream tries to connect. 270 // Called before a SocketStream tries to connect.
272 // See OnBeforeURLRequest for return value description. Returns OK by default. 271 // See OnBeforeURLRequest for return value description. Returns OK by default.
273 virtual int OnBeforeSocketStreamConnect( 272 virtual int OnBeforeSocketStreamConnect(
274 SocketStream* socket, const CompletionCallback& callback); 273 SocketStream* socket, const CompletionCallback& callback) = 0;
275 274
276 // Called when the |referrer_url| for requesting |target_url| during handling 275 // Called when the |referrer_url| for requesting |target_url| during handling
277 // of the |request| is does not comply with the referrer policy (e.g. a 276 // of the |request| is does not comply with the referrer policy (e.g. a
278 // secure referrer for an insecure initial target). 277 // secure referrer for an insecure initial target).
279 // Returns true if the request should be cancelled. Otherwise, the referrer 278 // Returns true if the request should be cancelled. Otherwise, the referrer
280 // header is stripped from the request. 279 // header is stripped from the request.
281 virtual bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( 280 virtual bool OnCancelURLRequestWithPolicyViolatingReferrerHeader(
282 const URLRequest& request, 281 const URLRequest& request,
283 const GURL& target_url, 282 const GURL& target_url,
284 const GURL& referrer_url) const; 283 const GURL& referrer_url) const = 0;
285 }; 284 };
286 285
287 } // namespace net 286 } // namespace net
288 287
289 #endif // NET_BASE_NETWORK_DELEGATE_H_ 288 #endif // NET_BASE_NETWORK_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698