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/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 return; | 167 return; |
168 } | 168 } |
169 | 169 |
170 int64 length = file_info->size; | 170 int64 length = file_info->size; |
171 if (range_offset_ < static_cast<uint64>(length)) { | 171 if (range_offset_ < static_cast<uint64>(length)) { |
172 // Compensate for the offset. | 172 // Compensate for the offset. |
173 length = std::min(length - range_offset_, range_length_); | 173 length = std::min(length - range_offset_, range_length_); |
174 } | 174 } |
175 | 175 |
176 // If the underlying file has been changed and the expected file modification | 176 // If the underlying file has been changed and the expected file modification |
177 // time is set, treat it as error. Note that |expected_modification_time_| may | 177 // time is set, treat it as error. Note that the expected modification time |
178 // have gone through multiple conversion steps involving loss of precision | 178 // from WebKit is based on time_t precision. So we have to convert both to |
179 // (including conversion to time_t). Therefore the check below only verifies | 179 // time_t to compare. This check is used for sliced files. |
180 // that the timestamps are within one second of each other. This check is used | |
181 // for sliced files. | |
182 if (!expected_modification_time_.is_null() && | 180 if (!expected_modification_time_.is_null() && |
183 (expected_modification_time_ - file_info->last_modified) | 181 expected_modification_time_.ToTimeT() != |
184 .magnitude() | 182 file_info->last_modified.ToTimeT()) { |
185 .InSeconds() != 0) { | |
186 callback.Run(ERR_UPLOAD_FILE_CHANGED); | 183 callback.Run(ERR_UPLOAD_FILE_CHANGED); |
187 return; | 184 return; |
188 } | 185 } |
189 | 186 |
190 content_length_ = length; | 187 content_length_ = length; |
191 bytes_remaining_ = GetContentLength(); | 188 bytes_remaining_ = GetContentLength(); |
192 callback.Run(OK); | 189 callback.Run(OK); |
193 } | 190 } |
194 | 191 |
195 int UploadFileElementReader::OnReadCompleted( | 192 int UploadFileElementReader::OnReadCompleted( |
(...skipping 16 matching lines...) Expand all Loading... |
212 ScopedOverridingContentLengthForTests(uint64 value) { | 209 ScopedOverridingContentLengthForTests(uint64 value) { |
213 overriding_content_length = value; | 210 overriding_content_length = value; |
214 } | 211 } |
215 | 212 |
216 UploadFileElementReader::ScopedOverridingContentLengthForTests:: | 213 UploadFileElementReader::ScopedOverridingContentLengthForTests:: |
217 ~ScopedOverridingContentLengthForTests() { | 214 ~ScopedOverridingContentLengthForTests() { |
218 overriding_content_length = 0; | 215 overriding_content_length = 0; |
219 } | 216 } |
220 | 217 |
221 } // namespace net | 218 } // namespace net |
OLD | NEW |