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_data_stream.h" | 5 #include "net/base/upload_data_stream.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
10 #include "net/base/file_stream.h" | 10 #include "net/base/file_stream.h" |
11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 | 15 |
16 const size_t UploadDataStream::kBufferSize = 16384; | 16 const size_t UploadDataStream::kBufferSize = 16384; |
17 bool UploadDataStream::merge_chunks_ = true; | 17 bool UploadDataStream::merge_chunks_ = true; |
18 | 18 |
19 UploadDataStream::~UploadDataStream() { | 19 UploadDataStream::~UploadDataStream() { |
20 } | 20 } |
21 | 21 |
22 int UploadDataStream::Init() { | 22 int UploadDataStream::Init() { |
23 DCHECK(!initialized_successfully_); | 23 DCHECK(!initialized_successfully_); |
24 | 24 |
25 total_size_ = upload_data_->GetContentLength(); | 25 total_size_ = upload_data_->GetContentLengthSyncHack(); |
26 const int result = FillBuffer(); | 26 const int result = FillBuffer(); |
27 initialized_successfully_ = (result == OK); | 27 initialized_successfully_ = (result == OK); |
28 return result; | 28 return result; |
29 } | 29 } |
30 | 30 |
31 // static | 31 // static |
32 size_t UploadDataStream::GetBufferSize() { | 32 size_t UploadDataStream::GetBufferSize() { |
33 return kBufferSize; | 33 return kBufferSize; |
34 } | 34 } |
35 | 35 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // time_t precision. So we have to convert both to time_t to compare. | 107 // time_t precision. So we have to convert both to time_t to compare. |
108 if (!element.expected_file_modification_time().is_null()) { | 108 if (!element.expected_file_modification_time().is_null()) { |
109 base::PlatformFileInfo info; | 109 base::PlatformFileInfo info; |
110 if (file_util::GetFileInfo(element.file_path(), &info) && | 110 if (file_util::GetFileInfo(element.file_path(), &info) && |
111 element.expected_file_modification_time().ToTimeT() != | 111 element.expected_file_modification_time().ToTimeT() != |
112 info.last_modified.ToTimeT()) { | 112 info.last_modified.ToTimeT()) { |
113 return ERR_UPLOAD_FILE_CHANGED; | 113 return ERR_UPLOAD_FILE_CHANGED; |
114 } | 114 } |
115 } | 115 } |
116 element_file_bytes_remaining_ = element.GetContentLength(); | 116 element_file_bytes_remaining_ = element.GetContentLength(); |
| 117 // Temporarily allow until fix: http://crbug.com/72001. |
| 118 base::ThreadRestrictions::ScopedAllowIO allow_io; |
117 element_file_stream_.reset(element.NewFileStreamForReading()); | 119 element_file_stream_.reset(element.NewFileStreamForReading()); |
118 } | 120 } |
119 | 121 |
120 const int num_bytes_to_read = | 122 const int num_bytes_to_read = |
121 static_cast<int>(std::min(element_file_bytes_remaining_, | 123 static_cast<int>(std::min(element_file_bytes_remaining_, |
122 static_cast<uint64>(free_buffer_space))); | 124 static_cast<uint64>(free_buffer_space))); |
123 if (num_bytes_to_read > 0) { | 125 if (num_bytes_to_read > 0) { |
124 int num_bytes_consumed = 0; | 126 int num_bytes_consumed = 0; |
125 // Temporarily allow until fix: http://crbug.com/72001. | 127 // Temporarily allow until fix: http://crbug.com/72001. |
126 base::ThreadRestrictions::ScopedAllowIO allow_io; | 128 base::ThreadRestrictions::ScopedAllowIO allow_io; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 elements.back().is_last_chunk())); | 201 elements.back().is_last_chunk())); |
200 } | 202 } |
201 | 203 |
202 bool UploadDataStream::IsInMemory() const { | 204 bool UploadDataStream::IsInMemory() const { |
203 DCHECK(initialized_successfully_); | 205 DCHECK(initialized_successfully_); |
204 | 206 |
205 return upload_data_->IsInMemory(); | 207 return upload_data_->IsInMemory(); |
206 } | 208 } |
207 | 209 |
208 } // namespace net | 210 } // namespace net |
OLD | NEW |