| 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 "net/base/upload_file_element_reader.h" | 5 #include "net/base/upload_file_element_reader.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 if (rv != OK) { | 34 if (rv != OK) { |
| 35 // If the file can't be opened, we'll just upload an empty file. | 35 // If the file can't be opened, we'll just upload an empty file. |
| 36 DLOG(WARNING) << "Failed to open \"" << path.value() | 36 DLOG(WARNING) << "Failed to open \"" << path.value() |
| 37 << "\" for reading: " << rv; | 37 << "\" for reading: " << rv; |
| 38 file_stream.reset(); | 38 file_stream.reset(); |
| 39 } else if (range_offset) { | 39 } else if (range_offset) { |
| 40 rv = file_stream->SeekSync(FROM_BEGIN, range_offset); | 40 rv = file_stream->SeekSync(FROM_BEGIN, range_offset); |
| 41 if (rv < 0) { | 41 if (rv < 0) { |
| 42 DLOG(WARNING) << "Failed to seek \"" << path.value() | 42 DLOG(WARNING) << "Failed to seek \"" << path.value() |
| 43 << "\" to offset: " << range_offset << " (" << rv << ")"; | 43 << "\" to offset: " << range_offset << " (" << rv << ")"; |
| 44 file_stream->CloseSync(); | |
| 45 file_stream.reset(); | 44 file_stream.reset(); |
| 46 } | 45 } |
| 47 } | 46 } |
| 48 | 47 |
| 49 int64 length = 0; | 48 int64 length = 0; |
| 50 if (file_stream.get() && | 49 if (file_stream.get() && |
| 51 file_util::GetFileSize(path, &length) && | 50 file_util::GetFileSize(path, &length) && |
| 52 range_offset < static_cast<uint64>(length)) { | 51 range_offset < static_cast<uint64>(length)) { |
| 53 // Compensate for the offset. | 52 // Compensate for the offset. |
| 54 length = std::min(length - range_offset, range_length); | 53 length = std::min(length - range_offset, range_length); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 84 range_length_(range_length), | 83 range_length_(range_length), |
| 85 expected_modification_time_(expected_modification_time), | 84 expected_modification_time_(expected_modification_time), |
| 86 content_length_(0), | 85 content_length_(0), |
| 87 bytes_remaining_(0), | 86 bytes_remaining_(0), |
| 88 weak_ptr_factory_(this) { | 87 weak_ptr_factory_(this) { |
| 89 } | 88 } |
| 90 | 89 |
| 91 UploadFileElementReader::~UploadFileElementReader() { | 90 UploadFileElementReader::~UploadFileElementReader() { |
| 92 // Temporarily allow until fix: http://crbug.com/72001. | 91 // Temporarily allow until fix: http://crbug.com/72001. |
| 93 base::ThreadRestrictions::ScopedAllowIO allow_io; | 92 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 94 if (file_stream_.get()) | 93 file_stream_.reset(); |
| 95 file_stream_->CloseSync(); | |
| 96 } | 94 } |
| 97 | 95 |
| 98 int UploadFileElementReader::Init(const CompletionCallback& callback) { | 96 int UploadFileElementReader::Init(const CompletionCallback& callback) { |
| 99 scoped_ptr<FileStream>* file_stream = new scoped_ptr<FileStream>; | 97 scoped_ptr<FileStream>* file_stream = new scoped_ptr<FileStream>; |
| 100 uint64* content_length = new uint64; | 98 uint64* content_length = new uint64; |
| 101 int* result = new int; | 99 int* result = new int; |
| 102 const bool posted = base::WorkerPool::PostTaskAndReply( | 100 const bool posted = base::WorkerPool::PostTaskAndReply( |
| 103 FROM_HERE, | 101 FROM_HERE, |
| 104 base::Bind(&InitInternal, | 102 base::Bind(&InitInternal, |
| 105 path_, | 103 path_, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 ScopedOverridingContentLengthForTests(uint64 value) { | 185 ScopedOverridingContentLengthForTests(uint64 value) { |
| 188 overriding_content_length = value; | 186 overriding_content_length = value; |
| 189 } | 187 } |
| 190 | 188 |
| 191 UploadFileElementReader::ScopedOverridingContentLengthForTests:: | 189 UploadFileElementReader::ScopedOverridingContentLengthForTests:: |
| 192 ~ScopedOverridingContentLengthForTests() { | 190 ~ScopedOverridingContentLengthForTests() { |
| 193 overriding_content_length = 0; | 191 overriding_content_length = 0; |
| 194 } | 192 } |
| 195 | 193 |
| 196 } // namespace net | 194 } // namespace net |
| OLD | NEW |