| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "webkit/fileapi/file_system_url_request_job.h" | 5 #include "webkit/fileapi/file_system_url_request_job.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/file_util_proxy.h" | |
| 9 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 10 #include "base/platform_file.h" | 9 #include "base/platform_file.h" |
| 11 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| 12 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 13 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 14 #include "net/base/file_stream.h" | 13 #include "net/base/file_stream.h" |
| 15 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
| 16 #include "net/base/mime_util.h" | 15 #include "net/base/mime_util.h" |
| 17 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 18 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
| 19 #include "net/http/http_util.h" | 18 #include "net/http/http_util.h" |
| 20 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
| 20 #include "webkit/fileapi/file_system_file_util_proxy.h" |
| 21 #include "webkit/fileapi/file_system_path_manager.h" | 21 #include "webkit/fileapi/file_system_path_manager.h" |
| 22 #include "webkit/fileapi/file_system_util.h" | 22 #include "webkit/fileapi/file_system_util.h" |
| 23 | 23 |
| 24 using net::URLRequest; | 24 using net::URLRequest; |
| 25 using net::URLRequestJob; | 25 using net::URLRequestJob; |
| 26 using net::URLRequestStatus; | 26 using net::URLRequestStatus; |
| 27 | 27 |
| 28 namespace fileapi { | 28 namespace fileapi { |
| 29 | 29 |
| 30 static const int kFileFlags = base::PLATFORM_FILE_OPEN | | 30 static const int kFileFlags = base::PLATFORM_FILE_OPEN | |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 void FileSystemURLRequestJob::DidGetRootPath(bool success, | 147 void FileSystemURLRequestJob::DidGetRootPath(bool success, |
| 148 const FilePath& root_path, | 148 const FilePath& root_path, |
| 149 const std::string& name) { | 149 const std::string& name) { |
| 150 if (!success) { | 150 if (!success) { |
| 151 NotifyFailed(net::ERR_FILE_NOT_FOUND); | 151 NotifyFailed(net::ERR_FILE_NOT_FOUND); |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 | 154 |
| 155 absolute_file_path_ = root_path.Append(relative_file_path_); | 155 absolute_file_path_ = root_path.Append(relative_file_path_); |
| 156 | 156 |
| 157 base::FileUtilProxy::GetFileInfo(file_thread_proxy_, absolute_file_path_, | 157 fileapi::FileSystemFileUtilProxy::GetFileInfo( |
| 158 file_system_operation_context_.get(), |
| 159 file_thread_proxy_, absolute_file_path_, |
| 158 callback_factory_.NewCallback(&FileSystemURLRequestJob::DidResolve)); | 160 callback_factory_.NewCallback(&FileSystemURLRequestJob::DidResolve)); |
| 159 } | 161 } |
| 160 | 162 |
| 161 void FileSystemURLRequestJob::DidResolve(base::PlatformFileError error_code, | 163 void FileSystemURLRequestJob::DidResolve(base::PlatformFileError error_code, |
| 162 const base::PlatformFileInfo& file_info) { | 164 const base::PlatformFileInfo& file_info) { |
| 163 // We may have been orphaned... | 165 // We may have been orphaned... |
| 164 if (!request_) | 166 if (!request_) |
| 165 return; | 167 return; |
| 166 | 168 |
| 167 // We use FileSystemURLRequestJob to handle files as well as directories | 169 // We use FileSystemURLRequestJob to handle files as well as directories |
| 168 // without trailing slash. | 170 // without trailing slash. |
| 169 // If a directory does not exist, we return ERR_FILE_NOT_FOUND. Otherwise, | 171 // If a directory does not exist, we return ERR_FILE_NOT_FOUND. Otherwise, |
| 170 // we will append trailing slash and redirect to FileDirJob. | 172 // we will append trailing slash and redirect to FileDirJob. |
| 171 if (error_code != base::PLATFORM_FILE_OK) { | 173 if (error_code != base::PLATFORM_FILE_OK) { |
| 172 NotifyFailed(error_code); | 174 NotifyFailed(error_code); |
| 173 return; | 175 return; |
| 174 } | 176 } |
| 175 | 177 |
| 176 is_directory_ = file_info.is_directory; | 178 is_directory_ = file_info.is_directory; |
| 177 | 179 |
| 178 if (!byte_range_.ComputeBounds(file_info.size)) { | 180 if (!byte_range_.ComputeBounds(file_info.size)) { |
| 179 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); | 181 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); |
| 180 return; | 182 return; |
| 181 } | 183 } |
| 182 | 184 |
| 183 if (!is_directory_) { | 185 if (!is_directory_) { |
| 184 base::FileUtilProxy::CreateOrOpen( | 186 fileapi::FileSystemFileUtilProxy::CreateOrOpen( |
| 187 file_system_operation_context_.get(), |
| 185 file_thread_proxy_, absolute_file_path_, kFileFlags, | 188 file_thread_proxy_, absolute_file_path_, kFileFlags, |
| 186 callback_factory_.NewCallback(&FileSystemURLRequestJob::DidOpen)); | 189 callback_factory_.NewCallback(&FileSystemURLRequestJob::DidOpen)); |
| 187 } else | 190 } else |
| 188 NotifyHeadersComplete(); | 191 NotifyHeadersComplete(); |
| 189 } | 192 } |
| 190 | 193 |
| 191 void FileSystemURLRequestJob::DidOpen(base::PlatformFileError error_code, | 194 void FileSystemURLRequestJob::DidOpen(base::PlatformFileError error_code, |
| 192 base::PassPlatformFile file, | 195 base::PassPlatformFile file, |
| 193 bool created) { | 196 bool created) { |
| 194 if (error_code != base::PLATFORM_FILE_OK) { | 197 if (error_code != base::PLATFORM_FILE_OK) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 247 } |
| 245 | 248 |
| 246 return false; | 249 return false; |
| 247 } | 250 } |
| 248 | 251 |
| 249 void FileSystemURLRequestJob::NotifyFailed(int rv) { | 252 void FileSystemURLRequestJob::NotifyFailed(int rv) { |
| 250 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 253 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
| 251 } | 254 } |
| 252 | 255 |
| 253 } // namespace fileapi | 256 } // namespace fileapi |
| OLD | NEW |