| 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 #include "content/browser/download/download_manager_impl.h" | 5 #include "content/browser/download/download_manager_impl.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 DCHECK(ContainsKey(active_downloads_, download_id)); | 443 DCHECK(ContainsKey(active_downloads_, download_id)); |
| 444 | 444 |
| 445 // Make sure the initial file name is set only once. | 445 // Make sure the initial file name is set only once. |
| 446 DCHECK(download->GetFullPath().empty()); | 446 DCHECK(download->GetFullPath().empty()); |
| 447 download->OnPathDetermined(chosen_file); | 447 download->OnPathDetermined(chosen_file); |
| 448 | 448 |
| 449 VLOG(20) << __FUNCTION__ << "()" | 449 VLOG(20) << __FUNCTION__ << "()" |
| 450 << " download = " << download->DebugString(true); | 450 << " download = " << download->DebugString(true); |
| 451 | 451 |
| 452 in_progress_[download_id] = download; | 452 in_progress_[download_id] = download; |
| 453 UpdateDownloadProgress(); // Reflect entry into in_progress_. | |
| 454 | 453 |
| 455 // Rename to intermediate name. | 454 // Rename to intermediate name. |
| 456 FilePath download_path; | 455 FilePath download_path; |
| 457 if (download->GetDangerType() != | 456 if (download->GetDangerType() != |
| 458 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { | 457 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { |
| 459 if (download->PromptUserForSaveLocation()) { | 458 if (download->PromptUserForSaveLocation()) { |
| 460 // When we prompt the user, we overwrite the FullPath with what the user | 459 // When we prompt the user, we overwrite the FullPath with what the user |
| 461 // wanted to use. Construct a file path using the previously determined | 460 // wanted to use. Construct a file path using the previously determined |
| 462 // intermediate filename and the new path. | 461 // intermediate filename and the new path. |
| 463 // TODO(asanka): This can trample an in-progress download in the new | 462 // TODO(asanka): This can trample an in-progress download in the new |
| (...skipping 26 matching lines...) Expand all Loading... |
| 490 void DownloadManagerImpl::UpdateDownload(int32 download_id, | 489 void DownloadManagerImpl::UpdateDownload(int32 download_id, |
| 491 int64 bytes_so_far, | 490 int64 bytes_so_far, |
| 492 int64 bytes_per_sec, | 491 int64 bytes_per_sec, |
| 493 const std::string& hash_state) { | 492 const std::string& hash_state) { |
| 494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 493 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 495 DownloadMap::iterator it = active_downloads_.find(download_id); | 494 DownloadMap::iterator it = active_downloads_.find(download_id); |
| 496 if (it != active_downloads_.end()) { | 495 if (it != active_downloads_.end()) { |
| 497 DownloadItem* download = it->second; | 496 DownloadItem* download = it->second; |
| 498 if (download->IsInProgress()) { | 497 if (download->IsInProgress()) { |
| 499 download->UpdateProgress(bytes_so_far, bytes_per_sec, hash_state); | 498 download->UpdateProgress(bytes_so_far, bytes_per_sec, hash_state); |
| 500 UpdateDownloadProgress(); // Reflect size updates. | |
| 501 delegate_->UpdateItemInPersistentStore(download); | 499 delegate_->UpdateItemInPersistentStore(download); |
| 502 } | 500 } |
| 503 } | 501 } |
| 504 } | 502 } |
| 505 | 503 |
| 506 void DownloadManagerImpl::OnResponseCompleted(int32 download_id, | 504 void DownloadManagerImpl::OnResponseCompleted(int32 download_id, |
| 507 int64 size, | 505 int64 size, |
| 508 const std::string& hash) { | 506 const std::string& hash) { |
| 509 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 507 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 510 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id | 508 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 | 602 |
| 605 // Give the delegate a chance to override. | 603 // Give the delegate a chance to override. |
| 606 if (!delegate_->ShouldCompleteDownload(download)) | 604 if (!delegate_->ShouldCompleteDownload(download)) |
| 607 return; | 605 return; |
| 608 | 606 |
| 609 VLOG(20) << __FUNCTION__ << "()" << " executing: download = " | 607 VLOG(20) << __FUNCTION__ << "()" << " executing: download = " |
| 610 << download->DebugString(false); | 608 << download->DebugString(false); |
| 611 | 609 |
| 612 // Remove the id from in_progress | 610 // Remove the id from in_progress |
| 613 in_progress_.erase(download->GetId()); | 611 in_progress_.erase(download->GetId()); |
| 614 UpdateDownloadProgress(); // Reflect removal from in_progress_. | |
| 615 | 612 |
| 616 delegate_->UpdateItemInPersistentStore(download); | 613 delegate_->UpdateItemInPersistentStore(download); |
| 617 | 614 |
| 618 // Finish the download. | 615 // Finish the download. |
| 619 download->OnDownloadCompleting(file_manager_); | 616 download->OnDownloadCompleting(file_manager_); |
| 620 } | 617 } |
| 621 | 618 |
| 622 void DownloadManagerImpl::DownloadCompleted(DownloadItem* download) { | 619 void DownloadManagerImpl::DownloadCompleted(DownloadItem* download) { |
| 623 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 624 DCHECK(download); | 621 DCHECK(download); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 | 718 |
| 722 void DownloadManagerImpl::RemoveFromActiveList(DownloadItem* download) { | 719 void DownloadManagerImpl::RemoveFromActiveList(DownloadItem* download) { |
| 723 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 720 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 724 DCHECK(download); | 721 DCHECK(download); |
| 725 | 722 |
| 726 // Clean up will happen when the history system create callback runs if we | 723 // Clean up will happen when the history system create callback runs if we |
| 727 // don't have a valid db_handle yet. | 724 // don't have a valid db_handle yet. |
| 728 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) { | 725 if (download->GetDbHandle() != DownloadItem::kUninitializedHandle) { |
| 729 in_progress_.erase(download->GetId()); | 726 in_progress_.erase(download->GetId()); |
| 730 active_downloads_.erase(download->GetId()); | 727 active_downloads_.erase(download->GetId()); |
| 731 UpdateDownloadProgress(); // Reflect removal from in_progress_. | |
| 732 delegate_->UpdateItemInPersistentStore(download); | 728 delegate_->UpdateItemInPersistentStore(download); |
| 733 } | 729 } |
| 734 } | 730 } |
| 735 | 731 |
| 736 bool DownloadManagerImpl::GenerateFileHash() { | 732 bool DownloadManagerImpl::GenerateFileHash() { |
| 737 return delegate_->GenerateFileHash(); | 733 return delegate_->GenerateFileHash(); |
| 738 } | 734 } |
| 739 | 735 |
| 740 content::DownloadManagerDelegate* DownloadManagerImpl::delegate() const { | 736 content::DownloadManagerDelegate* DownloadManagerImpl::delegate() const { |
| 741 return delegate_; | 737 return delegate_; |
| 742 } | 738 } |
| 743 | 739 |
| 744 void DownloadManagerImpl::SetDownloadManagerDelegate( | 740 void DownloadManagerImpl::SetDownloadManagerDelegate( |
| 745 content::DownloadManagerDelegate* delegate) { | 741 content::DownloadManagerDelegate* delegate) { |
| 746 delegate_ = delegate; | 742 delegate_ = delegate; |
| 747 } | 743 } |
| 748 | 744 |
| 749 void DownloadManagerImpl::UpdateDownloadProgress() { | |
| 750 delegate_->DownloadProgressUpdated(); | |
| 751 } | |
| 752 | |
| 753 int DownloadManagerImpl::RemoveDownloadItems( | 745 int DownloadManagerImpl::RemoveDownloadItems( |
| 754 const DownloadVector& pending_deletes) { | 746 const DownloadVector& pending_deletes) { |
| 755 if (pending_deletes.empty()) | 747 if (pending_deletes.empty()) |
| 756 return 0; | 748 return 0; |
| 757 | 749 |
| 758 // Delete from internal maps. | 750 // Delete from internal maps. |
| 759 for (DownloadVector::const_iterator it = pending_deletes.begin(); | 751 for (DownloadVector::const_iterator it = pending_deletes.begin(); |
| 760 it != pending_deletes.end(); | 752 it != pending_deletes.end(); |
| 761 ++it) { | 753 ++it) { |
| 762 DownloadItem* download = *it; | 754 DownloadItem* download = *it; |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 it != history_downloads_.end(); ++it) { | 1158 it != history_downloads_.end(); ++it) { |
| 1167 if (it->second->IsComplete() && !it->second->GetOpened()) | 1159 if (it->second->IsComplete() && !it->second->GetOpened()) |
| 1168 ++num_unopened; | 1160 ++num_unopened; |
| 1169 } | 1161 } |
| 1170 download_stats::RecordOpensOutstanding(num_unopened); | 1162 download_stats::RecordOpensOutstanding(num_unopened); |
| 1171 } | 1163 } |
| 1172 | 1164 |
| 1173 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { | 1165 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { |
| 1174 file_manager_ = file_manager; | 1166 file_manager_ = file_manager; |
| 1175 } | 1167 } |
| OLD | NEW |