Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / net / url_request / url_request_file_dir_job.h
blobf8974930d01d370840bbe84f4941763ca3425f0b
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/files/file_path.h"
11 #include "base/memory/weak_ptr.h"
12 #include "net/base/directory_lister.h"
13 #include "net/url_request/url_request_job.h"
15 namespace net {
17 class URLRequestFileDirJob
18 : public URLRequestJob,
19 public DirectoryLister::DirectoryListerDelegate {
20 public:
21 URLRequestFileDirJob(URLRequest* request,
22 NetworkDelegate* network_delegate,
23 const base::FilePath& dir_path);
25 bool list_complete() const { return list_complete_; }
27 virtual void StartAsync();
29 // Overridden from URLRequestJob:
30 virtual void Start() OVERRIDE;
31 virtual void Kill() OVERRIDE;
32 virtual bool ReadRawData(IOBuffer* buf,
33 int buf_size,
34 int* bytes_read) OVERRIDE;
35 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
36 virtual bool GetCharset(std::string* charset) OVERRIDE;
38 // Overridden from DirectoryLister::DirectoryListerDelegate:
39 virtual void OnListFile(
40 const DirectoryLister::DirectoryListerData& data) OVERRIDE;
41 virtual void OnListDone(int error) OVERRIDE;
43 private:
44 virtual ~URLRequestFileDirJob();
46 void CloseLister();
48 // When we have data and a read has been pending, this function
49 // will fill the response buffer and notify the request
50 // appropriately.
51 void CompleteRead();
53 // Fills a buffer with the output.
54 bool FillReadBuffer(char *buf, int buf_size, int *bytes_read);
56 DirectoryLister lister_;
57 base::FilePath dir_path_;
58 std::string data_;
59 bool canceled_;
61 // Indicates whether we have the complete list of the dir
62 bool list_complete_;
64 // Indicates whether we have written the HTML header
65 bool wrote_header_;
67 // To simulate Async IO, we hold onto the Reader's buffer while
68 // we wait for IO to complete. When done, we fill the buffer
69 // manually.
70 bool read_pending_;
71 scoped_refptr<IOBuffer> read_buffer_;
72 int read_buffer_length_;
73 base::WeakPtrFactory<URLRequestFileDirJob> weak_factory_;
75 DISALLOW_COPY_AND_ASSIGN(URLRequestFileDirJob);
78 } // namespace net
80 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H_