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(); |
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. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 // this is the place where the races collide. It's also possible for | 1349 // this is the place where the races collide. It's also possible for |
1350 // interrupts to race with cancels. | 1350 // interrupts to race with cancels. |
1351 | 1351 |
1352 // Whatever happens, the first one to hit the UI thread wins. | 1352 // Whatever happens, the first one to hit the UI thread wins. |
1353 if (state_ != IN_PROGRESS_INTERNAL && state_ != RESUMING_INTERNAL) | 1353 if (state_ != IN_PROGRESS_INTERNAL && state_ != RESUMING_INTERNAL) |
1354 return; | 1354 return; |
1355 | 1355 |
1356 last_reason_ = reason; | 1356 last_reason_ = reason; |
1357 | 1357 |
1358 ResumeMode resume_mode = GetResumeMode(); | 1358 ResumeMode resume_mode = GetResumeMode(); |
1359 // Cancel (delete file) if we're going to restart; no point in leaving | 1359 |
1360 // data around we aren't going to use. Also cancel if resumption isn't | 1360 if (state_ == IN_PROGRESS_INTERNAL) { |
1361 // enabled for the same reason. | 1361 // Cancel (delete file) if we're going to restart; no point in leaving |
1362 ReleaseDownloadFile(resume_mode == RESUME_MODE_IMMEDIATE_RESTART || | 1362 // data around we aren't going to use. Also cancel if resumption isn't |
1363 resume_mode == RESUME_MODE_USER_RESTART || | 1363 // enabled for the same reason. |
1364 !IsDownloadResumptionEnabled()); | 1364 ReleaseDownloadFile(resume_mode == RESUME_MODE_IMMEDIATE_RESTART || |
| 1365 resume_mode == RESUME_MODE_USER_RESTART || |
| 1366 !IsDownloadResumptionEnabled()); |
| 1367 |
| 1368 // Cancel the originating URL request. |
| 1369 request_handle_->CancelRequest(); |
| 1370 } else { |
| 1371 DCHECK(!download_file_.get()); |
| 1372 } |
1365 | 1373 |
1366 // Reset all data saved, as even if we did save all the data we're going | 1374 // 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. | 1375 // 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 | 1376 // 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 | 1377 // 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 | 1378 // 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 | 1379 // 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 | 1380 // b) if there were, that would probably simply result in a null range |
1373 // request, which would generate a DestinationCompleted() notification | 1381 // request, which would generate a DestinationCompleted() notification |
1374 // from the DownloadFile, which would behave properly with setting | 1382 // from the DownloadFile, which would behave properly with setting |
1375 // all_data_saved_ to false here. | 1383 // all_data_saved_ to false here. |
1376 all_data_saved_ = false; | 1384 all_data_saved_ = false; |
1377 | 1385 |
1378 // Cancel the originating URL request. | 1386 TransitionTo(INTERRUPTED_INTERNAL, DONT_UPDATE_OBSERVERS); |
1379 request_handle_->CancelRequest(); | |
1380 | |
1381 TransitionTo(INTERRUPTED_INTERNAL); | |
1382 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_); | 1387 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_); |
1383 | 1388 |
1384 AutoResumeIfValid(); | 1389 AutoResumeIfValid(); |
| 1390 UpdateObservers(); |
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 return false; | 1443 return false; |
1438 | 1444 |
1439 // Give the delegate a chance to hold up a stop sign. It'll call | 1445 // 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. | 1446 // use back through the passed callback if it does and that state changes. |
1441 if (!delegate_->ShouldCompleteDownload(this, state_change_notification)) | 1447 if (!delegate_->ShouldCompleteDownload(this, state_change_notification)) |
1442 return false; | 1448 return false; |
1443 | 1449 |
1444 return true; | 1450 return true; |
1445 } | 1451 } |
1446 | 1452 |
1447 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state) { | 1453 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state, |
| 1454 ShouldUpdateObservers notify_action) { |
1448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1449 | 1456 |
1450 if (state_ == new_state) | 1457 if (state_ == new_state) |
1451 return; | 1458 return; |
1452 | 1459 |
1453 DownloadInternalState old_state = state_; | 1460 DownloadInternalState old_state = state_; |
1454 state_ = new_state; | 1461 state_ = new_state; |
1455 | 1462 |
1456 switch (state_) { | 1463 switch (state_) { |
1457 case COMPLETING_INTERNAL: | 1464 case COMPLETING_INTERNAL: |
(...skipping 27 matching lines...) Expand all Loading... |
1485 &hash_state_)); | 1492 &hash_state_)); |
1486 break; | 1493 break; |
1487 default: | 1494 default: |
1488 break; | 1495 break; |
1489 } | 1496 } |
1490 | 1497 |
1491 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true) | 1498 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true) |
1492 << " " << InternalToExternalState(old_state) | 1499 << " " << InternalToExternalState(old_state) |
1493 << " " << InternalToExternalState(state_); | 1500 << " " << InternalToExternalState(state_); |
1494 | 1501 |
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 && | 1502 bool is_done = (state_ != IN_PROGRESS_INTERNAL && |
1500 state_ != COMPLETING_INTERNAL); | 1503 state_ != COMPLETING_INTERNAL); |
1501 bool was_done = (old_state != IN_PROGRESS_INTERNAL && | 1504 bool was_done = (old_state != IN_PROGRESS_INTERNAL && |
1502 old_state != COMPLETING_INTERNAL); | 1505 old_state != COMPLETING_INTERNAL); |
1503 // Termination | 1506 // Termination |
1504 if (is_done && !was_done) | 1507 if (is_done && !was_done) |
1505 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE); | 1508 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE); |
1506 | 1509 |
1507 // Resumption | 1510 // Resumption |
1508 if (was_done && !is_done) { | 1511 if (was_done && !is_done) { |
1509 std::string file_name(target_path_.BaseName().AsUTF8Unsafe()); | 1512 std::string file_name(target_path_.BaseName().AsUTF8Unsafe()); |
1510 bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, | 1513 bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, |
1511 base::Bind(&ItemActivatedNetLogCallback, | 1514 base::Bind(&ItemActivatedNetLogCallback, |
1512 this, SRC_ACTIVE_DOWNLOAD, | 1515 this, SRC_ACTIVE_DOWNLOAD, |
1513 &file_name)); | 1516 &file_name)); |
1514 } | 1517 } |
| 1518 |
| 1519 if (notify_action == UPDATE_OBSERVERS) |
| 1520 UpdateObservers(); |
1515 } | 1521 } |
1516 | 1522 |
1517 void DownloadItemImpl::SetDangerType(DownloadDangerType danger_type) { | 1523 void DownloadItemImpl::SetDangerType(DownloadDangerType danger_type) { |
1518 if (danger_type != danger_type_) { | 1524 if (danger_type != danger_type_) { |
1519 bound_net_log_.AddEvent( | 1525 bound_net_log_.AddEvent( |
1520 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, | 1526 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, |
1521 base::Bind(&ItemCheckedNetLogCallback, danger_type)); | 1527 base::Bind(&ItemCheckedNetLogCallback, danger_type)); |
1522 } | 1528 } |
1523 danger_type_ = danger_type; | 1529 danger_type_ = danger_type; |
1524 } | 1530 } |
1525 | 1531 |
1526 void DownloadItemImpl::SetFullPath(const base::FilePath& new_path) { | 1532 void DownloadItemImpl::SetFullPath(const base::FilePath& new_path) { |
1527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1533 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1528 VLOG(20) << __FUNCTION__ << "()" | 1534 VLOG(20) << __FUNCTION__ << "()" |
1529 << " new_path = \"" << new_path.value() << "\"" | 1535 << " new_path = \"" << new_path.value() << "\"" |
1530 << " " << DebugString(true); | 1536 << " " << DebugString(true); |
1531 DCHECK(!new_path.empty()); | 1537 DCHECK(!new_path.empty()); |
1532 | 1538 |
1533 bound_net_log_.AddEvent( | 1539 bound_net_log_.AddEvent( |
1534 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, | 1540 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, |
1535 base::Bind(&ItemRenamedNetLogCallback, ¤t_path_, &new_path)); | 1541 base::Bind(&ItemRenamedNetLogCallback, ¤t_path_, &new_path)); |
1536 | 1542 |
1537 current_path_ = new_path; | 1543 current_path_ = new_path; |
1538 UpdateObservers(); | |
1539 } | 1544 } |
1540 | 1545 |
1541 void DownloadItemImpl::AutoResumeIfValid() { | 1546 void DownloadItemImpl::AutoResumeIfValid() { |
1542 DVLOG(20) << __FUNCTION__ << "() " << DebugString(true); | 1547 DVLOG(20) << __FUNCTION__ << "() " << DebugString(true); |
1543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1544 ResumeMode mode = GetResumeMode(); | 1549 ResumeMode mode = GetResumeMode(); |
1545 | 1550 |
1546 if (mode != RESUME_MODE_IMMEDIATE_RESTART && | 1551 if (mode != RESUME_MODE_IMMEDIATE_RESTART && |
1547 mode != RESUME_MODE_IMMEDIATE_CONTINUE) { | 1552 mode != RESUME_MODE_IMMEDIATE_CONTINUE) { |
1548 return; | 1553 return; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1593 download_params->set_last_modified(GetLastModifiedTime()); | 1598 download_params->set_last_modified(GetLastModifiedTime()); |
1594 download_params->set_etag(GetETag()); | 1599 download_params->set_etag(GetETag()); |
1595 download_params->set_callback( | 1600 download_params->set_callback( |
1596 base::Bind(&DownloadItemImpl::OnResumeRequestStarted, | 1601 base::Bind(&DownloadItemImpl::OnResumeRequestStarted, |
1597 weak_ptr_factory_.GetWeakPtr())); | 1602 weak_ptr_factory_.GetWeakPtr())); |
1598 | 1603 |
1599 delegate_->ResumeInterruptedDownload(download_params.Pass(), GetGlobalId()); | 1604 delegate_->ResumeInterruptedDownload(download_params.Pass(), GetGlobalId()); |
1600 // Just in case we were interrupted while paused. | 1605 // Just in case we were interrupted while paused. |
1601 is_paused_ = false; | 1606 is_paused_ = false; |
1602 | 1607 |
1603 TransitionTo(RESUMING_INTERNAL); | 1608 TransitionTo(RESUMING_INTERNAL, DONT_UPDATE_OBSERVERS); |
1604 } | 1609 } |
1605 | 1610 |
1606 // static | 1611 // static |
1607 DownloadItem::DownloadState DownloadItemImpl::InternalToExternalState( | 1612 DownloadItem::DownloadState DownloadItemImpl::InternalToExternalState( |
1608 DownloadInternalState internal_state) { | 1613 DownloadInternalState internal_state) { |
1609 switch (internal_state) { | 1614 switch (internal_state) { |
1610 case IN_PROGRESS_INTERNAL: | 1615 case IN_PROGRESS_INTERNAL: |
1611 return IN_PROGRESS; | 1616 return IN_PROGRESS; |
1612 case COMPLETING_INTERNAL: | 1617 case COMPLETING_INTERNAL: |
1613 return IN_PROGRESS; | 1618 return IN_PROGRESS; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1678 case RESUME_MODE_USER_CONTINUE: | 1683 case RESUME_MODE_USER_CONTINUE: |
1679 return "USER_CONTINUE"; | 1684 return "USER_CONTINUE"; |
1680 case RESUME_MODE_USER_RESTART: | 1685 case RESUME_MODE_USER_RESTART: |
1681 return "USER_RESTART"; | 1686 return "USER_RESTART"; |
1682 } | 1687 } |
1683 NOTREACHED() << "Unknown resume mode " << mode; | 1688 NOTREACHED() << "Unknown resume mode " << mode; |
1684 return "unknown"; | 1689 return "unknown"; |
1685 } | 1690 } |
1686 | 1691 |
1687 } // namespace content | 1692 } // namespace content |
OLD | NEW |