OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 // For loading files, we make use of overlapped i/o to ensure that reading from | 5 // For loading files, we make use of overlapped i/o to ensure that reading from |
6 // the filesystem (e.g., a network filesystem) does not block the calling | 6 // the filesystem (e.g., a network filesystem) does not block the calling |
7 // thread. An alternative approach would be to use a background thread or pool | 7 // thread. An alternative approach would be to use a background thread or pool |
8 // of threads, but it seems better to leverage the operating system's ability | 8 // of threads, but it seems better to leverage the operating system's ability |
9 // to do background file reads for us. | 9 // to do background file reads for us. |
10 // | 10 // |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 encoding_types->push_back(Filter::FILTER_TYPE_GZIP); | 176 encoding_types->push_back(Filter::FILTER_TYPE_GZIP); |
177 | 177 |
178 return !encoding_types->empty(); | 178 return !encoding_types->empty(); |
179 } | 179 } |
180 | 180 |
181 bool URLRequestFileJob::GetMimeType(std::string* mime_type) const { | 181 bool URLRequestFileJob::GetMimeType(std::string* mime_type) const { |
182 DCHECK(request_); | 182 DCHECK(request_); |
183 return net::GetMimeTypeFromFile(file_path_, mime_type); | 183 return net::GetMimeTypeFromFile(file_path_, mime_type); |
184 } | 184 } |
185 | 185 |
186 void URLRequestFileJob::GetResponseInfo(net::HttpResponseInfo* info) { | |
187 DCHECK(request_); | |
188 | |
189 // If we have enabled downloading the file, the requester expects to receive | |
190 // a file handle to the file. Since we are serving file:/// url requests we | |
191 // can provide such a handle if the file exists. | |
192 bool created; | |
193 if ((request_->load_flags() & net::LOAD_ENABLE_DOWNLOAD_FILE) && | |
194 stream_.IsOpen()) { | |
195 info->response_data_file = | |
196 base::CreatePlatformFile(file_path_.ToWStringHack(), | |
197 base::PLATFORM_FILE_OPEN | | |
198 base::PLATFORM_FILE_READ | | |
199 base::PLATFORM_FILE_ASYNC, | |
200 &created); | |
201 } | |
202 } | |
203 | |
204 void URLRequestFileJob::SetExtraRequestHeaders(const std::string& headers) { | 186 void URLRequestFileJob::SetExtraRequestHeaders(const std::string& headers) { |
205 // We only care about "Range" header here. | 187 // We only care about "Range" header here. |
206 std::vector<net::HttpByteRange> ranges; | 188 std::vector<net::HttpByteRange> ranges; |
207 if (net::HttpUtil::ParseRanges(headers, &ranges)) { | 189 if (net::HttpUtil::ParseRanges(headers, &ranges)) { |
208 if (ranges.size() == 1) { | 190 if (ranges.size() == 1) { |
209 byte_range_ = ranges[0]; | 191 byte_range_ = ranges[0]; |
210 } else { | 192 } else { |
211 // We don't support multiple range requests in one single URL request, | 193 // We don't support multiple range requests in one single URL request, |
212 // because we need to do multipart encoding here. | 194 // because we need to do multipart encoding here. |
213 // TODO(hclam): decide whether we want to support multiple range requests. | 195 // TODO(hclam): decide whether we want to support multiple range requests. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 if (!resolved) | 287 if (!resolved) |
306 return false; | 288 return false; |
307 | 289 |
308 *location = net::FilePathToFileURL(FilePath(new_path)); | 290 *location = net::FilePathToFileURL(FilePath(new_path)); |
309 *http_status_code = 301; | 291 *http_status_code = 301; |
310 return true; | 292 return true; |
311 #else | 293 #else |
312 return false; | 294 return false; |
313 #endif | 295 #endif |
314 } | 296 } |
OLD | NEW |