Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / net / url_request / url_request_ftp_job.h
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"
12 #include "net/base/net_export.h"
13 #include "net/ftp/ftp_request_info.h"
14 #include "net/ftp/ftp_transaction.h"
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"
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.
29 class NET_EXPORT_PRIVATE URLRequestFtpJob : public URLRequestJob {
30  public:
31   URLRequestFtpJob(URLRequest* request,
32                    NetworkDelegate* network_delegate,
33                    FtpTransactionFactory* ftp_transaction_factory,
34                    FtpAuthCache* ftp_auth_cache);
35
36  protected:
37   ~URLRequestFtpJob() override;
38
39   // Overridden from URLRequestJob:
40   bool IsSafeRedirect(const GURL& location) override;
41   bool GetMimeType(std::string* mime_type) const override;
42   void GetResponseInfo(HttpResponseInfo* info) override;
43   HostPortPair GetSocketAddress() const override;
44   void SetPriority(RequestPriority priority) override;
45   void Start() override;
46   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();
55
56   void OnStartCompleted(int result);
57   void OnStartCompletedAsync(int result);
58   void OnReadCompleted(int result);
59
60   void RestartTransactionWithAuth();
61
62   void LogFtpServerType(char server_type);
63
64   // Overridden from URLRequestJob:
65   LoadState GetLoadState() const override;
66   bool NeedsAuth() override;
67   void GetAuthChallengeInfo(
68       scoped_refptr<AuthChallengeInfo>* auth_info) override;
69   void SetAuth(const AuthCredentials& credentials) override;
70   void CancelAuth() override;
71
72   // TODO(ibrar):  Yet to give another look at this function.
73   UploadProgress GetUploadProgress() const override;
74   bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read) override;
75
76   void HandleAuthNeededResponse();
77
78   RequestPriority priority_;
79
80   ProxyService* proxy_service_;
81   ProxyInfo proxy_info_;
82   ProxyService::PacRequest* pac_request_;
83
84   FtpRequestInfo ftp_request_info_;
85   scoped_ptr<FtpTransaction> ftp_transaction_;
86
87   HttpRequestInfo http_request_info_;
88   scoped_ptr<HttpTransaction> http_transaction_;
89   const HttpResponseInfo* http_response_info_;
90
91   bool read_in_progress_;
92
93   scoped_refptr<AuthData> auth_data_;
94
95   FtpTransactionFactory* ftp_transaction_factory_;
96   FtpAuthCache* ftp_auth_cache_;
97
98   base::WeakPtrFactory<URLRequestFtpJob> weak_factory_;
99
100   DISALLOW_COPY_AND_ASSIGN(URLRequestFtpJob);
101 };
102
103 }  // namespace net
104
105 #endif  // NET_URL_REQUEST_URL_REQUEST_FTP_JOB_H_