summaryrefslogtreecommitdiffstats
path: root/net/url_request
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-19 23:04:29 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-19 23:04:29 +0000
commit721c3f17a7fb36edaa17f607a11db9c82ba720ca (patch)
treec78e993a5474acdb2751c222db8787d7aa482301 /net/url_request
parentf785ad125747f9125c952c7e74f2154098ee15a9 (diff)
downloadchromium_src-721c3f17a7fb36edaa17f607a11db9c82ba720ca.zip
chromium_src-721c3f17a7fb36edaa17f607a11db9c82ba720ca.tar.gz
chromium_src-721c3f17a7fb36edaa17f607a11db9c82ba720ca.tar.bz2
Port directory lister so test shell can view file directories.
Review URL: http://codereview.chromium.org/11437 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5725 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request')
-rw-r--r--net/url_request/url_request_file_dir_job.cc42
-rw-r--r--net/url_request/url_request_file_dir_job.h10
-rw-r--r--net/url_request/url_request_file_job.cc4
-rw-r--r--net/url_request/url_request_ftp_job.cc7
4 files changed, 38 insertions, 25 deletions
diff --git a/net/url_request/url_request_file_dir_job.cc b/net/url_request/url_request_file_dir_job.cc
index 731d741..3685107 100644
--- a/net/url_request/url_request_file_dir_job.cc
+++ b/net/url_request/url_request_file_dir_job.cc
@@ -7,16 +7,18 @@
#include "base/file_util.h"
#include "base/message_loop.h"
#include "base/string_util.h"
+#include "base/time.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"
-#include "net/base/wininet_util.h"
#include "net/url_request/url_request.h"
+#if defined(OS_POSIX)
+#include <sys/stat.h>
+#endif
+
using std::string;
using std::wstring;
-using net::WinInetUtil;
-
URLRequestFileDirJob::URLRequestFileDirJob(URLRequest* request,
const wstring& dir_path)
: URLRequestJob(request),
@@ -97,12 +99,8 @@ bool URLRequestFileDirJob::GetCharset(string* charset) {
return true;
}
-void URLRequestFileDirJob::OnListFile(const WIN32_FIND_DATA& data) {
- FILETIME local_time;
- FileTimeToLocalFileTime(&data.ftLastWriteTime, &local_time);
- int64 size = (static_cast<unsigned __int64>(data.nFileSizeHigh) << 32) |
- data.nFileSizeLow;
-
+void URLRequestFileDirJob::OnListFile(
+ const file_util::FileEnumerator::FindInfo& data) {
// We wait to write out the header until we get the first file, so that we
// can catch errors from DirectoryLister and show an error page.
if (!wrote_header_) {
@@ -110,11 +108,27 @@ void URLRequestFileDirJob::OnListFile(const WIN32_FIND_DATA& data) {
wrote_header_ = true;
}
+#if defined(OS_WIN)
+ FILETIME local_time;
+ ::FileTimeToLocalFileTime(&data.ftLastWriteTime, &local_time);
+ int64 size = (static_cast<unsigned __int64>(data.nFileSizeHigh) << 32) |
+ data.nFileSizeLow;
+
data_.append(net::GetDirectoryListingEntry(
- WideToUTF8(data.cFileName), data.dwFileAttributes, size, &local_time));
+ WideToUTF8(data.cFileName),
+ (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? true : false,
+ size,
+ base::Time::FromFileTime(local_time)));
- // TODO(darin): coalesce more?
+#elif defined(OS_POSIX)
+ data_.append(net::GetDirectoryListingEntry(
+ data.filename.c_str(),
+ S_ISDIR(data.stat.st_mode),
+ data.stat.st_size,
+ base::Time::FromTimeT(data.stat.st_mtime)));
+#endif
+ // TODO(darin): coalesce more?
CompleteRead();
}
@@ -123,8 +137,7 @@ void URLRequestFileDirJob::OnListDone(int error) {
if (error) {
read_pending_ = false;
- NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
- WinInetUtil::OSErrorToNetError(error)));
+ NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, error));
} else if (canceled_) {
read_pending_ = false;
NotifyCanceled();
@@ -176,7 +189,8 @@ void URLRequestFileDirJob::CompleteRead() {
NotifyReadComplete(bytes_read);
} else {
NOTREACHED();
- NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, 0)); // TODO: Better error code.
+ // TODO: Better error code.
+ NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, 0));
}
}
}
diff --git a/net/url_request/url_request_file_dir_job.h b/net/url_request/url_request_file_dir_job.h
index d8e7d43..afbb56b 100644
--- a/net/url_request/url_request_file_dir_job.h
+++ b/net/url_request/url_request_file_dir_job.h
@@ -5,11 +5,13 @@
#ifndef NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H__
#define NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H__
+#include "base/file_util.h"
#include "net/base/directory_lister.h"
#include "net/url_request/url_request_job.h"
-class URLRequestFileDirJob : public URLRequestJob,
- public net::DirectoryLister::Delegate {
+class URLRequestFileDirJob
+ : public URLRequestJob,
+ public net::DirectoryLister::DirectoryListerDelegate {
public:
URLRequestFileDirJob(URLRequest* request, const std::wstring& dir_path);
virtual ~URLRequestFileDirJob();
@@ -22,8 +24,8 @@ class URLRequestFileDirJob : public URLRequestJob,
virtual bool GetMimeType(std::string* mime_type);
virtual bool GetCharset(std::string* charset);
- // DirectoryLister::Delegate methods:
- virtual void OnListFile(const WIN32_FIND_DATA& data);
+ // DirectoryLister::DirectoryListerDelegate methods:
+ virtual void OnListFile(const file_util::FileEnumerator::FindInfo& data);
virtual void OnListDone(int error);
private:
diff --git a/net/url_request/url_request_file_job.cc b/net/url_request/url_request_file_job.cc
index 608dc64..5c823d8 100644
--- a/net/url_request/url_request_file_job.cc
+++ b/net/url_request/url_request_file_job.cc
@@ -28,9 +28,7 @@
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
#include "net/url_request/url_request.h"
-#if defined(OS_WIN)
#include "net/url_request/url_request_file_dir_job.h"
-#endif
#if defined(OS_WIN)
class URLRequestFileJob::AsyncResolver :
@@ -76,10 +74,8 @@ URLRequestJob* URLRequestFileJob::Factory(
std::wstring file_path;
if (net::FileURLToFilePath(request->url(), &file_path)) {
if (file_path[file_path.size() - 1] == file_util::kPathSeparator) {
-#if defined(OS_WIN)
// Only directories have trailing slashes.
return new URLRequestFileDirJob(request, file_path);
-#endif
}
}
diff --git a/net/url_request/url_request_ftp_job.cc b/net/url_request/url_request_ftp_job.cc
index 9cd7ca9..7b72118 100644
--- a/net/url_request/url_request_ftp_job.cc
+++ b/net/url_request/url_request_ftp_job.cc
@@ -9,6 +9,7 @@
#include "base/message_loop.h"
#include "base/string_util.h"
+#include "base/time.h"
#include "net/base/auth.h"
#include "net/base/load_flags.h"
#include "net/base/net_util.h"
@@ -378,8 +379,8 @@ void URLRequestFtpJob::OnFindFile(DWORD last_error) {
// We don't know the encoding, and can't assume utf8, so pass the 8bit
// directly to the browser for it to decide.
string file_entry = net::GetDirectoryListingEntry(
- find_data_.cFileName, find_data_.dwFileAttributes, size,
- &find_data_.ftLastWriteTime);
+ find_data_.cFileName, false, size,
+ base::Time::FromFileTime(find_data_.ftLastWriteTime));
WriteData(&file_entry, true);
FindNextFile();
@@ -401,7 +402,7 @@ void URLRequestFtpJob::OnStartDirectoryTraversal() {
// If this isn't top level directory (i.e. the path isn't "/",) add a link to
// the parent directory.
if (request_->url().path().length() > 1)
- html.append(net::GetDirectoryListingEntry("..", 0, 0, NULL));
+ html.append(net::GetDirectoryListingEntry("..", false, 0, base::Time()));
WriteData(&html, true);