| 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/blob/blob_url_request_job.h" | 5 #include "webkit/blob/blob_url_request_job.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 8 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 10 #include "base/file_util_proxy.h" | 11 #include "base/file_util_proxy.h" |
| 11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 12 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
| 13 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 14 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 15 #include "net/base/file_stream.h" | 16 #include "net/base/file_stream.h" |
| 16 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 44 | 45 |
| 45 static const int kFileOpenFlags = base::PLATFORM_FILE_OPEN | | 46 static const int kFileOpenFlags = base::PLATFORM_FILE_OPEN | |
| 46 base::PLATFORM_FILE_READ | | 47 base::PLATFORM_FILE_READ | |
| 47 base::PLATFORM_FILE_ASYNC; | 48 base::PLATFORM_FILE_ASYNC; |
| 48 | 49 |
| 49 BlobURLRequestJob::BlobURLRequestJob( | 50 BlobURLRequestJob::BlobURLRequestJob( |
| 50 net::URLRequest* request, | 51 net::URLRequest* request, |
| 51 BlobData* blob_data, | 52 BlobData* blob_data, |
| 52 base::MessageLoopProxy* file_thread_proxy) | 53 base::MessageLoopProxy* file_thread_proxy) |
| 53 : net::URLRequestJob(request), | 54 : net::URLRequestJob(request), |
| 54 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 55 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 55 blob_data_(blob_data), | 56 blob_data_(blob_data), |
| 56 file_thread_proxy_(file_thread_proxy), | 57 file_thread_proxy_(file_thread_proxy), |
| 57 ALLOW_THIS_IN_INITIALIZER_LIST( | 58 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 58 io_callback_(this, &BlobURLRequestJob::DidRead)), | 59 io_callback_(this, &BlobURLRequestJob::DidRead)), |
| 59 item_index_(0), | 60 item_index_(0), |
| 60 total_size_(0), | 61 total_size_(0), |
| 61 current_item_offset_(0), | 62 current_item_offset_(0), |
| 62 remaining_bytes_(0), | 63 remaining_bytes_(0), |
| 63 read_buf_offset_(0), | 64 read_buf_offset_(0), |
| 64 read_buf_size_(0), | 65 read_buf_size_(0), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 if (stream_ != NULL) { | 105 if (stream_ != NULL) { |
| 105 stream_->Close(); | 106 stream_->Close(); |
| 106 stream_.reset(NULL); | 107 stream_.reset(NULL); |
| 107 } | 108 } |
| 108 } | 109 } |
| 109 | 110 |
| 110 void BlobURLRequestJob::Kill() { | 111 void BlobURLRequestJob::Kill() { |
| 111 CloseStream(); | 112 CloseStream(); |
| 112 | 113 |
| 113 net::URLRequestJob::Kill(); | 114 net::URLRequestJob::Kill(); |
| 114 callback_factory_.RevokeAll(); | 115 weak_factory_.InvalidateWeakPtrs(); |
| 115 method_factory_.RevokeAll(); | 116 method_factory_.RevokeAll(); |
| 116 } | 117 } |
| 117 | 118 |
| 118 void BlobURLRequestJob::ResolveFile(const FilePath& file_path) { | 119 void BlobURLRequestJob::ResolveFile(const FilePath& file_path) { |
| 119 base::FileUtilProxy::GetFileInfo( | 120 base::FileUtilProxy::GetFileInfo( |
| 120 file_thread_proxy_, | 121 file_thread_proxy_, |
| 121 file_path, | 122 file_path, |
| 122 callback_factory_.NewCallback(&BlobURLRequestJob::DidResolve)); | 123 base::Bind(&BlobURLRequestJob::DidResolve, |
| 124 weak_factory_.GetWeakPtr())); |
| 123 } | 125 } |
| 124 | 126 |
| 125 void BlobURLRequestJob::DidResolve(base::PlatformFileError rv, | 127 void BlobURLRequestJob::DidResolve(base::PlatformFileError rv, |
| 126 const base::PlatformFileInfo& file_info) { | 128 const base::PlatformFileInfo& file_info) { |
| 127 // If an error occured, bail out. | 129 // If an error occured, bail out. |
| 128 if (rv == base::PLATFORM_FILE_ERROR_NOT_FOUND) { | 130 if (rv == base::PLATFORM_FILE_ERROR_NOT_FOUND) { |
| 129 NotifyFailure(net::ERR_FILE_NOT_FOUND); | 131 NotifyFailure(net::ERR_FILE_NOT_FOUND); |
| 130 return; | 132 return; |
| 131 } else if (rv != base::PLATFORM_FILE_OK) { | 133 } else if (rv != base::PLATFORM_FILE_OK) { |
| 132 NotifyFailure(net::ERR_FAILED); | 134 NotifyFailure(net::ERR_FAILED); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 return true; | 312 return true; |
| 311 } | 313 } |
| 312 | 314 |
| 313 bool BlobURLRequestJob::DispatchReadFile(const BlobData::Item& item) { | 315 bool BlobURLRequestJob::DispatchReadFile(const BlobData::Item& item) { |
| 314 // If the stream already exists, keep reading from it. | 316 // If the stream already exists, keep reading from it. |
| 315 if (stream_ != NULL) | 317 if (stream_ != NULL) |
| 316 return ReadFile(item); | 318 return ReadFile(item); |
| 317 | 319 |
| 318 base::FileUtilProxy::CreateOrOpen( | 320 base::FileUtilProxy::CreateOrOpen( |
| 319 file_thread_proxy_, item.file_path(), kFileOpenFlags, | 321 file_thread_proxy_, item.file_path(), kFileOpenFlags, |
| 320 callback_factory_.NewCallback(&BlobURLRequestJob::DidOpen)); | 322 base::Bind(&BlobURLRequestJob::DidOpen, |
| 323 weak_factory_.GetWeakPtr())); |
| 321 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); | 324 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
| 322 return false; | 325 return false; |
| 323 } | 326 } |
| 324 | 327 |
| 325 void BlobURLRequestJob::DidOpen(base::PlatformFileError rv, | 328 void BlobURLRequestJob::DidOpen(base::PlatformFileError rv, |
| 326 base::PassPlatformFile file, | 329 base::PassPlatformFile file, |
| 327 bool created) { | 330 bool created) { |
| 328 if (rv != base::PLATFORM_FILE_OK) { | 331 if (rv != base::PLATFORM_FILE_OK) { |
| 329 NotifyFailure(net::ERR_FAILED); | 332 NotifyFailure(net::ERR_FAILED); |
| 330 return; | 333 return; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 // We don't support multiple range requests in one single URL request, | 564 // We don't support multiple range requests in one single URL request, |
| 562 // because we need to do multipart encoding here. | 565 // because we need to do multipart encoding here. |
| 563 // TODO(jianli): Support multipart byte range requests. | 566 // TODO(jianli): Support multipart byte range requests. |
| 564 NotifyFailure(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); | 567 NotifyFailure(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); |
| 565 } | 568 } |
| 566 } | 569 } |
| 567 } | 570 } |
| 568 } | 571 } |
| 569 | 572 |
| 570 } // namespace webkit_blob | 573 } // namespace webkit_blob |
| OLD | NEW |