OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_URL_REQUEST_URL_REQUEST_FTP_JOB_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_FTP_JOB_H_ |
6 #define NET_URL_REQUEST_URL_REQUEST_FTP_JOB_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_FTP_JOB_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
8 #include "net/url_request/url_request_inet_job.h" | 10 #include "net/url_request/url_request_inet_job.h" |
9 | 11 |
10 // A basic FTP job that handles download files and showing directory listings. | 12 // A basic FTP job that handles download files and showing directory listings. |
11 class URLRequestFtpJob : public URLRequestInetJob { | 13 class URLRequestFtpJob : public URLRequestInetJob { |
12 public: | 14 public: |
13 static URLRequestJob* Factory(URLRequest* request, const std::string& scheme); | 15 static URLRequestJob* Factory(URLRequest* request, const std::string& scheme); |
14 | 16 |
15 virtual ~URLRequestFtpJob(); | 17 virtual ~URLRequestFtpJob(); |
16 | 18 |
17 // URLRequestJob methods: | 19 // URLRequestJob methods: |
18 virtual void Start(); | 20 virtual void Start(); |
19 virtual bool GetMimeType(std::string* mime_type); | 21 virtual bool GetMimeType(std::string* mime_type) const; |
20 | 22 |
21 // URLRequestInetJob methods: | 23 // URLRequestInetJob methods: |
22 virtual void OnIOComplete(const AsyncResult& result); | 24 virtual void OnIOComplete(const AsyncResult& result); |
23 | 25 |
24 protected: | 26 protected: |
25 URLRequestFtpJob(URLRequest* request); | 27 explicit URLRequestFtpJob(URLRequest* request); |
26 | 28 |
27 // Starts the WinInet request. | 29 // Starts the WinInet request. |
28 virtual void SendRequest(); | 30 virtual void SendRequest(); |
29 | 31 |
30 virtual int CallInternetRead(char* dest, int dest_size, int *bytes_read); | 32 virtual int CallInternetRead(char* dest, int dest_size, int *bytes_read); |
31 virtual bool GetReadBytes(const AsyncResult& result, int* bytes_read); | 33 virtual bool GetReadBytes(const AsyncResult& result, int* bytes_read); |
32 virtual void OnCancelAuth(); | 34 virtual void OnCancelAuth(); |
33 virtual void OnSetAuth(); | 35 virtual void OnSetAuth(); |
34 virtual bool NeedsAuth(); | 36 virtual bool NeedsAuth(); |
35 virtual void GetAuthChallengeInfo(scoped_refptr<net::AuthChallengeInfo>*); | 37 virtual void GetAuthChallengeInfo(scoped_refptr<net::AuthChallengeInfo>*); |
(...skipping 22 matching lines...) Expand all Loading... |
58 void OnFinishDirectoryTraversal(); | 60 void OnFinishDirectoryTraversal(); |
59 | 61 |
60 // If given data, writes it to the directory listing html. If | 62 // If given data, writes it to the directory listing html. If |
61 // call_io_complete is true, will also notify the parent class that we wrote | 63 // call_io_complete is true, will also notify the parent class that we wrote |
62 // data in the given buffer. | 64 // data in the given buffer. |
63 int WriteData(const std::string* data, bool call_io_complete); | 65 int WriteData(const std::string* data, bool call_io_complete); |
64 | 66 |
65 // Continuation function for calling OnIOComplete through the message loop. | 67 // Continuation function for calling OnIOComplete through the message loop. |
66 virtual void ContinueIOComplete(int bytes_written); | 68 virtual void ContinueIOComplete(int bytes_written); |
67 | 69 |
68 // Continuation function for calling NotifyHeadersComplete through | 70 // Continuation function for calling NotifyHeadersComplete through the message |
69 //the message loop | 71 // loop. |
70 virtual void ContinueNotifyHeadersComplete(); | 72 virtual void ContinueNotifyHeadersComplete(); |
71 | 73 |
72 typedef enum { | 74 typedef enum { |
73 START = 0x200, // initial state of the ftp job | 75 START = 0x200, // initial state of the ftp job |
74 CONNECTING, // opening the url | 76 CONNECTING, // opening the url |
75 SETTING_CUR_DIRECTORY, // attempting to change current dir to match request | 77 SETTING_CUR_DIRECTORY, // attempting to change current dir to match request |
76 FINDING_FIRST_FILE, // retrieving first file information in cur dir (by
FtpFindFirstFile) | 78 FINDING_FIRST_FILE, // retrieving first file information in cur dir (by |
| 79 // FtpFindFirstFile) |
77 GETTING_DIRECTORY, // retrieving the directory listing (if directory) | 80 GETTING_DIRECTORY, // retrieving the directory listing (if directory) |
78 GETTING_FILE_HANDLE, // initiate access to file by call to FtpOpenFile (i
f file) | 81 GETTING_FILE_HANDLE, // initiate access to file by call to FtpOpenFile |
| 82 // (if file). |
79 GETTING_FILE, // retrieving the file (if file) | 83 GETTING_FILE, // retrieving the file (if file) |
80 DONE // URLRequestInetJob is reading the response now | 84 DONE // URLRequestInetJob is reading the response now |
81 } FtpJobState; | 85 } FtpJobState; |
82 | 86 |
83 // The FtpJob has several asynchronous operations which happen | 87 // The FtpJob has several asynchronous operations which happen |
84 // in sequence. The state keeps track of which asynchronous IO | 88 // in sequence. The state keeps track of which asynchronous IO |
85 // is pending at any given point in time. | 89 // is pending at any given point in time. |
86 FtpJobState state_; | 90 FtpJobState state_; |
87 | 91 |
88 // In IE 4 and before, this pointer passed to asynchronous InternetReadFile | 92 // In IE 4 and before, this pointer passed to asynchronous InternetReadFile |
89 // calls is where the number of read bytes is written to. | 93 // calls is where the number of read bytes is written to. |
90 DWORD bytes_read_; | 94 DWORD bytes_read_; |
91 | 95 |
92 bool is_directory_; // does the url point to a file or directory | 96 bool is_directory_; // does the url point to a file or directory |
93 WIN32_FIND_DATAA find_data_; | 97 WIN32_FIND_DATAA find_data_; |
94 std::string directory_html_; // if url is directory holds html | 98 std::string directory_html_; // if url is directory holds html |
95 | 99 |
96 // When building a directory listing, we need to temporarily hold on to the | 100 // When building a directory listing, we need to temporarily hold on to the |
97 // buffer in between the time a Read() call comes in and we get the file | 101 // buffer in between the time a Read() call comes in and we get the file |
98 // entry from WinInet. | 102 // entry from WinInet. |
99 char* dest_; | 103 char* dest_; |
100 int dest_size_; | 104 int dest_size_; |
101 | 105 |
102 | 106 |
103 DISALLOW_EVIL_CONSTRUCTORS(URLRequestFtpJob); | 107 DISALLOW_EVIL_CONSTRUCTORS(URLRequestFtpJob); |
104 }; | 108 }; |
105 | 109 |
106 #endif // NET_URL_REQUEST_URL_REQUEST_FTP_JOB_H_ | 110 #endif // NET_URL_REQUEST_URL_REQUEST_FTP_JOB_H_ |
107 | 111 |
OLD | NEW |