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

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: Fix try bot problems. Created 7 years, 12 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);
asanka 2012/12/28 22:01:42 Wouldn't we need to slurp in the contents of the f
Randy Smith (Not in Mondays) 2012/12/29 17:16:16 Depending on the nature of the filesystem and the
asanka 2013/01/04 22:54:16 Ok by me. Can you add a TODO here?
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);
asanka 2012/12/28 22:01:42 This could mean an error. We should handle it inst
Randy Smith (Not in Mondays) 2012/12/29 17:16:16 Done (though the DCHECK's still there if it's not
306 } else if (file_size < bytes_so_far_) {
307 // The file is shorter than we expected. Our hashes won't be valid.
308 return LogInterruptReason("Unable to seek to last written point", 0,
309 DOWNLOAD_INTERRUPT_REASON_FILE_TOO_SHORT);
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

Powered by Google App Engine
This is Rietveld 408576698