| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 base::File::Info file_info; | 201 base::File::Info file_info; |
| 202 meta_info->file_exists = base::GetFileInfo(file_path, &file_info); | 202 meta_info->file_exists = base::GetFileInfo(file_path, &file_info); |
| 203 if (meta_info->file_exists) { | 203 if (meta_info->file_exists) { |
| 204 meta_info->file_size = file_info.size; | 204 meta_info->file_size = file_info.size; |
| 205 meta_info->is_directory = file_info.is_directory; | 205 meta_info->is_directory = file_info.is_directory; |
| 206 } | 206 } |
| 207 // On Windows GetMimeTypeFromFile() goes to the registry. Thus it should be | 207 // On Windows GetMimeTypeFromFile() goes to the registry. Thus it should be |
| 208 // done in WorkerPool. | 208 // done in WorkerPool. |
| 209 meta_info->mime_type_result = GetMimeTypeFromFile(file_path, | 209 meta_info->mime_type_result = GetMimeTypeFromFile(file_path, |
| 210 &meta_info->mime_type); | 210 &meta_info->mime_type); |
| 211 meta_info->absolute_path = base::MakeAbsoluteFilePath(file_path); |
| 211 } | 212 } |
| 212 | 213 |
| 213 void URLRequestFileJob::DidFetchMetaInfo(const FileMetaInfo* meta_info) { | 214 void URLRequestFileJob::DidFetchMetaInfo(const FileMetaInfo* meta_info) { |
| 214 meta_info_ = *meta_info; | 215 meta_info_ = *meta_info; |
| 215 | 216 |
| 216 // We use URLRequestFileJob to handle files as well as directories without | 217 // We use URLRequestFileJob to handle files as well as directories without |
| 217 // trailing slash. | 218 // trailing slash. |
| 218 // If a directory does not exist, we return ERR_FILE_NOT_FOUND. Otherwise, | 219 // If a directory does not exist, we return ERR_FILE_NOT_FOUND. Otherwise, |
| 219 // we will append trailing slash and redirect to FileDirJob. | 220 // we will append trailing slash and redirect to FileDirJob. |
| 220 // A special case is "\" on Windows. We should resolve as invalid. | 221 // A special case is "\" on Windows. We should resolve as invalid. |
| 221 // However, Windows resolves "\" to "C:\", thus reports it as existent. | 222 // However, Windows resolves "\" to "C:\", thus reports it as existent. |
| 222 // So what happens is we append it with trailing slash and redirect it to | 223 // So what happens is we append it with trailing slash and redirect it to |
| 223 // FileDirJob where it is resolved as invalid. | 224 // FileDirJob where it is resolved as invalid. |
| 224 if (!meta_info_.file_exists) { | 225 if (!meta_info_.file_exists) { |
| 225 DidOpen(ERR_FILE_NOT_FOUND); | 226 DidOpen(ERR_FILE_NOT_FOUND); |
| 226 return; | 227 return; |
| 227 } | 228 } |
| 228 if (meta_info_.is_directory) { | 229 if (meta_info_.is_directory) { |
| 229 DidOpen(OK); | 230 DidOpen(OK); |
| 230 return; | 231 return; |
| 231 } | 232 } |
| 232 | 233 |
| 234 if (network_delegate() && |
| 235 !network_delegate()->CanAccessFile(*request(), file_path_, |
| 236 meta_info->absolute_path)) { |
| 237 DidOpen(ERR_ACCESS_DENIED); |
| 238 return; |
| 239 } |
| 240 |
| 233 int flags = base::File::FLAG_OPEN | | 241 int flags = base::File::FLAG_OPEN | |
| 234 base::File::FLAG_READ | | 242 base::File::FLAG_READ | |
| 235 base::File::FLAG_ASYNC; | 243 base::File::FLAG_ASYNC; |
| 236 int rv = stream_->Open(file_path_, flags, | 244 int rv = stream_->Open(file_path_, flags, |
| 237 base::Bind(&URLRequestFileJob::DidOpen, | 245 base::Bind(&URLRequestFileJob::DidOpen, |
| 238 weak_ptr_factory_.GetWeakPtr())); | 246 weak_ptr_factory_.GetWeakPtr())); |
| 239 if (rv != ERR_IO_PENDING) | 247 if (rv != ERR_IO_PENDING) |
| 240 DidOpen(rv); | 248 DidOpen(rv); |
| 241 } | 249 } |
| 242 | 250 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 DCHECK_GE(remaining_bytes_, 0); | 299 DCHECK_GE(remaining_bytes_, 0); |
| 292 } | 300 } |
| 293 | 301 |
| 294 OnReadComplete(buf.get(), result); | 302 OnReadComplete(buf.get(), result); |
| 295 buf = NULL; | 303 buf = NULL; |
| 296 | 304 |
| 297 ReadRawDataComplete(result); | 305 ReadRawDataComplete(result); |
| 298 } | 306 } |
| 299 | 307 |
| 300 } // namespace net | 308 } // namespace net |
| OLD | NEW |