OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/url_request/url_request_file_dir_job.h" | 5 #include "net/url_request/url_request_file_dir_job.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 return true; | 95 return true; |
96 } | 96 } |
97 | 97 |
98 bool URLRequestFileDirJob::GetCharset(string* charset) { | 98 bool URLRequestFileDirJob::GetCharset(string* charset) { |
99 // All the filenames are converted to UTF-8 before being added. | 99 // All the filenames are converted to UTF-8 before being added. |
100 *charset = "utf-8"; | 100 *charset = "utf-8"; |
101 return true; | 101 return true; |
102 } | 102 } |
103 | 103 |
104 void URLRequestFileDirJob::OnListFile( | 104 void URLRequestFileDirJob::OnListFile( |
105 const file_util::FileEnumerator::FindInfo& data) { | 105 const net::DirectoryLister::DirectoryListerData& data) { |
106 // We wait to write out the header until we get the first file, so that we | 106 // We wait to write out the header until we get the first file, so that we |
107 // can catch errors from DirectoryLister and show an error page. | 107 // can catch errors from DirectoryLister and show an error page. |
108 if (!wrote_header_) { | 108 if (!wrote_header_) { |
109 #if defined(OS_WIN) | 109 #if defined(OS_WIN) |
110 const string16& title = dir_path_.value(); | 110 const string16& title = dir_path_.value(); |
111 #elif defined(OS_POSIX) | 111 #elif defined(OS_POSIX) |
112 // TODO(jungshik): Add SysNativeMBToUTF16 to sys_string_conversions. | 112 // TODO(jungshik): Add SysNativeMBToUTF16 to sys_string_conversions. |
113 // On Mac, need to add NFKC->NFC conversion either here or in file_path. | 113 // On Mac, need to add NFKC->NFC conversion either here or in file_path. |
114 // On Linux, the file system encoding is not defined, but we assume that | 114 // On Linux, the file system encoding is not defined, but we assume that |
115 // SysNativeMBToWide takes care of it at least for now. We can try something | 115 // SysNativeMBToWide takes care of it at least for now. We can try something |
116 // more sophisticated if necessary later. | 116 // more sophisticated if necessary later. |
117 const string16& title = WideToUTF16( | 117 const string16& title = WideToUTF16( |
118 base::SysNativeMBToWide(dir_path_.value())); | 118 base::SysNativeMBToWide(dir_path_.value())); |
119 #endif | 119 #endif |
120 data_.append(net::GetDirectoryListingHeader(title)); | 120 data_.append(net::GetDirectoryListingHeader(title)); |
121 wrote_header_ = true; | 121 wrote_header_ = true; |
122 } | 122 } |
123 | 123 |
124 #if defined(OS_WIN) | 124 #if defined(OS_WIN) |
125 int64 size = (static_cast<unsigned __int64>(data.nFileSizeHigh) << 32) | | 125 int64 size = (static_cast<unsigned __int64>(data.info.nFileSizeHigh) << 32) | |
126 data.nFileSizeLow; | 126 data.info.nFileSizeLow; |
127 | 127 |
128 // Note that we should not convert ftLastWriteTime to the local time because | 128 // Note that we should not convert ftLastWriteTime to the local time because |
129 // ICU's datetime formatting APIs expect time in UTC and take into account | 129 // ICU's datetime formatting APIs expect time in UTC and take into account |
130 // the timezone before formatting. | 130 // the timezone before formatting. |
131 data_.append(net::GetDirectoryListingEntry( | 131 data_.append(net::GetDirectoryListingEntry( |
132 data.cFileName, std::string(), | 132 data.info.cFileName, std::string(), |
133 (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? true : false, | 133 (data.info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? true : false, |
134 size, | 134 size, |
135 base::Time::FromFileTime(data.ftLastWriteTime))); | 135 base::Time::FromFileTime(data.info.ftLastWriteTime))); |
136 | 136 |
137 #elif defined(OS_POSIX) | 137 #elif defined(OS_POSIX) |
138 // TOOD(jungshik): The same issue as for the directory name. | 138 // TOOD(jungshik): The same issue as for the directory name. |
139 data_.append(net::GetDirectoryListingEntry( | 139 data_.append(net::GetDirectoryListingEntry( |
140 WideToUTF16(base::SysNativeMBToWide(data.filename)), | 140 WideToUTF16(base::SysNativeMBToWide(data.info.filename)), |
141 data.filename, | 141 data.info.filename, |
142 S_ISDIR(data.stat.st_mode), | 142 S_ISDIR(data.info.stat.st_mode), |
143 data.stat.st_size, | 143 data.info.stat.st_size, |
144 base::Time::FromTimeT(data.stat.st_mtime))); | 144 base::Time::FromTimeT(data.info.stat.st_mtime))); |
145 #endif | 145 #endif |
146 | 146 |
147 // TODO(darin): coalesce more? | 147 // TODO(darin): coalesce more? |
148 CompleteRead(); | 148 CompleteRead(); |
149 } | 149 } |
150 | 150 |
151 void URLRequestFileDirJob::OnListDone(int error) { | 151 void URLRequestFileDirJob::OnListDone(int error) { |
152 CloseLister(); | 152 CloseLister(); |
153 | 153 |
154 if (canceled_) { | 154 if (canceled_) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 SetStatus(URLRequestStatus()); | 205 SetStatus(URLRequestStatus()); |
206 NotifyReadComplete(bytes_read); | 206 NotifyReadComplete(bytes_read); |
207 } else { | 207 } else { |
208 NOTREACHED(); | 208 NOTREACHED(); |
209 // TODO: Better error code. | 209 // TODO: Better error code. |
210 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, 0)); | 210 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, 0)); |
211 } | 211 } |
212 } | 212 } |
213 } | 213 } |
OLD | NEW |