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

Side by Side Diff: content/browser/download/base_file.cc

Issue 11571025: Initial CL for Downloads resumption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated Pawel's comment. Created 7 years, 11 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 | Annotate | Revision Log
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 "content/browser/download/base_file.h" 5 #include "content/browser/download/base_file.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/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // writing at the end of the file. 289 // writing at the end of the file.
290 int64 seek_result = file_stream_->SeekSync(net::FROM_END, 0); 290 int64 seek_result = file_stream_->SeekSync(net::FROM_END, 0);
291 if (seek_result < 0) { 291 if (seek_result < 0) {
292 ClearStream(); 292 ClearStream();
293 return LogNetError("Seek", static_cast<net::Error>(seek_result)); 293 return LogNetError("Seek", static_cast<net::Error>(seek_result));
294 } 294 }
295 } else { 295 } else {
296 file_stream_->SetBoundNetLogSource(bound_net_log_); 296 file_stream_->SetBoundNetLogSource(bound_net_log_);
297 } 297 }
298 298
299 int64 file_size = file_stream_->SeekSync(net::FROM_END, 0);
300 if (file_size > bytes_so_far_) {
301 // The file is larger than we expected.
302 // This is OK, as long as we don't use the extra.
303 // Truncate the file.
304 int64 truncate_result = file_stream_->Truncate(bytes_so_far_);
305 if (truncate_result < 0)
306 return LogNetError("Truncate", static_cast<net::Error>(truncate_result));
307
308 // If if wasn't an error, it should have truncated to the size
309 // specified.
310 DCHECK_EQ(bytes_so_far_, truncate_result);
311 } else if (file_size < bytes_so_far_) {
312 // The file is shorter than we expected. Our hashes won't be valid.
313 return LogInterruptReason("Unable to seek to last written point", 0,
314 DOWNLOAD_INTERRUPT_REASON_FILE_TOO_SHORT);
315 }
316
299 return DOWNLOAD_INTERRUPT_REASON_NONE; 317 return DOWNLOAD_INTERRUPT_REASON_NONE;
300 } 318 }
301 319
302 void BaseFile::Close() { 320 void BaseFile::Close() {
303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
304 322
305 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_CLOSED); 323 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_CLOSED);
306 324
307 if (file_stream_.get()) { 325 if (file_stream_.get()) {
308 #if defined(OS_CHROMEOS) 326 #if defined(OS_CHROMEOS)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 const char* operation, 369 const char* operation,
352 int os_error, 370 int os_error,
353 DownloadInterruptReason reason) { 371 DownloadInterruptReason reason) {
354 bound_net_log_.AddEvent( 372 bound_net_log_.AddEvent(
355 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, 373 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR,
356 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); 374 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason));
357 return reason; 375 return reason;
358 } 376 }
359 377
360 } // namespace content 378 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/plugins/plugin_installer.cc ('k') | content/browser/download/base_file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698