| 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 15 matching lines...) Expand all Loading... |
| 26 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
| 27 #include "base/synchronization/lock.h" | 27 #include "base/synchronization/lock.h" |
| 28 #include "base/task_runner.h" | 28 #include "base/task_runner.h" |
| 29 #include "base/threading/thread_restrictions.h" | 29 #include "base/threading/thread_restrictions.h" |
| 30 #include "build/build_config.h" | 30 #include "build/build_config.h" |
| 31 #include "net/base/file_stream.h" | 31 #include "net/base/file_stream.h" |
| 32 #include "net/base/filename_util.h" | 32 #include "net/base/filename_util.h" |
| 33 #include "net/base/io_buffer.h" | 33 #include "net/base/io_buffer.h" |
| 34 #include "net/base/load_flags.h" | 34 #include "net/base/load_flags.h" |
| 35 #include "net/base/mime_util.h" | 35 #include "net/base/mime_util.h" |
| 36 #include "net/filter/filter.h" | 36 #include "net/filter/gzip_source_stream.h" |
| 37 #include "net/filter/source_stream.h" |
| 37 #include "net/http/http_util.h" | 38 #include "net/http/http_util.h" |
| 38 #include "net/url_request/url_request_error_job.h" | 39 #include "net/url_request/url_request_error_job.h" |
| 39 #include "net/url_request/url_request_file_dir_job.h" | 40 #include "net/url_request/url_request_file_dir_job.h" |
| 40 #include "url/gurl.h" | 41 #include "url/gurl.h" |
| 41 | 42 |
| 42 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
| 43 #include "base/win/shortcut.h" | 44 #include "base/win/shortcut.h" |
| 44 #endif | 45 #endif |
| 45 | 46 |
| 46 namespace net { | 47 namespace net { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 return false; | 139 return false; |
| 139 | 140 |
| 140 *location = FilePathToFileURL(new_path); | 141 *location = FilePathToFileURL(new_path); |
| 141 *http_status_code = 301; | 142 *http_status_code = 301; |
| 142 return true; | 143 return true; |
| 143 #else | 144 #else |
| 144 return false; | 145 return false; |
| 145 #endif | 146 #endif |
| 146 } | 147 } |
| 147 | 148 |
| 148 std::unique_ptr<Filter> URLRequestFileJob::SetupFilter() const { | |
| 149 // Bug 9936 - .svgz files needs to be decompressed. | |
| 150 return base::LowerCaseEqualsASCII(file_path_.Extension(), ".svgz") | |
| 151 ? Filter::GZipFactory() | |
| 152 : nullptr; | |
| 153 } | |
| 154 | |
| 155 bool URLRequestFileJob::GetMimeType(std::string* mime_type) const { | 149 bool URLRequestFileJob::GetMimeType(std::string* mime_type) const { |
| 156 DCHECK(request_); | 150 DCHECK(request_); |
| 157 if (meta_info_.mime_type_result) { | 151 if (meta_info_.mime_type_result) { |
| 158 *mime_type = meta_info_.mime_type; | 152 *mime_type = meta_info_.mime_type; |
| 159 return true; | 153 return true; |
| 160 } | 154 } |
| 161 return false; | 155 return false; |
| 162 } | 156 } |
| 163 | 157 |
| 164 void URLRequestFileJob::SetExtraRequestHeaders( | 158 void URLRequestFileJob::SetExtraRequestHeaders( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 185 } | 179 } |
| 186 | 180 |
| 187 void URLRequestFileJob::OnSeekComplete(int64_t result) {} | 181 void URLRequestFileJob::OnSeekComplete(int64_t result) {} |
| 188 | 182 |
| 189 void URLRequestFileJob::OnReadComplete(IOBuffer* buf, int result) { | 183 void URLRequestFileJob::OnReadComplete(IOBuffer* buf, int result) { |
| 190 } | 184 } |
| 191 | 185 |
| 192 URLRequestFileJob::~URLRequestFileJob() { | 186 URLRequestFileJob::~URLRequestFileJob() { |
| 193 } | 187 } |
| 194 | 188 |
| 189 std::unique_ptr<SourceStream> URLRequestFileJob::SetUpSourceStream() { |
| 190 std::unique_ptr<SourceStream> source = URLRequestJob::SetUpSourceStream(); |
| 191 if (!base::LowerCaseEqualsASCII(file_path_.Extension(), ".svgz")) |
| 192 return source; |
| 193 |
| 194 return GzipSourceStream::Create(std::move(source), |
| 195 GzipSourceStream::GZIP_SOURCE_STREAM_GZIP); |
| 196 } |
| 197 |
| 195 void URLRequestFileJob::FetchMetaInfo(const base::FilePath& file_path, | 198 void URLRequestFileJob::FetchMetaInfo(const base::FilePath& file_path, |
| 196 FileMetaInfo* meta_info) { | 199 FileMetaInfo* meta_info) { |
| 197 base::File::Info file_info; | 200 base::File::Info file_info; |
| 198 meta_info->file_exists = base::GetFileInfo(file_path, &file_info); | 201 meta_info->file_exists = base::GetFileInfo(file_path, &file_info); |
| 199 if (meta_info->file_exists) { | 202 if (meta_info->file_exists) { |
| 200 meta_info->file_size = file_info.size; | 203 meta_info->file_size = file_info.size; |
| 201 meta_info->is_directory = file_info.is_directory; | 204 meta_info->is_directory = file_info.is_directory; |
| 202 } | 205 } |
| 203 // On Windows GetMimeTypeFromFile() goes to the registry. Thus it should be | 206 // On Windows GetMimeTypeFromFile() goes to the registry. Thus it should be |
| 204 // done in WorkerPool. | 207 // done in WorkerPool. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 DCHECK_GE(remaining_bytes_, 0); | 296 DCHECK_GE(remaining_bytes_, 0); |
| 294 } | 297 } |
| 295 | 298 |
| 296 OnReadComplete(buf.get(), result); | 299 OnReadComplete(buf.get(), result); |
| 297 buf = NULL; | 300 buf = NULL; |
| 298 | 301 |
| 299 ReadRawDataComplete(result); | 302 ReadRawDataComplete(result); |
| 300 } | 303 } |
| 301 | 304 |
| 302 } // namespace net | 305 } // namespace net |
| OLD | NEW |