| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 URLRequestFileJob::URLRequestFileJob(URLRequest* request, | 86 URLRequestFileJob::URLRequestFileJob(URLRequest* request, |
| 87 const FilePath& file_path, | 87 const FilePath& file_path, |
| 88 NetworkDelegate* network_delegate) | 88 NetworkDelegate* network_delegate) |
| 89 : URLRequestJob(request, network_delegate), | 89 : URLRequestJob(request, network_delegate), |
| 90 file_path_(file_path), | 90 file_path_(file_path), |
| 91 stream_(NULL), | 91 stream_(NULL), |
| 92 is_directory_(false), | 92 is_directory_(false), |
| 93 remaining_bytes_(0) { | 93 remaining_bytes_(0) { |
| 94 } | 94 } |
| 95 | 95 |
| 96 // static | |
| 97 URLRequestJob* URLRequestFileJob::Factory(URLRequest* request, | |
| 98 const std::string& scheme) { | |
| 99 FilePath file_path; | |
| 100 const bool is_file = FileURLToFilePath(request->url(), &file_path); | |
| 101 | |
| 102 // Check file access permissions. | |
| 103 if (!request->context()->network_delegate() || | |
| 104 !request->context()->network_delegate()->CanAccessFile( | |
| 105 *request, file_path)) { | |
| 106 return new URLRequestErrorJob(request, ERR_ACCESS_DENIED); | |
| 107 } | |
| 108 | |
| 109 // We need to decide whether to create URLRequestFileJob for file access or | |
| 110 // URLRequestFileDirJob for directory access. To avoid accessing the | |
| 111 // filesystem, we only look at the path string here. | |
| 112 // The code in the URLRequestFileJob::Start() method discovers that a path, | |
| 113 // which doesn't end with a slash, should really be treated as a directory, | |
| 114 // and it then redirects to the URLRequestFileDirJob. | |
| 115 if (is_file && | |
| 116 file_util::EndsWithSeparator(file_path) && | |
| 117 file_path.IsAbsolute()) | |
| 118 return new URLRequestFileDirJob(request, file_path); | |
| 119 | |
| 120 // Use a regular file request job for all non-directories (including invalid | |
| 121 // file names). | |
| 122 return new URLRequestFileJob( | |
| 123 request, file_path, request->context()->network_delegate()); | |
| 124 } | |
| 125 | |
| 126 void URLRequestFileJob::Start() { | 96 void URLRequestFileJob::Start() { |
| 127 DCHECK(!async_resolver_); | 97 DCHECK(!async_resolver_); |
| 128 async_resolver_ = new AsyncResolver(this); | 98 async_resolver_ = new AsyncResolver(this); |
| 129 base::WorkerPool::PostTask( | 99 base::WorkerPool::PostTask( |
| 130 FROM_HERE, | 100 FROM_HERE, |
| 131 base::Bind(&AsyncResolver::Resolve, async_resolver_.get(), file_path_), | 101 base::Bind(&AsyncResolver::Resolve, async_resolver_.get(), file_path_), |
| 132 true); | 102 true); |
| 133 } | 103 } |
| 134 | 104 |
| 135 void URLRequestFileJob::Kill() { | 105 void URLRequestFileJob::Kill() { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); | 304 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 335 } | 305 } |
| 336 | 306 |
| 337 remaining_bytes_ -= result; | 307 remaining_bytes_ -= result; |
| 338 DCHECK_GE(remaining_bytes_, 0); | 308 DCHECK_GE(remaining_bytes_, 0); |
| 339 | 309 |
| 340 NotifyReadComplete(result); | 310 NotifyReadComplete(result); |
| 341 } | 311 } |
| 342 | 312 |
| 343 } // namespace net | 313 } // namespace net |
| OLD | NEW |