| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 downloads_.erase(download->GetId()); | 512 downloads_.erase(download->GetId()); |
| 513 } | 513 } |
| 514 | 514 |
| 515 void DownloadManagerImpl::AddUrlDownloader( | 515 void DownloadManagerImpl::AddUrlDownloader( |
| 516 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> | 516 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> |
| 517 downloader) { | 517 downloader) { |
| 518 if (downloader) | 518 if (downloader) |
| 519 url_downloaders_.push_back(std::move(downloader)); | 519 url_downloaders_.push_back(std::move(downloader)); |
| 520 } | 520 } |
| 521 | 521 |
| 522 void DownloadManagerImpl::RemoveUrlDownloader(UrlDownloader* downloader) { | |
| 523 for (auto ptr = url_downloaders_.begin(); ptr != url_downloaders_.end(); | |
| 524 ++ptr) { | |
| 525 if (ptr->get() == downloader) { | |
| 526 url_downloaders_.erase(ptr); | |
| 527 return; | |
| 528 } | |
| 529 } | |
| 530 } | |
| 531 | |
| 532 // static | 522 // static |
| 533 DownloadInterruptReason DownloadManagerImpl::BeginDownloadRequest( | 523 DownloadInterruptReason DownloadManagerImpl::BeginDownloadRequest( |
| 534 std::unique_ptr<net::URLRequest> url_request, | 524 std::unique_ptr<net::URLRequest> url_request, |
| 535 const Referrer& referrer, | 525 const Referrer& referrer, |
| 536 ResourceContext* resource_context, | 526 ResourceContext* resource_context, |
| 537 bool is_content_initiated, | 527 bool is_content_initiated, |
| 538 int render_process_id, | 528 int render_process_id, |
| 539 int render_view_route_id, | 529 int render_view_route_id, |
| 540 int render_frame_route_id, | 530 int render_frame_route_id, |
| 541 bool do_not_prompt_for_login) { | 531 bool do_not_prompt_for_login) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 ? downloads_[download_id].get() | 697 ? downloads_[download_id].get() |
| 708 : nullptr; | 698 : nullptr; |
| 709 } | 699 } |
| 710 | 700 |
| 711 DownloadItem* DownloadManagerImpl::GetDownloadByGuid(const std::string& guid) { | 701 DownloadItem* DownloadManagerImpl::GetDownloadByGuid(const std::string& guid) { |
| 712 DCHECK(guid == base::ToUpperASCII(guid)); | 702 DCHECK(guid == base::ToUpperASCII(guid)); |
| 713 return base::ContainsKey(downloads_by_guid_, guid) ? downloads_by_guid_[guid] | 703 return base::ContainsKey(downloads_by_guid_, guid) ? downloads_by_guid_[guid] |
| 714 : nullptr; | 704 : nullptr; |
| 715 } | 705 } |
| 716 | 706 |
| 707 void DownloadManagerImpl::OnUrlDownloaderStarted( |
| 708 std::unique_ptr<DownloadCreateInfo> download_create_info, |
| 709 std::unique_ptr<ByteStreamReader> stream_reader, |
| 710 const DownloadUrlParameters::OnStartedCallback& callback) { |
| 711 StartDownload(std::move(download_create_info), std::move(stream_reader), |
| 712 callback); |
| 713 } |
| 714 |
| 715 void DownloadManagerImpl::OnUrlDownloaderStopped(UrlDownloader* downloader) { |
| 716 for (auto ptr = url_downloaders_.begin(); ptr != url_downloaders_.end(); |
| 717 ++ptr) { |
| 718 if (ptr->get() == downloader) { |
| 719 url_downloaders_.erase(ptr); |
| 720 return; |
| 721 } |
| 722 } |
| 723 } |
| 724 |
| 717 void DownloadManagerImpl::GetAllDownloads(DownloadVector* downloads) { | 725 void DownloadManagerImpl::GetAllDownloads(DownloadVector* downloads) { |
| 718 for (const auto& it : downloads_) { | 726 for (const auto& it : downloads_) { |
| 719 downloads->push_back(it.second.get()); | 727 downloads->push_back(it.second.get()); |
| 720 } | 728 } |
| 721 } | 729 } |
| 722 | 730 |
| 723 void DownloadManagerImpl::OpenDownload(DownloadItemImpl* download) { | 731 void DownloadManagerImpl::OpenDownload(DownloadItemImpl* download) { |
| 724 int num_unopened = 0; | 732 int num_unopened = 0; |
| 725 for (const auto& it : downloads_) { | 733 for (const auto& it : downloads_) { |
| 726 DownloadItemImpl* item = it.second.get(); | 734 DownloadItemImpl* item = it.second.get(); |
| 727 if ((item->GetState() == DownloadItem::COMPLETE) && | 735 if ((item->GetState() == DownloadItem::COMPLETE) && |
| 728 !item->GetOpened()) | 736 !item->GetOpened()) |
| 729 ++num_unopened; | 737 ++num_unopened; |
| 730 } | 738 } |
| 731 RecordOpensOutstanding(num_unopened); | 739 RecordOpensOutstanding(num_unopened); |
| 732 | 740 |
| 733 if (delegate_) | 741 if (delegate_) |
| 734 delegate_->OpenDownload(download); | 742 delegate_->OpenDownload(download); |
| 735 } | 743 } |
| 736 | 744 |
| 737 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { | 745 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
| 738 if (delegate_) | 746 if (delegate_) |
| 739 delegate_->ShowDownloadInShell(download); | 747 delegate_->ShowDownloadInShell(download); |
| 740 } | 748 } |
| 741 | 749 |
| 742 } // namespace content | 750 } // namespace content |
| OLD | NEW |