diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-29 02:40:30 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-29 02:40:30 +0000 |
commit | c6c6e5651515399af25e8cd70ad17b729c14e09a (patch) | |
tree | 1368e8883d88caaa4adbda98a782af5c3af1e1df /net | |
parent | 43346e39ef7145d80ab53085294fd02fa0c78f6e (diff) | |
download | chromium_src-c6c6e5651515399af25e8cd70ad17b729c14e09a.zip chromium_src-c6c6e5651515399af25e8cd70ad17b729c14e09a.tar.gz chromium_src-c6c6e5651515399af25e8cd70ad17b729c14e09a.tar.bz2 |
Mostly useful for testing.
Added default implementations for methods in net::NetworkDelegate to make it easier to implement, and more likely for implementations to be correct.
BUG=310297
Review URL: https://codereview.chromium.org/38303002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231489 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/network_delegate.cc | 103 | ||||
-rw-r--r-- | net/base/network_delegate.h | 46 |
2 files changed, 116 insertions, 33 deletions
diff --git a/net/base/network_delegate.cc b/net/base/network_delegate.cc index 5a69b86..834769c 100644 --- a/net/base/network_delegate.cc +++ b/net/base/network_delegate.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "net/base/load_flags.h" +#include "net/base/net_errors.h" #include "net/url_request/url_request.h" namespace net { @@ -92,6 +93,21 @@ NetworkDelegate::AuthRequiredResponse NetworkDelegate::NotifyAuthRequired( return OnAuthRequired(request, auth_info, callback, credentials); } +int NetworkDelegate::NotifyBeforeSocketStreamConnect( + SocketStream* socket, + const CompletionCallback& callback) { + DCHECK(CalledOnValidThread()); + DCHECK(socket); + DCHECK(!callback.is_null()); + return OnBeforeSocketStreamConnect(socket, callback); +} + +void NetworkDelegate::NotifyRequestWaitStateChange(const URLRequest& request, + RequestWaitState state) { + DCHECK(CalledOnValidThread()); + OnRequestWaitStateChange(request, state); +} + bool NetworkDelegate::CanGetCookies(const URLRequest& request, const CookieList& cookie_list) { DCHECK(CalledOnValidThread()); @@ -125,26 +141,93 @@ bool NetworkDelegate::CanEnablePrivacyMode( return OnCanEnablePrivacyMode(url, first_party_for_cookies); } +int NetworkDelegate::OnBeforeURLRequest(URLRequest* request, + const CompletionCallback& callback, + GURL* new_url) { + return OK; +} + +int NetworkDelegate::OnBeforeSendHeaders(URLRequest* request, + const CompletionCallback& callback, + HttpRequestHeaders* headers) { + return OK; +} + +void NetworkDelegate::OnSendHeaders(URLRequest* request, + const HttpRequestHeaders& headers) { +} + +int NetworkDelegate::OnHeadersReceived( + URLRequest* request, + const CompletionCallback& callback, + const HttpResponseHeaders* original_response_headers, + scoped_refptr<HttpResponseHeaders>* override_response_headers) { + return OK; +} + +void NetworkDelegate::OnBeforeRedirect(URLRequest* request, + const GURL& new_location) { +} + +void NetworkDelegate::OnResponseStarted(URLRequest* request) { +} + +void NetworkDelegate::OnRawBytesRead(const URLRequest& request, + int bytes_read) { +} + +void NetworkDelegate::OnCompleted(URLRequest* request, bool started) { +} + +void NetworkDelegate::OnURLRequestDestroyed(URLRequest* request) { +} + +void NetworkDelegate::OnPACScriptError(int line_number, + const base::string16& error) { +} + +NetworkDelegate::AuthRequiredResponse NetworkDelegate::OnAuthRequired( + URLRequest* request, + const AuthChallengeInfo& auth_info, + const AuthCallback& callback, + AuthCredentials* credentials) { + return AUTH_REQUIRED_RESPONSE_NO_ACTION; +} + +bool NetworkDelegate::OnCanGetCookies(const URLRequest& request, + const CookieList& cookie_list) { + return true; +} + +bool NetworkDelegate::OnCanSetCookie(const URLRequest& request, + const std::string& cookie_line, + CookieOptions* options) { + return true; +} + +bool NetworkDelegate::OnCanAccessFile(const URLRequest& request, + const base::FilePath& path) const { + return false; +} + +bool NetworkDelegate::OnCanThrottleRequest(const URLRequest& request) const { + return false; +} + bool NetworkDelegate::OnCanEnablePrivacyMode( const GURL& url, const GURL& first_party_for_cookies) const { - // Default implementation disables privacy mode. return false; } -int NetworkDelegate::NotifyBeforeSocketStreamConnect( +int NetworkDelegate::OnBeforeSocketStreamConnect( SocketStream* socket, const CompletionCallback& callback) { - DCHECK(CalledOnValidThread()); - DCHECK(socket); - DCHECK(!callback.is_null()); - return OnBeforeSocketStreamConnect(socket, callback); + return OK; } -void NetworkDelegate::NotifyRequestWaitStateChange(const URLRequest& request, - RequestWaitState state) { - DCHECK(CalledOnValidThread()); - OnRequestWaitStateChange(request, state); +void NetworkDelegate::OnRequestWaitStateChange(const URLRequest& request, + RequestWaitState state) { } } // namespace net diff --git a/net/base/network_delegate.h b/net/base/network_delegate.h index 4b64964..21c8e65 100644 --- a/net/base/network_delegate.h +++ b/net/base/network_delegate.h @@ -118,67 +118,66 @@ class NET_EXPORT NetworkDelegate : public base::NonThreadSafe { // ERR_IO_PENDING if the result is not ready yet. A status code other than OK // and ERR_IO_PENDING will cancel the request and report the status code as // the reason. + // + // The default implementation returns OK (continue with request). virtual int OnBeforeURLRequest(URLRequest* request, const CompletionCallback& callback, - GURL* new_url) = 0; + GURL* new_url); // Called right before the HTTP headers are sent. Allows the delegate to // read/write |headers| before they get sent out. |callback| and |headers| are // valid only until OnCompleted or OnURLRequestDestroyed is called for this // request. - // Returns a net status code. + // See OnBeforeURLRequest for return value description. Returns OK by default. virtual int OnBeforeSendHeaders(URLRequest* request, const CompletionCallback& callback, - HttpRequestHeaders* headers) = 0; + HttpRequestHeaders* headers); // Called right before the HTTP request(s) are being sent to the network. // |headers| is only valid until OnCompleted or OnURLRequestDestroyed is // called for this request. virtual void OnSendHeaders(URLRequest* request, - const HttpRequestHeaders& headers) = 0; + const HttpRequestHeaders& headers); - // Called for HTTP requests when the headers have been received. Returns a net - // status code, generally either OK to continue with the request or - // ERR_IO_PENDING if the result is not ready yet. A status code other than OK - // and ERR_IO_PENDING will cancel the request and report the status code as - // the reason. + // Called for HTTP requests when the headers have been received. // |original_response_headers| contains the headers as received over the // network, these must not be modified. |override_response_headers| can be set // to new values, that should be considered as overriding // |original_response_headers|. // |callback|, |original_response_headers|, and |override_response_headers| // are only valid until OnURLRequestDestroyed is called for this request. + // See OnBeforeURLRequest for return value description. Returns OK by default. virtual int OnHeadersReceived( URLRequest* request, const CompletionCallback& callback, const HttpResponseHeaders* original_response_headers, - scoped_refptr<HttpResponseHeaders>* override_response_headers) = 0; + scoped_refptr<HttpResponseHeaders>* override_response_headers); // Called right after a redirect response code was received. // |new_location| is only valid until OnURLRequestDestroyed is called for this // request. virtual void OnBeforeRedirect(URLRequest* request, - const GURL& new_location) = 0; + const GURL& new_location); // This corresponds to URLRequestDelegate::OnResponseStarted. - virtual void OnResponseStarted(URLRequest* request) = 0; + virtual void OnResponseStarted(URLRequest* request); // Called every time we read raw bytes. - virtual void OnRawBytesRead(const URLRequest& request, int bytes_read) = 0; + virtual void OnRawBytesRead(const URLRequest& request, int bytes_read); // Indicates that the URL request has been completed or failed. // |started| indicates whether the request has been started. If false, // some information like the socket address is not available. - virtual void OnCompleted(URLRequest* request, bool started) = 0; + virtual void OnCompleted(URLRequest* request, bool started); // Called when an URLRequest is being destroyed. Note that the request is // being deleted, so it's not safe to call any methods that may result in // a virtual method call. - virtual void OnURLRequestDestroyed(URLRequest* request) = 0; + virtual void OnURLRequestDestroyed(URLRequest* request); // Corresponds to ProxyResolverJSBindings::OnError. virtual void OnPACScriptError(int line_number, - const base::string16& error) = 0; + const base::string16& error); // Called when a request receives an authentication challenge // specified by |auth_info|, and is unable to respond using cached @@ -201,31 +200,31 @@ class NET_EXPORT NetworkDelegate : public base::NonThreadSafe { URLRequest* request, const AuthChallengeInfo& auth_info, const AuthCallback& callback, - AuthCredentials* credentials) = 0; + AuthCredentials* credentials); // Called when reading cookies to allow the network delegate to block access // to the cookie. This method will never be invoked when // LOAD_DO_NOT_SEND_COOKIES is specified. virtual bool OnCanGetCookies(const URLRequest& request, - const CookieList& cookie_list) = 0; + const CookieList& cookie_list); // Called when a cookie is set to allow the network delegate to block access // to the cookie. This method will never be invoked when // LOAD_DO_NOT_SAVE_COOKIES is specified. virtual bool OnCanSetCookie(const URLRequest& request, const std::string& cookie_line, - CookieOptions* options) = 0; + CookieOptions* options); // Called when a file access is attempted to allow the network delegate to // allow or block access to the given file path. Returns true if access is // allowed. virtual bool OnCanAccessFile(const URLRequest& request, - const base::FilePath& path) const = 0; + const base::FilePath& path) const; // Returns true if the given request may be rejected when the // URLRequestThrottlerManager believes the server servicing the // request is overloaded or down. - virtual bool OnCanThrottleRequest(const URLRequest& request) const = 0; + virtual bool OnCanThrottleRequest(const URLRequest& request) const; // Returns true if the given |url| has to be requested over connection that // is not tracked by the server. Usually is false, unless user privacy @@ -235,15 +234,16 @@ class NET_EXPORT NetworkDelegate : public base::NonThreadSafe { const GURL& first_party_for_cookies) const; // Called before a SocketStream tries to connect. + // See OnBeforeURLRequest for return value description. Returns OK by default. virtual int OnBeforeSocketStreamConnect( - SocketStream* socket, const CompletionCallback& callback) = 0; + SocketStream* socket, const CompletionCallback& callback); // Called when the completion of a URLRequest is blocking on a cache // action or a network action, or when that is no longer the case. // REQUEST_WAIT_STATE_RESET indicates for a given URLRequest // cancellation of any pending waits for this request. virtual void OnRequestWaitStateChange(const URLRequest& request, - RequestWaitState state) = 0; + RequestWaitState state); }; } // namespace net |