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