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