OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 DCHECK(encoding_types->empty()); | 196 DCHECK(encoding_types->empty()); |
197 | 197 |
198 // Bug 9936 - .svgz files needs to be decompressed. | 198 // Bug 9936 - .svgz files needs to be decompressed. |
199 if (LowerCaseEqualsASCII(file_path_.Extension(), ".svgz")) | 199 if (LowerCaseEqualsASCII(file_path_.Extension(), ".svgz")) |
200 encoding_types->push_back(Filter::FILTER_TYPE_GZIP); | 200 encoding_types->push_back(Filter::FILTER_TYPE_GZIP); |
201 | 201 |
202 return !encoding_types->empty(); | 202 return !encoding_types->empty(); |
203 } | 203 } |
204 | 204 |
205 bool URLRequestFileJob::GetMimeType(std::string* mime_type) const { | 205 bool URLRequestFileJob::GetMimeType(std::string* mime_type) const { |
206 // URL requests should not block on the disk! On Windows this goes to the | |
207 // registry. | |
208 // http://code.google.com/p/chromium/issues/detail?id=59849 | |
209 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
210 DCHECK(request_); | 206 DCHECK(request_); |
211 return net::GetMimeTypeFromFile(file_path_, mime_type); | 207 return net::GetMimeTypeFromFile(file_path_, mime_type); |
212 } | 208 } |
213 | 209 |
214 void URLRequestFileJob::SetExtraRequestHeaders( | 210 void URLRequestFileJob::SetExtraRequestHeaders( |
215 const net::HttpRequestHeaders& headers) { | 211 const net::HttpRequestHeaders& headers) { |
216 std::string range_header; | 212 std::string range_header; |
217 if (headers.GetHeader(net::HttpRequestHeaders::kRange, &range_header)) { | 213 if (headers.GetHeader(net::HttpRequestHeaders::kRange, &range_header)) { |
218 // We only care about "Range" header here. | 214 // We only care about "Range" header here. |
219 std::vector<net::HttpByteRange> ranges; | 215 std::vector<net::HttpByteRange> ranges; |
(...skipping 29 matching lines...) Expand all Loading... |
249 // trailing slash. | 245 // trailing slash. |
250 // If a directory does not exist, we return ERR_FILE_NOT_FOUND. Otherwise, | 246 // If a directory does not exist, we return ERR_FILE_NOT_FOUND. Otherwise, |
251 // we will append trailing slash and redirect to FileDirJob. | 247 // we will append trailing slash and redirect to FileDirJob. |
252 // A special case is "\" on Windows. We should resolve as invalid. | 248 // A special case is "\" on Windows. We should resolve as invalid. |
253 // However, Windows resolves "\" to "C:\", thus reports it as existent. | 249 // However, Windows resolves "\" to "C:\", thus reports it as existent. |
254 // So what happens is we append it with trailing slash and redirect it to | 250 // So what happens is we append it with trailing slash and redirect it to |
255 // FileDirJob where it is resolved as invalid. | 251 // FileDirJob where it is resolved as invalid. |
256 if (!exists) { | 252 if (!exists) { |
257 rv = net::ERR_FILE_NOT_FOUND; | 253 rv = net::ERR_FILE_NOT_FOUND; |
258 } else if (!is_directory_) { | 254 } else if (!is_directory_) { |
259 // URL requests should not block on the disk! | |
260 // http://code.google.com/p/chromium/issues/detail?id=59849 | |
261 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
262 | |
263 int flags = base::PLATFORM_FILE_OPEN | | 255 int flags = base::PLATFORM_FILE_OPEN | |
264 base::PLATFORM_FILE_READ | | 256 base::PLATFORM_FILE_READ | |
265 base::PLATFORM_FILE_ASYNC; | 257 base::PLATFORM_FILE_ASYNC; |
266 rv = stream_.Open(file_path_, flags); | 258 rv = stream_.Open(file_path_, flags); |
267 } | 259 } |
268 | 260 |
269 if (rv != net::OK) { | 261 if (rv != net::OK) { |
270 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 262 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
271 return; | 263 return; |
272 } | 264 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 if (!resolved) | 331 if (!resolved) |
340 return false; | 332 return false; |
341 | 333 |
342 *location = net::FilePathToFileURL(new_path); | 334 *location = net::FilePathToFileURL(new_path); |
343 *http_status_code = 301; | 335 *http_status_code = 301; |
344 return true; | 336 return true; |
345 #else | 337 #else |
346 return false; | 338 return false; |
347 #endif | 339 #endif |
348 } | 340 } |
OLD | NEW |