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 3 // found in the LICENSE file. 4 5 #ifndef NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H__ 6 #define NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H__ 7 8 #include <string> 9 10 #include "base/file_path.h" 11 #include "base/file_util.h" 12 #include "net/base/directory_lister.h" 13 #include "net/url_request/url_request_job.h" 14 15 class URLRequestFileDirJob 16 : public URLRequestJob, 17 public net::DirectoryLister::DirectoryListerDelegate { 18 public: 19 URLRequestFileDirJob(URLRequest* request, const FilePath& dir_path); 20 21 // URLRequestJob methods: 22 virtual void Start(); 23 virtual void StartAsync(); 24 virtual void Kill(); 25 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); 26 virtual bool GetMimeType(std::string* mime_type) const; 27 virtual bool GetCharset(std::string* charset); 28 virtual bool IsRedirectResponse(GURL* location, int* http_status_code); 29 30 // DirectoryLister::DirectoryListerDelegate methods: 31 virtual void OnListFile(const file_util::FileEnumerator::FindInfo& data); 32 virtual void OnListDone(int error); 33 34 bool list_complete() const { return list_complete_; } 35 36 private: 37 virtual ~URLRequestFileDirJob(); 38 39 void CloseLister(); 40 // When we have data and a read has been pending, this function 41 // will fill the response buffer and notify the request 42 // appropriately. 43 void CompleteRead(); 44 45 // Fills a buffer with the output. 46 bool FillReadBuffer(char *buf, int buf_size, int *bytes_read); 47 48 scoped_refptr<net::DirectoryLister> lister_; 49 FilePath dir_path_; 50 std::string data_; 51 bool canceled_; 52 53 // Indicates whether we have the complete list of the dir 54 bool list_complete_; 55 56 // Indicates whether we have written the HTML header 57 bool wrote_header_; 58 59 // To simulate Async IO, we hold onto the Reader's buffer while 60 // we wait for IO to complete. When done, we fill the buffer 61 // manually. 62 bool read_pending_; 63 scoped_refptr<net::IOBuffer> read_buffer_; 64 int read_buffer_length_; 65 66 DISALLOW_EVIL_CONSTRUCTORS(URLRequestFileDirJob); 67 }; 68 69 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H__ 70