Chromium Code Reviews| 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 // |
| 11 // Since overlapped reads require a 'static' buffer for the duration of the | 11 // Since overlapped reads require a 'static' buffer for the duration of the |
| 12 // asynchronous read, the URLRequestFileJob keeps a buffer as a member var. In | 12 // asynchronous read, the URLRequestFileJob keeps a buffer as a member var. In |
| 13 // URLRequestFileJob::Read, data is simply copied from the object's buffer into | 13 // URLRequestFileJob::Read, data is simply copied from the object's buffer into |
| 14 // the given buffer. If there is no data to copy, the URLRequestFileJob | 14 // the given buffer. If there is no data to copy, the URLRequestFileJob |
| 15 // attempts to read more from the file to fill its buffer. If reading from the | 15 // attempts to read more from the file to fill its buffer. If reading from the |
| 16 // file does not complete synchronously, then the URLRequestFileJob waits for a | 16 // file does not complete synchronously, then the URLRequestFileJob waits for a |
| 17 // signal from the OS that the overlapped read has completed. It does so by | 17 // signal from the OS that the overlapped read has completed. It does so by |
| 18 // leveraging the MessageLoop::WatchObject API. | 18 // leveraging the MessageLoop::WatchObject API. |
| 19 | 19 |
| 20 #include "net/url_request/url_request_file_job.h" | 20 #include "net/url_request/url_request_file_job.h" |
| 21 | 21 |
| 22 #include "base/bind.h" | 22 #include "base/bind.h" |
| 23 #include "base/compiler_specific.h" | 23 #include "base/compiler_specific.h" |
| 24 #include "base/files/file_util.h" | 24 #include "base/files/file_util.h" |
| 25 #include "base/memory/ptr_util.h" | |
|
mmenke
2016/07/21 18:14:09
What's this being used for?
xunjieli
2016/07/27 20:32:03
Done.
| |
| 25 #include "base/message_loop/message_loop.h" | 26 #include "base/message_loop/message_loop.h" |
| 26 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
| 27 #include "base/synchronization/lock.h" | 28 #include "base/synchronization/lock.h" |
| 28 #include "base/task_runner.h" | 29 #include "base/task_runner.h" |
| 29 #include "base/threading/thread_restrictions.h" | 30 #include "base/threading/thread_restrictions.h" |
| 30 #include "build/build_config.h" | 31 #include "build/build_config.h" |
| 31 #include "net/base/file_stream.h" | 32 #include "net/base/file_stream.h" |
| 32 #include "net/base/filename_util.h" | 33 #include "net/base/filename_util.h" |
| 33 #include "net/base/io_buffer.h" | 34 #include "net/base/io_buffer.h" |
| 34 #include "net/base/load_flags.h" | 35 #include "net/base/load_flags.h" |
| 35 #include "net/base/mime_util.h" | 36 #include "net/base/mime_util.h" |
| 36 #include "net/filter/filter.h" | 37 #include "net/filter/gzip_stream_source.h" |
| 38 #include "net/filter/stream_source.h" | |
| 37 #include "net/http/http_util.h" | 39 #include "net/http/http_util.h" |
| 38 #include "net/url_request/url_request_error_job.h" | 40 #include "net/url_request/url_request_error_job.h" |
| 39 #include "net/url_request/url_request_file_dir_job.h" | 41 #include "net/url_request/url_request_file_dir_job.h" |
| 40 #include "url/gurl.h" | 42 #include "url/gurl.h" |
| 41 | 43 |
| 42 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
| 43 #include "base/win/shortcut.h" | 45 #include "base/win/shortcut.h" |
| 44 #endif | 46 #endif |
| 45 | 47 |
| 46 namespace net { | 48 namespace net { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 return false; | 140 return false; |
| 139 | 141 |
| 140 *location = FilePathToFileURL(new_path); | 142 *location = FilePathToFileURL(new_path); |
| 141 *http_status_code = 301; | 143 *http_status_code = 301; |
| 142 return true; | 144 return true; |
| 143 #else | 145 #else |
| 144 return false; | 146 return false; |
| 145 #endif | 147 #endif |
| 146 } | 148 } |
| 147 | 149 |
| 148 std::unique_ptr<Filter> URLRequestFileJob::SetupFilter() const { | 150 std::unique_ptr<StreamSource> URLRequestFileJob::SetupSource() { |
| 149 // Bug 9936 - .svgz files needs to be decompressed. | 151 std::unique_ptr<StreamSource> source = URLRequestJob::SetupSource(); |
| 150 return base::LowerCaseEqualsASCII(file_path_.Extension(), ".svgz") | 152 if (!base::LowerCaseEqualsASCII(file_path_.Extension(), ".svgz")) |
| 151 ? Filter::GZipFactory() | 153 return source; |
| 152 : nullptr; | 154 |
| 155 std::unique_ptr<GzipStreamSource> gzip(new GzipStreamSource( | |
| 156 std::move(source), GzipStreamSource::GZIP_STREAM_SOURCE_GZIP)); | |
| 157 if (gzip->Init()) | |
| 158 return std::move(gzip); | |
| 159 return nullptr; | |
| 153 } | 160 } |
| 154 | 161 |
| 155 bool URLRequestFileJob::GetMimeType(std::string* mime_type) const { | 162 bool URLRequestFileJob::GetMimeType(std::string* mime_type) const { |
| 156 DCHECK(request_); | 163 DCHECK(request_); |
| 157 if (meta_info_.mime_type_result) { | 164 if (meta_info_.mime_type_result) { |
| 158 *mime_type = meta_info_.mime_type; | 165 *mime_type = meta_info_.mime_type; |
| 159 return true; | 166 return true; |
| 160 } | 167 } |
| 161 return false; | 168 return false; |
| 162 } | 169 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 DCHECK_GE(remaining_bytes_, 0); | 300 DCHECK_GE(remaining_bytes_, 0); |
| 294 } | 301 } |
| 295 | 302 |
| 296 OnReadComplete(buf.get(), result); | 303 OnReadComplete(buf.get(), result); |
| 297 buf = NULL; | 304 buf = NULL; |
| 298 | 305 |
| 299 ReadRawDataComplete(result); | 306 ReadRawDataComplete(result); |
| 300 } | 307 } |
| 301 | 308 |
| 302 } // namespace net | 309 } // namespace net |
| OLD | NEW |