• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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 #pragma once
8 
9 #include <string>
10 
11 #include "base/string16.h"
12 #include "base/task.h"
13 #include "net/base/auth.h"
14 #include "net/base/completion_callback.h"
15 #include "net/ftp/ftp_request_info.h"
16 #include "net/ftp/ftp_transaction.h"
17 #include "net/url_request/url_request_job.h"
18 
19 namespace net {
20 
21 class URLRequestContext;
22 
23 // A URLRequestJob subclass that is built on top of FtpTransaction. It
24 // provides an implementation for FTP.
25 class URLRequestFtpJob : public URLRequestJob {
26  public:
27   explicit URLRequestFtpJob(URLRequest* request);
28 
29   static URLRequestJob* Factory(URLRequest* request,
30                                 const std::string& scheme);
31 
32   // Overridden from URLRequestJob:
33   virtual bool GetMimeType(std::string* mime_type) const;
34   virtual HostPortPair GetSocketAddress() const;
35 
36  private:
37   virtual ~URLRequestFtpJob();
38 
39   void StartTransaction();
40 
41   void OnStartCompleted(int result);
42   void OnReadCompleted(int result);
43 
44   void RestartTransactionWithAuth();
45 
46   void LogFtpServerType(char server_type);
47 
48   // Overridden from URLRequestJob:
49   virtual void Start();
50   virtual void Kill();
51   virtual LoadState GetLoadState() const;
52   virtual bool NeedsAuth();
53   virtual void GetAuthChallengeInfo(
54       scoped_refptr<AuthChallengeInfo>* auth_info);
55   virtual void SetAuth(const string16& username,
56                        const string16& password);
57   virtual void CancelAuth();
58 
59   // TODO(ibrar):  Yet to give another look at this function.
60   virtual uint64 GetUploadProgress() const;
61   virtual bool ReadRawData(IOBuffer* buf, int buf_size, int *bytes_read);
62 
63   FtpRequestInfo request_info_;
64   scoped_ptr<FtpTransaction> transaction_;
65 
66   CompletionCallbackImpl<URLRequestFtpJob> start_callback_;
67   CompletionCallbackImpl<URLRequestFtpJob> read_callback_;
68 
69   bool read_in_progress_;
70 
71   scoped_refptr<AuthData> server_auth_;
72 
73   // Keep a reference to the url request context to be sure it's not deleted
74   // before us.
75   scoped_refptr<URLRequestContext> context_;
76 
77   ScopedRunnableMethodFactory<URLRequestFtpJob> method_factory_;
78 
79   DISALLOW_COPY_AND_ASSIGN(URLRequestFtpJob);
80 };
81 
82 }  // namespace net
83 
84 #endif  // NET_URL_REQUEST_URL_REQUEST_FTP_JOB_H_
85