Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: net/base/upload_file_element_reader.cc

Issue 868253012: [net] Subtract timestamps to determine if uploading file changed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatting Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/base/upload_file_element_reader_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 the expected modification time 177 // time is set, treat it as error. Note that |expected_modification_time_| may
178 // from WebKit is based on time_t precision. So we have to convert both to 178 // have gone through multiple conversion steps involving loss of precision
179 // time_t to compare. This check is used for sliced files. 179 // (including conversion to time_t). Therefore the check below only verifies
180 // that the timestamps are within one second of each other. This check is used
181 // for sliced files.
180 if (!expected_modification_time_.is_null() && 182 if (!expected_modification_time_.is_null() &&
181 expected_modification_time_.ToTimeT() != 183 (expected_modification_time_ - file_info->last_modified)
182 file_info->last_modified.ToTimeT()) { 184 .magnitude()
185 .InSeconds() != 0) {
183 callback.Run(ERR_UPLOAD_FILE_CHANGED); 186 callback.Run(ERR_UPLOAD_FILE_CHANGED);
184 return; 187 return;
185 } 188 }
186 189
187 content_length_ = length; 190 content_length_ = length;
188 bytes_remaining_ = GetContentLength(); 191 bytes_remaining_ = GetContentLength();
189 callback.Run(OK); 192 callback.Run(OK);
190 } 193 }
191 194
192 int UploadFileElementReader::OnReadCompleted( 195 int UploadFileElementReader::OnReadCompleted(
(...skipping 16 matching lines...) Expand all
209 ScopedOverridingContentLengthForTests(uint64 value) { 212 ScopedOverridingContentLengthForTests(uint64 value) {
210 overriding_content_length = value; 213 overriding_content_length = value;
211 } 214 }
212 215
213 UploadFileElementReader::ScopedOverridingContentLengthForTests:: 216 UploadFileElementReader::ScopedOverridingContentLengthForTests::
214 ~ScopedOverridingContentLengthForTests() { 217 ~ScopedOverridingContentLengthForTests() {
215 overriding_content_length = 0; 218 overriding_content_length = 0;
216 } 219 }
217 220
218 } // namespace net 221 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/base/upload_file_element_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698