Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_URL_REQUEST_URL_REQUEST_FTP_JOB_H_ |
| 6 | #define NET_URL_REQUEST_URL_REQUEST_FTP_JOB_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/memory/weak_ptr.h" |
| 11 | #include "net/base/auth.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 12 | #include "net/base/net_export.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 13 | #include "net/ftp/ftp_request_info.h" |
| 14 | #include "net/ftp/ftp_transaction.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 15 | #include "net/http/http_request_info.h" |
| 16 | #include "net/http/http_transaction.h" |
| 17 | #include "net/proxy/proxy_info.h" |
| 18 | #include "net/proxy/proxy_service.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 19 | #include "net/url_request/url_request_job.h" |
| 20 | |
| 21 | namespace net { |
| 22 | |
| 23 | class NetworkDelegate; |
| 24 | class FtpTransactionFactory; |
| 25 | class FtpAuthCache; |
| 26 | |
| 27 | // A URLRequestJob subclass that is built on top of FtpTransaction. It |
| 28 | // provides an implementation for FTP. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 29 | class NET_EXPORT_PRIVATE URLRequestFtpJob : public URLRequestJob { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 30 | public: |
| 31 | URLRequestFtpJob(URLRequest* request, |
| 32 | NetworkDelegate* network_delegate, |
| 33 | FtpTransactionFactory* ftp_transaction_factory, |
| 34 | FtpAuthCache* ftp_auth_cache); |
| 35 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 36 | protected: |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 37 | virtual ~URLRequestFtpJob(); |
| 38 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 39 | // Overridden from URLRequestJob: |
| 40 | virtual bool IsSafeRedirect(const GURL& location) OVERRIDE; |
| 41 | virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
| 42 | virtual void GetResponseInfo(HttpResponseInfo* info) OVERRIDE; |
| 43 | virtual HostPortPair GetSocketAddress() const OVERRIDE; |
| 44 | virtual void SetPriority(RequestPriority priority) OVERRIDE; |
| 45 | virtual void Start() OVERRIDE; |
| 46 | virtual void Kill() OVERRIDE; |
| 47 | |
| 48 | RequestPriority priority() const { return priority_; } |
| 49 | |
| 50 | private: |
| 51 | void OnResolveProxyComplete(int result); |
| 52 | |
| 53 | void StartFtpTransaction(); |
| 54 | void StartHttpTransaction(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 55 | |
| 56 | void OnStartCompleted(int result); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 57 | void OnStartCompletedAsync(int result); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 58 | void OnReadCompleted(int result); |
| 59 | |
| 60 | void RestartTransactionWithAuth(); |
| 61 | |
| 62 | void LogFtpServerType(char server_type); |
| 63 | |
| 64 | // Overridden from URLRequestJob: |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 65 | virtual LoadState GetLoadState() const OVERRIDE; |
| 66 | virtual bool NeedsAuth() OVERRIDE; |
| 67 | virtual void GetAuthChallengeInfo( |
| 68 | scoped_refptr<AuthChallengeInfo>* auth_info) OVERRIDE; |
| 69 | virtual void SetAuth(const AuthCredentials& credentials) OVERRIDE; |
| 70 | virtual void CancelAuth() OVERRIDE; |
| 71 | |
| 72 | // TODO(ibrar): Yet to give another look at this function. |
| 73 | virtual UploadProgress GetUploadProgress() const OVERRIDE; |
| 74 | virtual bool ReadRawData(IOBuffer* buf, |
| 75 | int buf_size, |
| 76 | int *bytes_read) OVERRIDE; |
| 77 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 78 | void HandleAuthNeededResponse(); |
| 79 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 80 | RequestPriority priority_; |
| 81 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 82 | ProxyService* proxy_service_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 83 | ProxyInfo proxy_info_; |
| 84 | ProxyService::PacRequest* pac_request_; |
| 85 | |
| 86 | FtpRequestInfo ftp_request_info_; |
| 87 | scoped_ptr<FtpTransaction> ftp_transaction_; |
| 88 | |
| 89 | HttpRequestInfo http_request_info_; |
| 90 | scoped_ptr<HttpTransaction> http_transaction_; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 91 | const HttpResponseInfo* http_response_info_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 92 | |
| 93 | bool read_in_progress_; |
| 94 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 95 | scoped_refptr<AuthData> auth_data_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 96 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 97 | FtpTransactionFactory* ftp_transaction_factory_; |
| 98 | FtpAuthCache* ftp_auth_cache_; |
| 99 | |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 100 | base::WeakPtrFactory<URLRequestFtpJob> weak_factory_; |
| 101 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 102 | DISALLOW_COPY_AND_ASSIGN(URLRequestFtpJob); |
| 103 | }; |
| 104 | |
| 105 | } // namespace net |
| 106 | |
| 107 | #endif // NET_URL_REQUEST_URL_REQUEST_FTP_JOB_H_ |