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

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

Issue 11150027: Handle the case where IAttachmentExecute::Save() deletes a downloaded file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 5 // File method ordering: Methods in this file are in the same order
6 // as in download_item_impl.h, with the following exception: The public 6 // as in download_item_impl.h, with the following exception: The public
7 // interfaces DelayedDownloadOpened, OnDownloadTargetDetermined, and 7 // interfaces DelayedDownloadOpened, OnDownloadTargetDetermined, and
8 // OnDownloadCompleting are placed in chronological order with the other 8 // OnDownloadCompleting are placed in chronological order with the other
9 // (private) routines that together define a DownloadItem's state transitions 9 // (private) routines that together define a DownloadItem's state transitions
10 // as the download progresses. See "Download progression cascade" later in 10 // as the download progresses. See "Download progression cascade" later in
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 // Somewhat counter-intuitively, it is possible for us to receive an 814 // Somewhat counter-intuitively, it is possible for us to receive an
815 // interrupt after we've already been interrupted. The generation of 815 // interrupt after we've already been interrupted. The generation of
816 // interrupts from the file thread Renames and the generation of 816 // interrupts from the file thread Renames and the generation of
817 // interrupts from disk writes go through two different mechanisms (driven 817 // interrupts from disk writes go through two different mechanisms (driven
818 // by rename requests from UI thread and by write requests from IO thread, 818 // by rename requests from UI thread and by write requests from IO thread,
819 // respectively), and since we choose not to keep state on the File thread, 819 // respectively), and since we choose not to keep state on the File thread,
820 // this is the place where the races collide. It's also possible for 820 // this is the place where the races collide. It's also possible for
821 // interrupts to race with cancels. 821 // interrupts to race with cancels.
822 822
823 // Whatever happens, the first one to hit the UI thread wins. 823 // Whatever happens, the first one to hit the UI thread wins.
824 if (state_ != IN_PROGRESS_INTERNAL) 824 if (state_ != IN_PROGRESS_INTERNAL && state_ != COMPLETING_INTERNAL)
825 return; 825 return;
826 826
827 last_reason_ = reason; 827 last_reason_ = reason;
828 TransitionTo(INTERRUPTED_INTERNAL); 828 TransitionTo(INTERRUPTED_INTERNAL);
829 download_stats::RecordDownloadInterrupted( 829 download_stats::RecordDownloadInterrupted(
830 reason, received_bytes_, total_bytes_); 830 reason, received_bytes_, total_bytes_);
831 delegate_->DownloadStopped(this); 831 delegate_->DownloadStopped(this);
832 } 832 }
833 833
834 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) { 834 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 // Complete the download and release the DownloadFile. 1083 // Complete the download and release the DownloadFile.
1084 BrowserThread::PostTask( 1084 BrowserThread::PostTask(
1085 BrowserThread::FILE, FROM_HERE, 1085 BrowserThread::FILE, FROM_HERE,
1086 base::Bind(&DownloadFileManager::CompleteDownload, 1086 base::Bind(&DownloadFileManager::CompleteDownload,
1087 delegate_->GetDownloadFileManager(), GetGlobalId(), 1087 delegate_->GetDownloadFileManager(), GetGlobalId(),
1088 base::Bind(&DownloadItemImpl::OnDownloadFileReleased, 1088 base::Bind(&DownloadItemImpl::OnDownloadFileReleased,
1089 weak_ptr_factory_.GetWeakPtr()))); 1089 weak_ptr_factory_.GetWeakPtr())));
1090 TransitionTo(COMPLETING_INTERNAL); 1090 TransitionTo(COMPLETING_INTERNAL);
1091 } 1091 }
1092 1092
1093 void DownloadItemImpl::OnDownloadFileReleased() { 1093 void DownloadItemImpl::OnDownloadFileReleased(
1094 content::DownloadInterruptReason reason) {
1095 if (content::DOWNLOAD_INTERRUPT_REASON_NONE != reason) {
1096 Interrupt(reason);
1097 return;
1098 }
1094 if (delegate_->ShouldOpenDownload(this)) 1099 if (delegate_->ShouldOpenDownload(this))
1095 Completed(); 1100 Completed();
1096 else 1101 else
1097 delegate_delayed_complete_ = true; 1102 delegate_delayed_complete_ = true;
1098 } 1103 }
1099 1104
1100 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) { 1105 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) {
1101 auto_opened_ = auto_opened; 1106 auto_opened_ = auto_opened;
1102 Completed(); 1107 Completed();
1103 } 1108 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 return "COMPLETE"; 1285 return "COMPLETE";
1281 case CANCELLED_INTERNAL: 1286 case CANCELLED_INTERNAL:
1282 return "CANCELLED"; 1287 return "CANCELLED";
1283 case INTERRUPTED_INTERNAL: 1288 case INTERRUPTED_INTERNAL:
1284 return "INTERRUPTED"; 1289 return "INTERRUPTED";
1285 default: 1290 default:
1286 NOTREACHED() << "Unknown download state " << state; 1291 NOTREACHED() << "Unknown download state " << state;
1287 return "unknown"; 1292 return "unknown";
1288 }; 1293 };
1289 } 1294 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698