Revert 162240 - See also:
[chromium-blink-merge.git] / net / url_request / url_request_file_dir_job.h
blobbc6cccb78a07a4ac33a956d42e64391174dbe10f
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.
5 #ifndef NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H_
6 #define NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H_
8 #include <string>
10 #include "base/file_path.h"
11 #include "base/file_util.h"
12 #include "base/memory/weak_ptr.h"
13 #include "net/base/directory_lister.h"
14 #include "net/url_request/url_request_job.h"
16 namespace net {
18 class URLRequestFileDirJob
19 : public URLRequestJob,
20 public DirectoryLister::DirectoryListerDelegate {
21 public:
22 URLRequestFileDirJob(URLRequest* request,
23 NetworkDelegate* network_delegate,
24 const FilePath& dir_path);
26 bool list_complete() const { return list_complete_; }
28 virtual void StartAsync();
30 // Overridden from URLRequestJob:
31 virtual void Start() OVERRIDE;
32 virtual void Kill() OVERRIDE;
33 virtual bool ReadRawData(IOBuffer* buf,
34 int buf_size,
35 int *bytes_read) OVERRIDE;
36 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
37 virtual bool GetCharset(std::string* charset) OVERRIDE;
39 // Overridden from DirectoryLister::DirectoryListerDelegate:
40 virtual void OnListFile(
41 const DirectoryLister::DirectoryListerData& data) OVERRIDE;
42 virtual void OnListDone(int error) OVERRIDE;
44 private:
45 virtual ~URLRequestFileDirJob();
47 void CloseLister();
49 // When we have data and a read has been pending, this function
50 // will fill the response buffer and notify the request
51 // appropriately.
52 void CompleteRead();
54 // Fills a buffer with the output.
55 bool FillReadBuffer(char *buf, int buf_size, int *bytes_read);
57 DirectoryLister lister_;
58 FilePath dir_path_;
59 std::string data_;
60 bool canceled_;
62 // Indicates whether we have the complete list of the dir
63 bool list_complete_;
65 // Indicates whether we have written the HTML header
66 bool wrote_header_;
68 // To simulate Async IO, we hold onto the Reader's buffer while
69 // we wait for IO to complete. When done, we fill the buffer
70 // manually.
71 bool read_pending_;
72 scoped_refptr<IOBuffer> read_buffer_;
73 int read_buffer_length_;
74 base::WeakPtrFactory<URLRequestFileDirJob> weak_factory_;
76 DISALLOW_COPY_AND_ASSIGN(URLRequestFileDirJob);
79 } // namespace net
81 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H_