OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_FILE_DIR_JOB_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H_ |
6 #define NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "net/base/directory_lister.h" | 12 #include "net/base/directory_lister.h" |
| 13 #include "net/base/net_errors.h" |
13 #include "net/url_request/url_request_job.h" | 14 #include "net/url_request/url_request_job.h" |
14 | 15 |
15 namespace net { | 16 namespace net { |
16 | 17 |
17 class URLRequestFileDirJob | 18 class URLRequestFileDirJob |
18 : public URLRequestJob, | 19 : public URLRequestJob, |
19 public DirectoryLister::DirectoryListerDelegate { | 20 public DirectoryLister::DirectoryListerDelegate { |
20 public: | 21 public: |
21 URLRequestFileDirJob(URLRequest* request, | 22 URLRequestFileDirJob(URLRequest* request, |
22 NetworkDelegate* network_delegate, | 23 NetworkDelegate* network_delegate, |
23 const base::FilePath& dir_path); | 24 const base::FilePath& dir_path); |
24 | 25 |
25 bool list_complete() const { return list_complete_; } | 26 bool list_complete() const { return list_complete_; } |
26 | 27 |
27 virtual void StartAsync(); | 28 virtual void StartAsync(); |
28 | 29 |
29 // Overridden from URLRequestJob: | 30 // Overridden from URLRequestJob: |
30 void Start() override; | 31 void Start() override; |
31 void Kill() override; | 32 void Kill() override; |
32 bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read) override; | 33 int ReadRawData(IOBuffer* buf, int buf_size) override; |
33 bool GetMimeType(std::string* mime_type) const override; | 34 bool GetMimeType(std::string* mime_type) const override; |
34 bool GetCharset(std::string* charset) override; | 35 bool GetCharset(std::string* charset) override; |
35 | 36 |
36 // Overridden from DirectoryLister::DirectoryListerDelegate: | 37 // Overridden from DirectoryLister::DirectoryListerDelegate: |
37 void OnListFile(const DirectoryLister::DirectoryListerData& data) override; | 38 void OnListFile(const DirectoryLister::DirectoryListerData& data) override; |
38 void OnListDone(int error) override; | 39 void OnListDone(int error) override; |
39 | 40 |
40 private: | 41 private: |
41 ~URLRequestFileDirJob() override; | 42 ~URLRequestFileDirJob() override; |
42 | 43 |
43 void CloseLister(); | 44 void CloseLister(); |
44 | 45 |
45 // When we have data and a read has been pending, this function | 46 // When we have data and a read has been pending, this function |
46 // will fill the response buffer and notify the request | 47 // will fill the response buffer and notify the request |
47 // appropriately. | 48 // appropriately. |
48 void CompleteRead(); | 49 void CompleteRead(Error error); |
49 | 50 |
50 // Fills a buffer with the output. | 51 // Fills a buffer with the output. |
51 bool FillReadBuffer(char* buf, int buf_size, int* bytes_read); | 52 bool FillReadBuffer(char* buf, int buf_size, int* bytes_read); |
52 | 53 |
53 DirectoryLister lister_; | 54 DirectoryLister lister_; |
54 base::FilePath dir_path_; | 55 base::FilePath dir_path_; |
55 std::string data_; | 56 std::string data_; |
56 bool canceled_; | 57 bool canceled_; |
57 | 58 |
58 // Indicates whether we have the complete list of the dir | 59 // Indicates whether we have the complete list of the dir |
59 bool list_complete_; | 60 bool list_complete_; |
60 | 61 |
61 // Indicates whether we have written the HTML header | 62 // Indicates whether we have written the HTML header |
62 bool wrote_header_; | 63 bool wrote_header_; |
63 | 64 |
64 // To simulate Async IO, we hold onto the Reader's buffer while | 65 // To simulate Async IO, we hold onto the Reader's buffer while |
65 // we wait for IO to complete. When done, we fill the buffer | 66 // we wait for IO to complete. When done, we fill the buffer |
66 // manually. | 67 // manually. |
67 bool read_pending_; | 68 bool read_pending_; |
68 scoped_refptr<IOBuffer> read_buffer_; | 69 scoped_refptr<IOBuffer> read_buffer_; |
69 int read_buffer_length_; | 70 int read_buffer_length_; |
| 71 |
70 base::WeakPtrFactory<URLRequestFileDirJob> weak_factory_; | 72 base::WeakPtrFactory<URLRequestFileDirJob> weak_factory_; |
71 | 73 |
72 DISALLOW_COPY_AND_ASSIGN(URLRequestFileDirJob); | 74 DISALLOW_COPY_AND_ASSIGN(URLRequestFileDirJob); |
73 }; | 75 }; |
74 | 76 |
75 } // namespace net | 77 } // namespace net |
76 | 78 |
77 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H_ | 79 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H_ |
OLD | NEW |