| 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 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 // Find a better way to create the DownloadResourceHandler instance. | 581 // Find a better way to create the DownloadResourceHandler instance. |
| 582 std::unique_ptr<ResourceHandler> handler( | 582 std::unique_ptr<ResourceHandler> handler( |
| 583 DownloadResourceHandler::Create(url_request.get())); | 583 DownloadResourceHandler::Create(url_request.get())); |
| 584 | 584 |
| 585 ResourceDispatcherHostImpl::Get()->BeginURLRequest( | 585 ResourceDispatcherHostImpl::Get()->BeginURLRequest( |
| 586 std::move(url_request), std::move(handler), true, // download | 586 std::move(url_request), std::move(handler), true, // download |
| 587 is_content_initiated, do_not_prompt_for_login, resource_context); | 587 is_content_initiated, do_not_prompt_for_login, resource_context); |
| 588 return DOWNLOAD_INTERRUPT_REASON_NONE; | 588 return DOWNLOAD_INTERRUPT_REASON_NONE; |
| 589 } | 589 } |
| 590 | 590 |
| 591 namespace { | 591 int DownloadManagerImpl::RemoveDownloadsByURLAndTime( |
| 592 | |
| 593 bool EmptyFilter(const GURL& url) { | |
| 594 return true; | |
| 595 } | |
| 596 | |
| 597 bool RemoveDownloadByURLAndTime( | |
| 598 const base::Callback<bool(const GURL&)>& url_filter, | 592 const base::Callback<bool(const GURL&)>& url_filter, |
| 599 base::Time remove_begin, | 593 base::Time remove_begin, |
| 600 base::Time remove_end, | 594 base::Time remove_end) { |
| 601 const DownloadItemImpl* download_item) { | |
| 602 return url_filter.Run(download_item->GetURL()) && | |
| 603 download_item->GetStartTime() >= remove_begin && | |
| 604 (remove_end.is_null() || download_item->GetStartTime() < remove_end); | |
| 605 } | |
| 606 | |
| 607 } // namespace | |
| 608 | |
| 609 int DownloadManagerImpl::RemoveDownloads(const DownloadRemover& remover) { | |
| 610 int count = 0; | 595 int count = 0; |
| 611 auto it = downloads_.begin(); | 596 auto it = downloads_.begin(); |
| 612 while (it != downloads_.end()) { | 597 while (it != downloads_.end()) { |
| 613 DownloadItemImpl* download = it->second.get(); | 598 DownloadItemImpl* download = it->second.get(); |
| 614 | 599 |
| 615 // Increment done here to protect against invalidation below. | 600 // Increment done here to protect against invalidation below. |
| 616 ++it; | 601 ++it; |
| 617 | 602 |
| 618 if (download->GetState() != DownloadItem::IN_PROGRESS && | 603 if (download->GetState() != DownloadItem::IN_PROGRESS && |
| 619 remover.Run(download)) { | 604 url_filter.Run(download->GetURL()) && |
| 605 download->GetStartTime() >= remove_begin && |
| 606 (remove_end.is_null() || download->GetStartTime() < remove_end)) { |
| 620 download->Remove(); | 607 download->Remove(); |
| 621 count++; | 608 count++; |
| 622 } | 609 } |
| 623 } | 610 } |
| 624 return count; | 611 return count; |
| 625 } | 612 } |
| 626 | 613 |
| 627 int DownloadManagerImpl::RemoveDownloadsByURLAndTime( | |
| 628 const base::Callback<bool(const GURL&)>& url_filter, | |
| 629 base::Time remove_begin, | |
| 630 base::Time remove_end) { | |
| 631 return RemoveDownloads(base::Bind(&RemoveDownloadByURLAndTime, | |
| 632 url_filter, | |
| 633 remove_begin, remove_end)); | |
| 634 } | |
| 635 | |
| 636 int DownloadManagerImpl::RemoveAllDownloads() { | |
| 637 const base::Callback<bool(const GURL&)> empty_filter = | |
| 638 base::Bind(&EmptyFilter); | |
| 639 // The null times make the date range unbounded. | |
| 640 int num_deleted = RemoveDownloadsByURLAndTime( | |
| 641 empty_filter, base::Time(), base::Time()); | |
| 642 RecordClearAllSize(num_deleted); | |
| 643 return num_deleted; | |
| 644 } | |
| 645 | |
| 646 void DownloadManagerImpl::DownloadUrl( | 614 void DownloadManagerImpl::DownloadUrl( |
| 647 std::unique_ptr<DownloadUrlParameters> params) { | 615 std::unique_ptr<DownloadUrlParameters> params) { |
| 648 if (params->post_id() >= 0) { | 616 if (params->post_id() >= 0) { |
| 649 // Check this here so that the traceback is more useful. | 617 // Check this here so that the traceback is more useful. |
| 650 DCHECK(params->prefer_cache()); | 618 DCHECK(params->prefer_cache()); |
| 651 DCHECK_EQ("POST", params->method()); | 619 DCHECK_EQ("POST", params->method()); |
| 652 } | 620 } |
| 653 BrowserThread::PostTaskAndReplyWithResult( | 621 BrowserThread::PostTaskAndReplyWithResult( |
| 654 BrowserThread::IO, FROM_HERE, | 622 BrowserThread::IO, FROM_HERE, |
| 655 base::Bind(&BeginDownload, base::Passed(¶ms), | 623 base::Bind(&BeginDownload, base::Passed(¶ms), |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 if (delegate_) | 732 if (delegate_) |
| 765 delegate_->OpenDownload(download); | 733 delegate_->OpenDownload(download); |
| 766 } | 734 } |
| 767 | 735 |
| 768 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { | 736 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
| 769 if (delegate_) | 737 if (delegate_) |
| 770 delegate_->ShowDownloadInShell(download); | 738 delegate_->ShowDownloadInShell(download); |
| 771 } | 739 } |
| 772 | 740 |
| 773 } // namespace content | 741 } // namespace content |
| OLD | NEW |