Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(706)

Side by Side Diff: content/browser/download/download_manager_impl.cc

Issue 2689373003: Introduce ParallelDownloadJob. (Closed)
Patch Set: nits. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 downloads_.erase(download->GetId()); 513 downloads_.erase(download->GetId());
514 } 514 }
515 515
516 void DownloadManagerImpl::AddUrlDownloader( 516 void DownloadManagerImpl::AddUrlDownloader(
517 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> 517 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>
518 downloader) { 518 downloader) {
519 if (downloader) 519 if (downloader)
520 url_downloaders_.push_back(std::move(downloader)); 520 url_downloaders_.push_back(std::move(downloader));
521 } 521 }
522 522
523 void DownloadManagerImpl::RemoveUrlDownloader(UrlDownloader* downloader) {
524 for (auto ptr = url_downloaders_.begin(); ptr != url_downloaders_.end();
525 ++ptr) {
526 if (ptr->get() == downloader) {
527 url_downloaders_.erase(ptr);
528 return;
529 }
530 }
531 }
532
533 // static 523 // static
534 DownloadInterruptReason DownloadManagerImpl::BeginDownloadRequest( 524 DownloadInterruptReason DownloadManagerImpl::BeginDownloadRequest(
535 std::unique_ptr<net::URLRequest> url_request, 525 std::unique_ptr<net::URLRequest> url_request,
536 const Referrer& referrer, 526 const Referrer& referrer,
537 ResourceContext* resource_context, 527 ResourceContext* resource_context,
538 bool is_content_initiated, 528 bool is_content_initiated,
539 int render_process_id, 529 int render_process_id,
540 int render_view_route_id, 530 int render_view_route_id,
541 int render_frame_route_id, 531 int render_frame_route_id,
542 bool do_not_prompt_for_login) { 532 bool do_not_prompt_for_login) {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 ? downloads_[download_id].get() 699 ? downloads_[download_id].get()
710 : nullptr; 700 : nullptr;
711 } 701 }
712 702
713 DownloadItem* DownloadManagerImpl::GetDownloadByGuid(const std::string& guid) { 703 DownloadItem* DownloadManagerImpl::GetDownloadByGuid(const std::string& guid) {
714 DCHECK(guid == base::ToUpperASCII(guid)); 704 DCHECK(guid == base::ToUpperASCII(guid));
715 return base::ContainsKey(downloads_by_guid_, guid) ? downloads_by_guid_[guid] 705 return base::ContainsKey(downloads_by_guid_, guid) ? downloads_by_guid_[guid]
716 : nullptr; 706 : nullptr;
717 } 707 }
718 708
709 void DownloadManagerImpl::OnUrlDownloaderStarted(
710 std::unique_ptr<DownloadCreateInfo> download_create_info,
711 std::unique_ptr<ByteStreamReader> stream_reader,
712 const DownloadUrlParameters::OnStartedCallback& callback) {
713 StartDownload(std::move(download_create_info), std::move(stream_reader),
714 callback);
715 }
716
717 void DownloadManagerImpl::OnUrlDownloaderStopped(UrlDownloader* downloader) {
718 for (auto ptr = url_downloaders_.begin(); ptr != url_downloaders_.end();
719 ++ptr) {
720 if (ptr->get() == downloader) {
721 url_downloaders_.erase(ptr);
722 return;
723 }
724 }
725 }
726
719 void DownloadManagerImpl::GetAllDownloads(DownloadVector* downloads) { 727 void DownloadManagerImpl::GetAllDownloads(DownloadVector* downloads) {
720 for (const auto& it : downloads_) { 728 for (const auto& it : downloads_) {
721 downloads->push_back(it.second.get()); 729 downloads->push_back(it.second.get());
722 } 730 }
723 } 731 }
724 732
725 void DownloadManagerImpl::OpenDownload(DownloadItemImpl* download) { 733 void DownloadManagerImpl::OpenDownload(DownloadItemImpl* download) {
726 int num_unopened = 0; 734 int num_unopened = 0;
727 for (const auto& it : downloads_) { 735 for (const auto& it : downloads_) {
728 DownloadItemImpl* item = it.second.get(); 736 DownloadItemImpl* item = it.second.get();
729 if ((item->GetState() == DownloadItem::COMPLETE) && 737 if ((item->GetState() == DownloadItem::COMPLETE) &&
730 !item->GetOpened()) 738 !item->GetOpened())
731 ++num_unopened; 739 ++num_unopened;
732 } 740 }
733 RecordOpensOutstanding(num_unopened); 741 RecordOpensOutstanding(num_unopened);
734 742
735 if (delegate_) 743 if (delegate_)
736 delegate_->OpenDownload(download); 744 delegate_->OpenDownload(download);
737 } 745 }
738 746
739 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { 747 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) {
740 if (delegate_) 748 if (delegate_)
741 delegate_->ShowDownloadInShell(download); 749 delegate_->ShowDownloadInShell(download);
742 } 750 }
743 751
744 } // namespace content 752 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_manager_impl.h ('k') | content/browser/download/download_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698