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_
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"
18 class URLRequestFileDirJob
19 : public URLRequestJob
,
20 public DirectoryLister::DirectoryListerDelegate
{
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
,
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
;
45 virtual ~URLRequestFileDirJob();
49 // When we have data and a read has been pending, this function
50 // will fill the response buffer and notify the request
54 // Fills a buffer with the output.
55 bool FillReadBuffer(char *buf
, int buf_size
, int *bytes_read
);
57 DirectoryLister lister_
;
62 // Indicates whether we have the complete list of the dir
65 // Indicates whether we have written the HTML 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
72 scoped_refptr
<IOBuffer
> read_buffer_
;
73 int read_buffer_length_
;
74 base::WeakPtrFactory
<URLRequestFileDirJob
> weak_factory_
;
76 DISALLOW_COPY_AND_ASSIGN(URLRequestFileDirJob
);
81 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H_