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

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

Issue 17315009: [Downloads] Add more browsertests for resumption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 // File method ordering: Methods in this file are in the same order as 5 // File method ordering: Methods in this file are in the same order as
6 // in download_item_impl.h, with the following exception: The public 6 // in download_item_impl.h, with the following exception: The public
7 // interface Start is placed in chronological order with the other 7 // interface Start is placed in chronological order with the other
8 // (private) routines that together define a DownloadItem's state 8 // (private) routines that together define a DownloadItem's state
9 // transitions as the download progresses. See "Download progression 9 // transitions as the download progresses. See "Download progression
10 // cascade" later in this file. 10 // cascade" later in this file.
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 if (GetState() == CANCELLED) { 1029 if (GetState() == CANCELLED) {
1030 // The download was in the process of resuming when it was cancelled. Don't 1030 // The download was in the process of resuming when it was cancelled. Don't
1031 // proceed. 1031 // proceed.
1032 ReleaseDownloadFile(true); 1032 ReleaseDownloadFile(true);
1033 request_handle_->CancelRequest(); 1033 request_handle_->CancelRequest();
1034 return; 1034 return;
1035 } 1035 }
1036 1036
1037 TransitionTo(IN_PROGRESS_INTERNAL); 1037 TransitionTo(IN_PROGRESS_INTERNAL);
1038 1038
1039 last_reason_ = DOWNLOAD_INTERRUPT_REASON_NONE;
1040
1041 BrowserThread::PostTask( 1039 BrowserThread::PostTask(
1042 BrowserThread::FILE, FROM_HERE, 1040 BrowserThread::FILE, FROM_HERE,
1043 base::Bind(&DownloadFile::Initialize, 1041 base::Bind(&DownloadFile::Initialize,
1044 // Safe because we control download file lifetime. 1042 // Safe because we control download file lifetime.
1045 base::Unretained(download_file_.get()), 1043 base::Unretained(download_file_.get()),
1046 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, 1044 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized,
1047 weak_ptr_factory_.GetWeakPtr()))); 1045 weak_ptr_factory_.GetWeakPtr())));
1048 } 1046 }
1049 1047
1050 void DownloadItemImpl::OnDownloadFileInitialized( 1048 void DownloadItemImpl::OnDownloadFileInitialized(
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 // Whatever happens, the first one to hit the UI thread wins. 1350 // Whatever happens, the first one to hit the UI thread wins.
1353 if (state_ != IN_PROGRESS_INTERNAL && state_ != RESUMING_INTERNAL) 1351 if (state_ != IN_PROGRESS_INTERNAL && state_ != RESUMING_INTERNAL)
1354 return; 1352 return;
1355 1353
1356 last_reason_ = reason; 1354 last_reason_ = reason;
1357 1355
1358 ResumeMode resume_mode = GetResumeMode(); 1356 ResumeMode resume_mode = GetResumeMode();
1359 // Cancel (delete file) if we're going to restart; no point in leaving 1357 // Cancel (delete file) if we're going to restart; no point in leaving
1360 // data around we aren't going to use. Also cancel if resumption isn't 1358 // data around we aren't going to use. Also cancel if resumption isn't
1361 // enabled for the same reason. 1359 // enabled for the same reason.
1362 ReleaseDownloadFile(resume_mode == RESUME_MODE_IMMEDIATE_RESTART || 1360 if (download_file_.get()) {
Randy Smith (Not in Mondays) 2013/06/19 21:46:21 What are the circumstances that trigger this code
asanka 2013/06/20 20:04:01 That's exactly the transition that's being handled
Randy Smith (Not in Mondays) 2013/06/20 20:55:22 Gotcha. To the extent possible, I'd like to make
asanka 2013/06/20 22:40:13 Yup. That's a good suggestion.
1363 resume_mode == RESUME_MODE_USER_RESTART || 1361 ReleaseDownloadFile(resume_mode == RESUME_MODE_IMMEDIATE_RESTART ||
1364 !IsDownloadResumptionEnabled()); 1362 resume_mode == RESUME_MODE_USER_RESTART ||
1363 !IsDownloadResumptionEnabled());
1364 }
1365 1365
1366 // Reset all data saved, as even if we did save all the data we're going 1366 // Reset all data saved, as even if we did save all the data we're going
1367 // to go through another round of downloading when we resume. 1367 // to go through another round of downloading when we resume.
1368 // There's a potential problem here in the abstract, as if we did download 1368 // There's a potential problem here in the abstract, as if we did download
1369 // all the data and then run into a continuable error, on resumption we 1369 // all the data and then run into a continuable error, on resumption we
1370 // won't download any more data. However, a) there are currently no 1370 // won't download any more data. However, a) there are currently no
1371 // continuable errors that can occur after we download all the data, and 1371 // continuable errors that can occur after we download all the data, and
1372 // b) if there were, that would probably simply result in a null range 1372 // b) if there were, that would probably simply result in a null range
1373 // request, which would generate a DestinationCompleted() notification 1373 // request, which would generate a DestinationCompleted() notification
1374 // from the DownloadFile, which would behave properly with setting 1374 // from the DownloadFile, which would behave properly with setting
1375 // all_data_saved_ to false here. 1375 // all_data_saved_ to false here.
1376 all_data_saved_ = false; 1376 all_data_saved_ = false;
1377 1377
1378 // Cancel the originating URL request. 1378 // Cancel the originating URL request.
1379 request_handle_->CancelRequest(); 1379 if (request_handle_.get())
1380 request_handle_->CancelRequest();
1380 1381
1381 TransitionTo(INTERRUPTED_INTERNAL); 1382 TransitionTo(INTERRUPTED_INTERNAL);
1382 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_); 1383 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_);
1383 1384
1384 AutoResumeIfValid(); 1385 AutoResumeIfValid();
1386
1387 // Since the external state could be INTERRUPTED before and after the
1388 // TransitionTo() calls, the observers may not be notified. Manually trigger
1389 // an update since the value of CanResume() may have changed.
1390 UpdateObservers();
Randy Smith (Not in Mondays) 2013/06/19 21:46:21 Making a note to myself to come back to this after
1385 } 1391 }
1386 1392
1387 void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) { 1393 void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) {
1388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1389 1395
1390 if (destroy_file) { 1396 if (destroy_file) {
1391 BrowserThread::PostTask( 1397 BrowserThread::PostTask(
1392 BrowserThread::FILE, FROM_HERE, 1398 BrowserThread::FILE, FROM_HERE,
1393 // Will be deleted at end of task execution. 1399 // Will be deleted at end of task execution.
1394 base::Bind(&DownloadFileCancel, base::Passed(&download_file_))); 1400 base::Bind(&DownloadFileCancel, base::Passed(&download_file_)));
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 case RESUME_MODE_USER_CONTINUE: 1684 case RESUME_MODE_USER_CONTINUE:
1679 return "USER_CONTINUE"; 1685 return "USER_CONTINUE";
1680 case RESUME_MODE_USER_RESTART: 1686 case RESUME_MODE_USER_RESTART:
1681 return "USER_RESTART"; 1687 return "USER_RESTART";
1682 } 1688 }
1683 NOTREACHED() << "Unknown resume mode " << mode; 1689 NOTREACHED() << "Unknown resume mode " << mode;
1684 return "unknown"; 1690 return "unknown";
1685 } 1691 }
1686 1692
1687 } // namespace content 1693 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698