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

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

Issue 11740026: Pull delegate check back into IsDownloadReadyForCompletion so that if (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed test. 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 // 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 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls 1055 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls
1056 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage 1056 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage
1057 // notices that the upload has completed and runs its normal Finish() pathway. 1057 // notices that the upload has completed and runs its normal Finish() pathway.
1058 // MaybeCompleteDownload() is never the mechanism by which SavePackage completes 1058 // MaybeCompleteDownload() is never the mechanism by which SavePackage completes
1059 // downloads. SavePackage always uses its own Finish() to mark downloads 1059 // downloads. SavePackage always uses its own Finish() to mark downloads
1060 // complete. 1060 // complete.
1061 void DownloadItemImpl::MaybeCompleteDownload() { 1061 void DownloadItemImpl::MaybeCompleteDownload() {
1062 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1062 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1063 DCHECK(!is_save_package_download_); 1063 DCHECK(!is_save_package_download_);
1064 1064
1065 if (!IsDownloadReadyForCompletion()) 1065 if (!IsDownloadReadyForCompletion(
1066 base::Bind(&DownloadItemImpl::MaybeCompleteDownload,
1067 weak_ptr_factory_.GetWeakPtr())))
1066 return; 1068 return;
1067 1069
1068 // TODO(rdsmith): DCHECK that we only pass through this point 1070 // TODO(rdsmith): DCHECK that we only pass through this point
1069 // once per download. The natural way to do this is by a state 1071 // once per download. The natural way to do this is by a state
1070 // transition on the DownloadItem. 1072 // transition on the DownloadItem.
1071 1073
1072 // Confirm we're in the proper set of states to be here; 1074 // Confirm we're in the proper set of states to be here;
1073 // have all data, have a history handle, (validated or safe). 1075 // have all data, have a history handle, (validated or safe).
1074 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); 1076 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_);
1075 DCHECK_NE(DownloadItem::DANGEROUS, GetSafetyState()); 1077 DCHECK_NE(DownloadItem::DANGEROUS, GetSafetyState());
1076 DCHECK(all_data_saved_); 1078 DCHECK(all_data_saved_);
1077 1079
1078 OnDownloadCompleting(); 1080 OnDownloadCompleting();
1079 } 1081 }
1080 1082
1081 // Called by MaybeCompleteDownload() when it has determined that the download 1083 // Called by MaybeCompleteDownload() when it has determined that the download
1082 // is ready for completion. 1084 // is ready for completion.
1083 void DownloadItemImpl::OnDownloadCompleting() { 1085 void DownloadItemImpl::OnDownloadCompleting() {
1084 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1086 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1085 1087
1086 if (state_ != IN_PROGRESS_INTERNAL) 1088 if (state_ != IN_PROGRESS_INTERNAL)
1087 return; 1089 return;
1088 1090
1089 // Give the delegate a chance to override.
1090 delegate_->ReadyForDownloadCompletion(
1091 this, base::Bind(&DownloadItemImpl::ReadyForDownloadCompletionDone,
1092 weak_ptr_factory_.GetWeakPtr()));
1093 }
1094
1095 void DownloadItemImpl::ReadyForDownloadCompletionDone() {
1096 if (state_ != IN_PROGRESS_INTERNAL)
1097 return;
1098
1099 VLOG(20) << __FUNCTION__ << "()" 1091 VLOG(20) << __FUNCTION__ << "()"
1100 << " " << DebugString(true); 1092 << " " << DebugString(true);
1101 DCHECK(!GetTargetFilePath().empty()); 1093 DCHECK(!GetTargetFilePath().empty());
1102 DCHECK_NE(DANGEROUS, GetSafetyState()); 1094 DCHECK_NE(DANGEROUS, GetSafetyState());
1103 1095
1104 // TODO(rdsmith/benjhayden): Remove as part of SavePackage integration. 1096 // TODO(rdsmith/benjhayden): Remove as part of SavePackage integration.
1105 if (is_save_package_download_) { 1097 if (is_save_package_download_) {
1106 // Avoid doing anything on the file thread; there's nothing we control 1098 // Avoid doing anything on the file thread; there's nothing we control
1107 // there. 1099 // there.
1108 // Strictly speaking, this skips giving the embedder a chance to open 1100 // Strictly speaking, this skips giving the embedder a chance to open
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 // download_file_ can be NULL if Interrupt() is called after the download file 1232 // download_file_ can be NULL if Interrupt() is called after the download file
1241 // has been released. 1233 // has been released.
1242 if (!is_save_package_download_ && download_file_.get()) { 1234 if (!is_save_package_download_ && download_file_.get()) {
1243 BrowserThread::PostTask( 1235 BrowserThread::PostTask(
1244 BrowserThread::FILE, FROM_HERE, 1236 BrowserThread::FILE, FROM_HERE,
1245 // Will be deleted at end of task execution. 1237 // Will be deleted at end of task execution.
1246 base::Bind(&DownloadFileCancel, base::Passed(&download_file_))); 1238 base::Bind(&DownloadFileCancel, base::Passed(&download_file_)));
1247 } 1239 }
1248 } 1240 }
1249 1241
1250 bool DownloadItemImpl::IsDownloadReadyForCompletion() { 1242 bool DownloadItemImpl::IsDownloadReadyForCompletion(
1251 VLOG(20) << __FUNCTION__ << " " << AllDataSaved() 1243 const base::Closure& state_change_notification) {
1252 << " " << (GetSafetyState() != DownloadItem::DANGEROUS)
1253 << " " << (state_ == IN_PROGRESS_INTERNAL)
1254 << " " << !GetTargetFilePath().empty()
1255 << " " << (target_path_.DirName() == current_path_.DirName());
1256 // If we don't have all the data, the download is not ready for 1244 // If we don't have all the data, the download is not ready for
1257 // completion. 1245 // completion.
1258 if (!AllDataSaved()) 1246 if (!AllDataSaved())
1259 return false; 1247 return false;
1260 1248
1261 // If the download is dangerous, but not yet validated, it's not ready for 1249 // If the download is dangerous, but not yet validated, it's not ready for
1262 // completion. 1250 // completion.
1263 if (GetSafetyState() == DownloadItem::DANGEROUS) 1251 if (GetSafetyState() == DownloadItem::DANGEROUS)
1264 return false; 1252 return false;
1265 1253
1266 // If the download isn't active (e.g. has been cancelled) it's not 1254 // If the download isn't active (e.g. has been cancelled) it's not
1267 // ready for completion. 1255 // ready for completion.
1268 if (state_ != IN_PROGRESS_INTERNAL) 1256 if (state_ != IN_PROGRESS_INTERNAL)
1269 return false; 1257 return false;
1270 1258
1271 // If the target filename hasn't been determined, then it's not ready for 1259 // If the target filename hasn't been determined, then it's not ready for
1272 // completion. This is checked in ReadyForDownloadCompletionDone(). 1260 // completion. This is checked in ReadyForDownloadCompletionDone().
1273 if (GetTargetFilePath().empty()) 1261 if (GetTargetFilePath().empty())
1274 return false; 1262 return false;
1275 1263
1276 // This is checked in NeedsRename(). Without this conditional, 1264 // This is checked in NeedsRename(). Without this conditional,
1277 // browser_tests:DownloadTest.DownloadMimeType fails the DCHECK. 1265 // browser_tests:DownloadTest.DownloadMimeType fails the DCHECK.
1278 if (target_path_.DirName() != current_path_.DirName()) 1266 if (target_path_.DirName() != current_path_.DirName())
1279 return false; 1267 return false;
1280 1268
1269 // Give the delegate a chance to hold up a stop sign. It'll call
1270 // use back through the passed callback if it does and that state changes.
1271 if (!delegate_->ShouldCompleteDownload(this, state_change_notification))
1272 return false;
1273
1281 return true; 1274 return true;
1282 } 1275 }
1283 1276
1284 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state) { 1277 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state) {
1285 if (state_ == new_state) 1278 if (state_ == new_state)
1286 return; 1279 return;
1287 1280
1288 DownloadInternalState old_state = state_; 1281 DownloadInternalState old_state = state_;
1289 state_ = new_state; 1282 state_ = new_state;
1290 1283
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 return "CANCELLED"; 1406 return "CANCELLED";
1414 case INTERRUPTED_INTERNAL: 1407 case INTERRUPTED_INTERNAL:
1415 return "INTERRUPTED"; 1408 return "INTERRUPTED";
1416 default: 1409 default:
1417 NOTREACHED() << "Unknown download state " << state; 1410 NOTREACHED() << "Unknown download state " << state;
1418 return "unknown"; 1411 return "unknown";
1419 }; 1412 };
1420 } 1413 }
1421 1414
1422 } // namespace content 1415 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.h ('k') | content/browser/download/download_item_impl_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698