| 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 #include "webkit/fileapi/file_system_url_request_job.h" | 5 #include "webkit/fileapi/file_system_url_request_job.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util_proxy.h" | 10 #include "base/file_util_proxy.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
| 13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 #include "net/base/file_stream.h" | 16 #include "net/base/file_stream.h" |
| 17 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
| 18 #include "net/base/mime_util.h" | 18 #include "net/base/mime_util.h" |
| 19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 20 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
| 21 #include "net/http/http_response_headers.h" | 21 #include "net/http/http_response_headers.h" |
| 22 #include "net/http/http_response_info.h" | 22 #include "net/http/http_response_info.h" |
| 23 #include "net/http/http_util.h" | 23 #include "net/http/http_util.h" |
| 24 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
| 25 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 25 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 26 #include "webkit/fileapi/file_system_context.h" |
| 26 #include "webkit/fileapi/file_system_operation.h" | 27 #include "webkit/fileapi/file_system_operation.h" |
| 27 #include "webkit/fileapi/file_system_util.h" | 28 #include "webkit/fileapi/file_system_util.h" |
| 28 | 29 |
| 29 using net::URLRequest; | 30 using net::URLRequest; |
| 30 using net::URLRequestJob; | 31 using net::URLRequestJob; |
| 31 using net::URLRequestStatus; | 32 using net::URLRequestStatus; |
| 32 | 33 |
| 33 namespace fileapi { | 34 namespace fileapi { |
| 34 | 35 |
| 35 static const int kFileFlags = base::PLATFORM_FILE_OPEN | | 36 static const int kFileFlags = base::PLATFORM_FILE_OPEN | |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 *info = *response_info_; | 213 *info = *response_info_; |
| 213 } | 214 } |
| 214 | 215 |
| 215 int FileSystemURLRequestJob::GetResponseCode() const { | 216 int FileSystemURLRequestJob::GetResponseCode() const { |
| 216 if (response_info_.get()) | 217 if (response_info_.get()) |
| 217 return 200; | 218 return 200; |
| 218 return URLRequestJob::GetResponseCode(); | 219 return URLRequestJob::GetResponseCode(); |
| 219 } | 220 } |
| 220 | 221 |
| 221 void FileSystemURLRequestJob::StartAsync() { | 222 void FileSystemURLRequestJob::StartAsync() { |
| 222 if (request_) { | 223 if (!request_) |
| 223 (new FileSystemOperation(CallbackDispatcher::Create(this), | 224 return; |
| 224 file_thread_proxy_, | 225 FileSystemOperationInterface* operation = |
| 225 file_system_context_) | 226 file_system_context_->CreateFileSystemOperation( |
| 226 )->GetMetadata(request_->url()); | 227 request_->url(), |
| 228 CallbackDispatcher::Create(this), |
| 229 file_thread_proxy_); |
| 230 if (!operation) { |
| 231 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
| 232 net::ERR_INVALID_URL)); |
| 233 return; |
| 227 } | 234 } |
| 235 operation->GetMetadata(request_->url()); |
| 228 } | 236 } |
| 229 | 237 |
| 230 void FileSystemURLRequestJob::DidGetMetadata( | 238 void FileSystemURLRequestJob::DidGetMetadata( |
| 231 const base::PlatformFileInfo& file_info, | 239 const base::PlatformFileInfo& file_info, |
| 232 const FilePath& platform_path) { | 240 const FilePath& platform_path) { |
| 233 // We may have been orphaned... | 241 // We may have been orphaned... |
| 234 if (!request_) | 242 if (!request_) |
| 235 return; | 243 return; |
| 236 | 244 |
| 237 is_directory_ = file_info.is_directory; | 245 is_directory_ = file_info.is_directory; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 321 } |
| 314 | 322 |
| 315 return false; | 323 return false; |
| 316 } | 324 } |
| 317 | 325 |
| 318 void FileSystemURLRequestJob::NotifyFailed(int rv) { | 326 void FileSystemURLRequestJob::NotifyFailed(int rv) { |
| 319 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 327 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
| 320 } | 328 } |
| 321 | 329 |
| 322 } // namespace fileapi | 330 } // namespace fileapi |
| OLD | NEW |