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/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"
17 class URLRequestFileDirJob
18 : public URLRequestJob
,
19 public DirectoryLister::DirectoryListerDelegate
{
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 void Start() override
;
32 bool ReadRawData(IOBuffer
* buf
, int buf_size
, int* bytes_read
) override
;
33 bool GetMimeType(std::string
* mime_type
) const override
;
34 bool GetCharset(std::string
* charset
) override
;
36 // Overridden from DirectoryLister::DirectoryListerDelegate:
37 void OnListFile(const DirectoryLister::DirectoryListerData
& data
) override
;
38 void OnListDone(int error
) override
;
41 ~URLRequestFileDirJob() override
;
45 // When we have data and a read has been pending, this function
46 // will fill the response buffer and notify the request
50 // Fills a buffer with the output.
51 bool FillReadBuffer(char *buf
, int buf_size
, int *bytes_read
);
53 DirectoryLister lister_
;
54 base::FilePath dir_path_
;
58 // Indicates whether we have the complete list of the dir
61 // Indicates whether we have written the HTML header
64 // To simulate Async IO, we hold onto the Reader's buffer while
65 // we wait for IO to complete. When done, we fill the buffer
68 scoped_refptr
<IOBuffer
> read_buffer_
;
69 int read_buffer_length_
;
70 base::WeakPtrFactory
<URLRequestFileDirJob
> weak_factory_
;
72 DISALLOW_COPY_AND_ASSIGN(URLRequestFileDirJob
);
77 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H_