Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 | 397 |
| 398 // Remove the intermediate file if we are cancelling an interrupted download. | 398 // Remove the intermediate file if we are cancelling an interrupted download. |
| 399 // Continuable interruptions leave the intermediate file around. | 399 // Continuable interruptions leave the intermediate file around. |
| 400 if ((state_ == INTERRUPTED_INTERNAL || state_ == RESUMING_INTERNAL) && | 400 if ((state_ == INTERRUPTED_INTERNAL || state_ == RESUMING_INTERNAL) && |
| 401 !current_path_.empty()) { | 401 !current_path_.empty()) { |
| 402 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 402 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 403 base::Bind(&DeleteDownloadedFile, current_path_)); | 403 base::Bind(&DeleteDownloadedFile, current_path_)); |
| 404 current_path_.clear(); | 404 current_path_.clear(); |
| 405 } | 405 } |
| 406 | 406 |
| 407 TransitionTo(CANCELLED_INTERNAL); | 407 TransitionTo(CANCELLED_INTERNAL, UPDATE_OBSERVERS); |
| 408 } | 408 } |
| 409 | 409 |
| 410 void DownloadItemImpl::Remove() { | 410 void DownloadItemImpl::Remove() { |
| 411 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); | 411 VLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); |
| 412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 413 | 413 |
| 414 delegate_->AssertStateConsistent(this); | 414 delegate_->AssertStateConsistent(this); |
| 415 Cancel(true); | 415 Cancel(true); |
| 416 delegate_->AssertStateConsistent(this); | 416 delegate_->AssertStateConsistent(this); |
| 417 | 417 |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 hash_state_ = ""; | 913 hash_state_ = ""; |
| 914 | 914 |
| 915 UpdateObservers(); | 915 UpdateObservers(); |
| 916 } | 916 } |
| 917 | 917 |
| 918 void DownloadItemImpl::MarkAsComplete() { | 918 void DownloadItemImpl::MarkAsComplete() { |
| 919 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 919 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 920 | 920 |
| 921 DCHECK(all_data_saved_); | 921 DCHECK(all_data_saved_); |
| 922 end_time_ = base::Time::Now(); | 922 end_time_ = base::Time::Now(); |
| 923 TransitionTo(COMPLETE_INTERNAL); | 923 TransitionTo(COMPLETE_INTERNAL, UPDATE_OBSERVERS); |
| 924 } | 924 } |
| 925 | |
| 925 void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far, | 926 void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far, |
| 926 int64 bytes_per_sec, | 927 int64 bytes_per_sec, |
| 927 const std::string& hash_state) { | 928 const std::string& hash_state) { |
| 928 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 929 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 929 VLOG(20) << __FUNCTION__ << " so_far=" << bytes_so_far | 930 VLOG(20) << __FUNCTION__ << " so_far=" << bytes_so_far |
| 930 << " per_sec=" << bytes_per_sec << " download=" << DebugString(true); | 931 << " per_sec=" << bytes_per_sec << " download=" << DebugString(true); |
| 931 | 932 |
| 932 if (GetState() != IN_PROGRESS) { | 933 if (GetState() != IN_PROGRESS) { |
| 933 // Ignore if we're no longer in-progress. This can happen if we race a | 934 // Ignore if we're no longer in-progress. This can happen if we race a |
| 934 // Cancel on the UI thread with an update on the FILE thread. | 935 // Cancel on the UI thread with an update on the FILE thread. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1027 request_handle_ = req_handle.Pass(); | 1028 request_handle_ = req_handle.Pass(); |
| 1028 | 1029 |
| 1029 if (GetState() == CANCELLED) { | 1030 if (GetState() == CANCELLED) { |
| 1030 // The download was in the process of resuming when it was cancelled. Don't | 1031 // The download was in the process of resuming when it was cancelled. Don't |
| 1031 // proceed. | 1032 // proceed. |
| 1032 ReleaseDownloadFile(true); | 1033 ReleaseDownloadFile(true); |
| 1033 request_handle_->CancelRequest(); | 1034 request_handle_->CancelRequest(); |
| 1034 return; | 1035 return; |
| 1035 } | 1036 } |
| 1036 | 1037 |
| 1037 TransitionTo(IN_PROGRESS_INTERNAL); | 1038 TransitionTo(IN_PROGRESS_INTERNAL, UPDATE_OBSERVERS); |
| 1038 | |
| 1039 last_reason_ = DOWNLOAD_INTERRUPT_REASON_NONE; | |
| 1040 | 1039 |
| 1041 BrowserThread::PostTask( | 1040 BrowserThread::PostTask( |
| 1042 BrowserThread::FILE, FROM_HERE, | 1041 BrowserThread::FILE, FROM_HERE, |
| 1043 base::Bind(&DownloadFile::Initialize, | 1042 base::Bind(&DownloadFile::Initialize, |
| 1044 // Safe because we control download file lifetime. | 1043 // Safe because we control download file lifetime. |
| 1045 base::Unretained(download_file_.get()), | 1044 base::Unretained(download_file_.get()), |
| 1046 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, | 1045 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, |
| 1047 weak_ptr_factory_.GetWeakPtr()))); | 1046 weak_ptr_factory_.GetWeakPtr()))); |
| 1048 } | 1047 } |
| 1049 | 1048 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1091 // UI) or automatic. If we keep the "ignore an error on download until file | 1090 // UI) or automatic. If we keep the "ignore an error on download until file |
| 1092 // name determination complete" semantics, we need to make sure that the | 1091 // name determination complete" semantics, we need to make sure that the |
| 1093 // error is kept completely invisible until that point. | 1092 // error is kept completely invisible until that point. |
| 1094 | 1093 |
| 1095 VLOG(20) << __FUNCTION__ << " " << target_path.value() << " " << disposition | 1094 VLOG(20) << __FUNCTION__ << " " << target_path.value() << " " << disposition |
| 1096 << " " << danger_type << " " << DebugString(true); | 1095 << " " << danger_type << " " << DebugString(true); |
| 1097 | 1096 |
| 1098 target_path_ = target_path; | 1097 target_path_ = target_path; |
| 1099 target_disposition_ = disposition; | 1098 target_disposition_ = disposition; |
| 1100 SetDangerType(danger_type); | 1099 SetDangerType(danger_type); |
| 1101 // TODO(asanka): SetDangerType() doesn't need to send a notification here. | |
| 1102 | 1100 |
| 1103 // We want the intermediate and target paths to refer to the same directory so | 1101 // We want the intermediate and target paths to refer to the same directory so |
| 1104 // that they are both on the same device and subject to same | 1102 // that they are both on the same device and subject to same |
| 1105 // space/permission/availability constraints. | 1103 // space/permission/availability constraints. |
| 1106 DCHECK(intermediate_path.DirName() == target_path.DirName()); | 1104 DCHECK(intermediate_path.DirName() == target_path.DirName()); |
| 1107 | 1105 |
| 1108 // During resumption, we may choose to proceed with the same intermediate | 1106 // During resumption, we may choose to proceed with the same intermediate |
| 1109 // file. No rename is necessary if our intermediate file already has the | 1107 // file. No rename is necessary if our intermediate file already has the |
| 1110 // correct name. | 1108 // correct name. |
| 1111 // | 1109 // |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1151 Interrupt(destination_error_); | 1149 Interrupt(destination_error_); |
| 1152 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE; | 1150 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE; |
| 1153 } else if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { | 1151 } else if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { |
| 1154 Interrupt(reason); | 1152 Interrupt(reason); |
| 1155 // All file errors result in file deletion above; no need to cleanup. The | 1153 // All file errors result in file deletion above; no need to cleanup. The |
| 1156 // current_path_ should be empty. Resuming this download will force a | 1154 // current_path_ should be empty. Resuming this download will force a |
| 1157 // restart and a re-doing of filename determination. | 1155 // restart and a re-doing of filename determination. |
| 1158 DCHECK(current_path_.empty()); | 1156 DCHECK(current_path_.empty()); |
| 1159 } else { | 1157 } else { |
| 1160 SetFullPath(full_path); | 1158 SetFullPath(full_path); |
| 1159 UpdateObservers(); | |
| 1161 MaybeCompleteDownload(); | 1160 MaybeCompleteDownload(); |
| 1162 } | 1161 } |
| 1163 } | 1162 } |
| 1164 | 1163 |
| 1165 // When SavePackage downloads MHTML to GData (see | 1164 // When SavePackage downloads MHTML to GData (see |
| 1166 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it | 1165 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it |
| 1167 // does for non-SavePackage downloads, but SavePackage downloads never satisfy | 1166 // does for non-SavePackage downloads, but SavePackage downloads never satisfy |
| 1168 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls | 1167 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls |
| 1169 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage | 1168 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage |
| 1170 // notices that the upload has completed and runs its normal Finish() pathway. | 1169 // notices that the upload has completed and runs its normal Finish() pathway. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1264 } | 1263 } |
| 1265 | 1264 |
| 1266 // Complete the download and release the DownloadFile. | 1265 // Complete the download and release the DownloadFile. |
| 1267 DCHECK(download_file_.get()); | 1266 DCHECK(download_file_.get()); |
| 1268 ReleaseDownloadFile(false); | 1267 ReleaseDownloadFile(false); |
| 1269 | 1268 |
| 1270 // We're not completely done with the download item yet, but at this | 1269 // We're not completely done with the download item yet, but at this |
| 1271 // point we're committed to complete the download. Cancels (or Interrupts, | 1270 // point we're committed to complete the download. Cancels (or Interrupts, |
| 1272 // though it's not clear how they could happen) after this point will be | 1271 // though it's not clear how they could happen) after this point will be |
| 1273 // ignored. | 1272 // ignored. |
| 1274 TransitionTo(COMPLETING_INTERNAL); | 1273 TransitionTo(COMPLETING_INTERNAL, DONT_UPDATE_OBSERVERS); |
| 1275 | 1274 |
| 1276 if (delegate_->ShouldOpenDownload( | 1275 if (delegate_->ShouldOpenDownload( |
| 1277 this, base::Bind(&DownloadItemImpl::DelayedDownloadOpened, | 1276 this, base::Bind(&DownloadItemImpl::DelayedDownloadOpened, |
| 1278 weak_ptr_factory_.GetWeakPtr()))) { | 1277 weak_ptr_factory_.GetWeakPtr()))) { |
| 1279 Completed(); | 1278 Completed(); |
| 1280 } else { | 1279 } else { |
| 1281 delegate_delayed_complete_ = true; | 1280 delegate_delayed_complete_ = true; |
| 1281 UpdateObservers(); | |
|
Randy Smith (Not in Mondays)
2013/06/21 18:31:28
What are we letting the observers know about here?
asanka
2013/06/21 20:30:56
I removed the UpdateObservers() call in SetFullPat
| |
| 1282 } | 1282 } |
| 1283 } | 1283 } |
| 1284 | 1284 |
| 1285 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) { | 1285 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) { |
| 1286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1287 | 1287 |
| 1288 auto_opened_ = auto_opened; | 1288 auto_opened_ = auto_opened; |
| 1289 Completed(); | 1289 Completed(); |
| 1290 } | 1290 } |
| 1291 | 1291 |
| 1292 void DownloadItemImpl::Completed() { | 1292 void DownloadItemImpl::Completed() { |
| 1293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1294 | 1294 |
| 1295 VLOG(20) << __FUNCTION__ << "() " << DebugString(false); | 1295 VLOG(20) << __FUNCTION__ << "() " << DebugString(false); |
| 1296 | 1296 |
| 1297 DCHECK(all_data_saved_); | 1297 DCHECK(all_data_saved_); |
| 1298 end_time_ = base::Time::Now(); | 1298 end_time_ = base::Time::Now(); |
| 1299 TransitionTo(COMPLETE_INTERNAL); | 1299 TransitionTo(COMPLETE_INTERNAL, UPDATE_OBSERVERS); |
| 1300 RecordDownloadCompleted(start_tick_, received_bytes_); | 1300 RecordDownloadCompleted(start_tick_, received_bytes_); |
| 1301 | 1301 |
| 1302 if (auto_opened_) { | 1302 if (auto_opened_) { |
| 1303 // If it was already handled by the delegate, do nothing. | 1303 // If it was already handled by the delegate, do nothing. |
| 1304 } else if (GetOpenWhenComplete() || | 1304 } else if (GetOpenWhenComplete() || |
| 1305 ShouldOpenFileBasedOnExtension() || | 1305 ShouldOpenFileBasedOnExtension() || |
| 1306 IsTemporary()) { | 1306 IsTemporary()) { |
| 1307 // If the download is temporary, like in drag-and-drop, do not open it but | 1307 // If the download is temporary, like in drag-and-drop, do not open it but |
| 1308 // we still need to set it auto-opened so that it can be removed from the | 1308 // we still need to set it auto-opened so that it can be removed from the |
| 1309 // download shelf. | 1309 // download shelf. |
| 1310 if (!IsTemporary()) | 1310 if (!IsTemporary()) |
| 1311 OpenDownload(); | 1311 OpenDownload(); |
| 1312 | 1312 |
| 1313 auto_opened_ = true; | 1313 auto_opened_ = true; |
| 1314 UpdateObservers(); | |
|
Randy Smith (Not in Mondays)
2013/06/21 18:31:28
I think this was for the auto_opened_ transition;
asanka
2013/06/21 20:30:56
Nope. Restored.
| |
| 1315 } | 1314 } |
| 1316 } | 1315 } |
| 1317 | 1316 |
| 1318 void DownloadItemImpl::OnResumeRequestStarted(DownloadItem* item, | 1317 void DownloadItemImpl::OnResumeRequestStarted(DownloadItem* item, |
| 1319 net::Error error) { | 1318 net::Error error) { |
| 1320 // If |item| is not NULL, then Start() has been called already, and nothing | 1319 // If |item| is not NULL, then Start() has been called already, and nothing |
| 1321 // more needs to be done here. | 1320 // more needs to be done here. |
| 1322 if (item) { | 1321 if (item) { |
| 1323 DCHECK_EQ(net::OK, error); | 1322 DCHECK_EQ(net::OK, error); |
| 1324 DCHECK_EQ(static_cast<DownloadItem*>(this), item); | 1323 DCHECK_EQ(static_cast<DownloadItem*>(this), item); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1349 // this is the place where the races collide. It's also possible for | 1348 // this is the place where the races collide. It's also possible for |
| 1350 // interrupts to race with cancels. | 1349 // interrupts to race with cancels. |
| 1351 | 1350 |
| 1352 // Whatever happens, the first one to hit the UI thread wins. | 1351 // Whatever happens, the first one to hit the UI thread wins. |
| 1353 if (state_ != IN_PROGRESS_INTERNAL && state_ != RESUMING_INTERNAL) | 1352 if (state_ != IN_PROGRESS_INTERNAL && state_ != RESUMING_INTERNAL) |
| 1354 return; | 1353 return; |
| 1355 | 1354 |
| 1356 last_reason_ = reason; | 1355 last_reason_ = reason; |
| 1357 | 1356 |
| 1358 ResumeMode resume_mode = GetResumeMode(); | 1357 ResumeMode resume_mode = GetResumeMode(); |
| 1359 // Cancel (delete file) if we're going to restart; no point in leaving | 1358 |
| 1360 // data around we aren't going to use. Also cancel if resumption isn't | 1359 if (state_ == IN_PROGRESS_INTERNAL) { |
| 1361 // enabled for the same reason. | 1360 // Cancel (delete file) if we're going to restart; no point in leaving |
| 1362 ReleaseDownloadFile(resume_mode == RESUME_MODE_IMMEDIATE_RESTART || | 1361 // data around we aren't going to use. Also cancel if resumption isn't |
| 1363 resume_mode == RESUME_MODE_USER_RESTART || | 1362 // enabled for the same reason. |
| 1364 !IsDownloadResumptionEnabled()); | 1363 ReleaseDownloadFile(resume_mode == RESUME_MODE_IMMEDIATE_RESTART || |
| 1364 resume_mode == RESUME_MODE_USER_RESTART || | |
| 1365 !IsDownloadResumptionEnabled()); | |
| 1366 | |
| 1367 // Cancel the originating URL request. | |
| 1368 request_handle_->CancelRequest(); | |
| 1369 } else { | |
| 1370 DCHECK(!download_file_.get()); | |
|
Randy Smith (Not in Mondays)
2013/06/21 18:31:28
What's the status of the request handle at this po
asanka
2013/06/21 20:30:56
The request_handle_ may or may not be NULL. E.g. i
| |
| 1371 } | |
| 1365 | 1372 |
| 1366 // Reset all data saved, as even if we did save all the data we're going | 1373 // 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. | 1374 // 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 | 1375 // 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 | 1376 // 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 | 1377 // 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 | 1378 // 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 | 1379 // b) if there were, that would probably simply result in a null range |
| 1373 // request, which would generate a DestinationCompleted() notification | 1380 // request, which would generate a DestinationCompleted() notification |
| 1374 // from the DownloadFile, which would behave properly with setting | 1381 // from the DownloadFile, which would behave properly with setting |
| 1375 // all_data_saved_ to false here. | 1382 // all_data_saved_ to false here. |
| 1376 all_data_saved_ = false; | 1383 all_data_saved_ = false; |
| 1377 | 1384 |
| 1378 // Cancel the originating URL request. | 1385 TransitionTo(INTERRUPTED_INTERNAL, DONT_UPDATE_OBSERVERS); |
| 1379 request_handle_->CancelRequest(); | |
| 1380 | |
| 1381 TransitionTo(INTERRUPTED_INTERNAL); | |
| 1382 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_); | 1386 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_); |
| 1383 | 1387 |
| 1384 AutoResumeIfValid(); | 1388 AutoResumeIfValid(); |
| 1389 UpdateObservers(); | |
| 1385 } | 1390 } |
| 1386 | 1391 |
| 1387 void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) { | 1392 void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) { |
| 1388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1389 | 1394 |
| 1390 if (destroy_file) { | 1395 if (destroy_file) { |
| 1391 BrowserThread::PostTask( | 1396 BrowserThread::PostTask( |
| 1392 BrowserThread::FILE, FROM_HERE, | 1397 BrowserThread::FILE, FROM_HERE, |
| 1393 // Will be deleted at end of task execution. | 1398 // Will be deleted at end of task execution. |
| 1394 base::Bind(&DownloadFileCancel, base::Passed(&download_file_))); | 1399 base::Bind(&DownloadFileCancel, base::Passed(&download_file_))); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1437 return false; | 1442 return false; |
| 1438 | 1443 |
| 1439 // Give the delegate a chance to hold up a stop sign. It'll call | 1444 // Give the delegate a chance to hold up a stop sign. It'll call |
| 1440 // use back through the passed callback if it does and that state changes. | 1445 // use back through the passed callback if it does and that state changes. |
| 1441 if (!delegate_->ShouldCompleteDownload(this, state_change_notification)) | 1446 if (!delegate_->ShouldCompleteDownload(this, state_change_notification)) |
| 1442 return false; | 1447 return false; |
| 1443 | 1448 |
| 1444 return true; | 1449 return true; |
| 1445 } | 1450 } |
| 1446 | 1451 |
| 1447 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state) { | 1452 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state, |
| 1453 ShouldUpdateObservers notify_action) { | |
| 1448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1454 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1449 | 1455 |
| 1450 if (state_ == new_state) | 1456 if (state_ == new_state) |
| 1451 return; | 1457 return; |
| 1452 | 1458 |
| 1453 DownloadInternalState old_state = state_; | 1459 DownloadInternalState old_state = state_; |
| 1454 state_ = new_state; | 1460 state_ = new_state; |
| 1455 | 1461 |
| 1456 switch (state_) { | 1462 switch (state_) { |
| 1457 case COMPLETING_INTERNAL: | 1463 case COMPLETING_INTERNAL: |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1485 &hash_state_)); | 1491 &hash_state_)); |
| 1486 break; | 1492 break; |
| 1487 default: | 1493 default: |
| 1488 break; | 1494 break; |
| 1489 } | 1495 } |
| 1490 | 1496 |
| 1491 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true) | 1497 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true) |
| 1492 << " " << InternalToExternalState(old_state) | 1498 << " " << InternalToExternalState(old_state) |
| 1493 << " " << InternalToExternalState(state_); | 1499 << " " << InternalToExternalState(state_); |
| 1494 | 1500 |
| 1495 // Only update observers on user visible state changes. | |
| 1496 if (InternalToExternalState(state_) != InternalToExternalState(old_state)) | |
| 1497 UpdateObservers(); | |
| 1498 | |
| 1499 bool is_done = (state_ != IN_PROGRESS_INTERNAL && | 1501 bool is_done = (state_ != IN_PROGRESS_INTERNAL && |
| 1500 state_ != COMPLETING_INTERNAL); | 1502 state_ != COMPLETING_INTERNAL); |
| 1501 bool was_done = (old_state != IN_PROGRESS_INTERNAL && | 1503 bool was_done = (old_state != IN_PROGRESS_INTERNAL && |
| 1502 old_state != COMPLETING_INTERNAL); | 1504 old_state != COMPLETING_INTERNAL); |
| 1503 // Termination | 1505 // Termination |
| 1504 if (is_done && !was_done) | 1506 if (is_done && !was_done) |
| 1505 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE); | 1507 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE); |
| 1506 | 1508 |
| 1507 // Resumption | 1509 // Resumption |
| 1508 if (was_done && !is_done) { | 1510 if (was_done && !is_done) { |
| 1509 std::string file_name(target_path_.BaseName().AsUTF8Unsafe()); | 1511 std::string file_name(target_path_.BaseName().AsUTF8Unsafe()); |
| 1510 bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, | 1512 bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, |
| 1511 base::Bind(&ItemActivatedNetLogCallback, | 1513 base::Bind(&ItemActivatedNetLogCallback, |
| 1512 this, SRC_ACTIVE_DOWNLOAD, | 1514 this, SRC_ACTIVE_DOWNLOAD, |
| 1513 &file_name)); | 1515 &file_name)); |
| 1514 } | 1516 } |
| 1517 | |
| 1518 if (notify_action == UPDATE_OBSERVERS) | |
| 1519 UpdateObservers(); | |
| 1515 } | 1520 } |
| 1516 | 1521 |
| 1517 void DownloadItemImpl::SetDangerType(DownloadDangerType danger_type) { | 1522 void DownloadItemImpl::SetDangerType(DownloadDangerType danger_type) { |
| 1518 if (danger_type != danger_type_) { | 1523 if (danger_type != danger_type_) { |
| 1519 bound_net_log_.AddEvent( | 1524 bound_net_log_.AddEvent( |
| 1520 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, | 1525 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, |
| 1521 base::Bind(&ItemCheckedNetLogCallback, danger_type)); | 1526 base::Bind(&ItemCheckedNetLogCallback, danger_type)); |
| 1522 } | 1527 } |
| 1523 danger_type_ = danger_type; | 1528 danger_type_ = danger_type; |
| 1524 } | 1529 } |
| 1525 | 1530 |
| 1526 void DownloadItemImpl::SetFullPath(const base::FilePath& new_path) { | 1531 void DownloadItemImpl::SetFullPath(const base::FilePath& new_path) { |
| 1527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1528 VLOG(20) << __FUNCTION__ << "()" | 1533 VLOG(20) << __FUNCTION__ << "()" |
| 1529 << " new_path = \"" << new_path.value() << "\"" | 1534 << " new_path = \"" << new_path.value() << "\"" |
| 1530 << " " << DebugString(true); | 1535 << " " << DebugString(true); |
| 1531 DCHECK(!new_path.empty()); | 1536 DCHECK(!new_path.empty()); |
| 1532 | 1537 |
| 1533 bound_net_log_.AddEvent( | 1538 bound_net_log_.AddEvent( |
| 1534 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, | 1539 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, |
| 1535 base::Bind(&ItemRenamedNetLogCallback, ¤t_path_, &new_path)); | 1540 base::Bind(&ItemRenamedNetLogCallback, ¤t_path_, &new_path)); |
| 1536 | 1541 |
| 1537 current_path_ = new_path; | 1542 current_path_ = new_path; |
| 1538 UpdateObservers(); | |
|
Randy Smith (Not in Mondays)
2013/06/21 18:31:28
Under what circumstances would we not want to upda
asanka
2013/06/21 20:30:56
Two of the three SetFullPath calls are made before
| |
| 1539 } | 1543 } |
| 1540 | 1544 |
| 1541 void DownloadItemImpl::AutoResumeIfValid() { | 1545 void DownloadItemImpl::AutoResumeIfValid() { |
| 1542 DVLOG(20) << __FUNCTION__ << "() " << DebugString(true); | 1546 DVLOG(20) << __FUNCTION__ << "() " << DebugString(true); |
| 1543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1547 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1544 ResumeMode mode = GetResumeMode(); | 1548 ResumeMode mode = GetResumeMode(); |
| 1545 | 1549 |
| 1546 if (mode != RESUME_MODE_IMMEDIATE_RESTART && | 1550 if (mode != RESUME_MODE_IMMEDIATE_RESTART && |
| 1547 mode != RESUME_MODE_IMMEDIATE_CONTINUE) { | 1551 mode != RESUME_MODE_IMMEDIATE_CONTINUE) { |
| 1548 return; | 1552 return; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1593 download_params->set_last_modified(GetLastModifiedTime()); | 1597 download_params->set_last_modified(GetLastModifiedTime()); |
| 1594 download_params->set_etag(GetETag()); | 1598 download_params->set_etag(GetETag()); |
| 1595 download_params->set_callback( | 1599 download_params->set_callback( |
| 1596 base::Bind(&DownloadItemImpl::OnResumeRequestStarted, | 1600 base::Bind(&DownloadItemImpl::OnResumeRequestStarted, |
| 1597 weak_ptr_factory_.GetWeakPtr())); | 1601 weak_ptr_factory_.GetWeakPtr())); |
| 1598 | 1602 |
| 1599 delegate_->ResumeInterruptedDownload(download_params.Pass(), GetGlobalId()); | 1603 delegate_->ResumeInterruptedDownload(download_params.Pass(), GetGlobalId()); |
| 1600 // Just in case we were interrupted while paused. | 1604 // Just in case we were interrupted while paused. |
| 1601 is_paused_ = false; | 1605 is_paused_ = false; |
| 1602 | 1606 |
| 1603 TransitionTo(RESUMING_INTERNAL); | 1607 TransitionTo(RESUMING_INTERNAL, DONT_UPDATE_OBSERVERS); |
| 1604 } | 1608 } |
| 1605 | 1609 |
| 1606 // static | 1610 // static |
| 1607 DownloadItem::DownloadState DownloadItemImpl::InternalToExternalState( | 1611 DownloadItem::DownloadState DownloadItemImpl::InternalToExternalState( |
| 1608 DownloadInternalState internal_state) { | 1612 DownloadInternalState internal_state) { |
| 1609 switch (internal_state) { | 1613 switch (internal_state) { |
| 1610 case IN_PROGRESS_INTERNAL: | 1614 case IN_PROGRESS_INTERNAL: |
| 1611 return IN_PROGRESS; | 1615 return IN_PROGRESS; |
| 1612 case COMPLETING_INTERNAL: | 1616 case COMPLETING_INTERNAL: |
| 1613 return IN_PROGRESS; | 1617 return IN_PROGRESS; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1678 case RESUME_MODE_USER_CONTINUE: | 1682 case RESUME_MODE_USER_CONTINUE: |
| 1679 return "USER_CONTINUE"; | 1683 return "USER_CONTINUE"; |
| 1680 case RESUME_MODE_USER_RESTART: | 1684 case RESUME_MODE_USER_RESTART: |
| 1681 return "USER_RESTART"; | 1685 return "USER_RESTART"; |
| 1682 } | 1686 } |
| 1683 NOTREACHED() << "Unknown resume mode " << mode; | 1687 NOTREACHED() << "Unknown resume mode " << mode; |
| 1684 return "unknown"; | 1688 return "unknown"; |
| 1685 } | 1689 } |
| 1686 | 1690 |
| 1687 } // namespace content | 1691 } // namespace content |
| OLD | NEW |