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

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

Issue 10831302: Download resumption - Preliminary (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed signed/unsigned compare issue. Created 8 years 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
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 DCHECK_EQ(bytes_so_far_, truncate_result);
306 } else if (file_size < bytes_so_far_) {
307 // The file is shorter than we expected. Our hashes won't be valid.
308 // This will map to a generic 'FAIL' interrupt reason.
309 return LogNetError("Seek", net::ERR_UNEXPECTED);
310 }
311
299 return DOWNLOAD_INTERRUPT_REASON_NONE; 312 return DOWNLOAD_INTERRUPT_REASON_NONE;
300 } 313 }
301 314
302 void BaseFile::Close() { 315 void BaseFile::Close() {
303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
304 317
305 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_CLOSED); 318 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_CLOSED);
306 319
307 if (file_stream_.get()) { 320 if (file_stream_.get()) {
308 #if defined(OS_CHROMEOS) 321 #if defined(OS_CHROMEOS)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 const char* operation, 364 const char* operation,
352 int os_error, 365 int os_error,
353 DownloadInterruptReason reason) { 366 DownloadInterruptReason reason) {
354 bound_net_log_.AddEvent( 367 bound_net_log_.AddEvent(
355 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, 368 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR,
356 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); 369 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason));
357 return reason; 370 return reason;
358 } 371 }
359 372
360 } // namespace content 373 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/download/download_item_view.cc ('k') | content/browser/download/base_file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698