| 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 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 ++ptr) { | 549 ++ptr) { |
| 550 if (ptr->get() == downloader) { | 550 if (ptr->get() == downloader) { |
| 551 url_downloaders_.erase(ptr); | 551 url_downloaders_.erase(ptr); |
| 552 return; | 552 return; |
| 553 } | 553 } |
| 554 } | 554 } |
| 555 } | 555 } |
| 556 | 556 |
| 557 namespace { | 557 namespace { |
| 558 | 558 |
| 559 bool RemoveDownloadBetween(base::Time remove_begin, | 559 bool EmptyFilter(const GURL& url) { |
| 560 base::Time remove_end, | 560 return true; |
| 561 const DownloadItemImpl* download_item) { | 561 } |
| 562 return download_item->GetStartTime() >= remove_begin && | 562 |
| 563 bool RemoveDownloadByURLAndTime( |
| 564 const base::Callback<bool(const GURL&)>& url_filter, |
| 565 base::Time remove_begin, |
| 566 base::Time remove_end, |
| 567 const DownloadItemImpl* download_item) { |
| 568 return url_filter.Run(download_item->GetURL()) && |
| 569 download_item->GetStartTime() >= remove_begin && |
| 563 (remove_end.is_null() || download_item->GetStartTime() < remove_end); | 570 (remove_end.is_null() || download_item->GetStartTime() < remove_end); |
| 564 } | 571 } |
| 565 | 572 |
| 566 bool RemoveDownloadByOriginAndTime(const url::Origin& origin, | |
| 567 base::Time remove_begin, | |
| 568 base::Time remove_end, | |
| 569 const DownloadItemImpl* download_item) { | |
| 570 return origin.IsSameOriginWith(url::Origin(download_item->GetURL())) && | |
| 571 RemoveDownloadBetween(remove_begin, remove_end, download_item); | |
| 572 } | |
| 573 | |
| 574 } // namespace | 573 } // namespace |
| 575 | 574 |
| 576 int DownloadManagerImpl::RemoveDownloads(const DownloadRemover& remover) { | 575 int DownloadManagerImpl::RemoveDownloads(const DownloadRemover& remover) { |
| 577 int count = 0; | 576 int count = 0; |
| 578 DownloadMap::const_iterator it = downloads_.begin(); | 577 DownloadMap::const_iterator it = downloads_.begin(); |
| 579 while (it != downloads_.end()) { | 578 while (it != downloads_.end()) { |
| 580 DownloadItemImpl* download = it->second; | 579 DownloadItemImpl* download = it->second; |
| 581 | 580 |
| 582 // Increment done here to protect against invalidation below. | 581 // Increment done here to protect against invalidation below. |
| 583 ++it; | 582 ++it; |
| 584 | 583 |
| 585 if (download->GetState() != DownloadItem::IN_PROGRESS && | 584 if (download->GetState() != DownloadItem::IN_PROGRESS && |
| 586 remover.Run(download)) { | 585 remover.Run(download)) { |
| 587 download->Remove(); | 586 download->Remove(); |
| 588 count++; | 587 count++; |
| 589 } | 588 } |
| 590 } | 589 } |
| 591 return count; | 590 return count; |
| 592 } | 591 } |
| 593 | 592 |
| 594 int DownloadManagerImpl::RemoveDownloadsByOriginAndTime( | 593 int DownloadManagerImpl::RemoveDownloadsByURLAndTime( |
| 595 const url::Origin& origin, | 594 const base::Callback<bool(const GURL&)>& url_filter, |
| 596 base::Time remove_begin, | 595 base::Time remove_begin, |
| 597 base::Time remove_end) { | 596 base::Time remove_end) { |
| 598 return RemoveDownloads(base::Bind(&RemoveDownloadByOriginAndTime, | 597 return RemoveDownloads(base::Bind(&RemoveDownloadByURLAndTime, |
| 599 base::ConstRef(origin), remove_begin, | 598 url_filter, |
| 600 remove_end)); | 599 remove_begin, remove_end)); |
| 601 } | |
| 602 | |
| 603 int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin, | |
| 604 base::Time remove_end) { | |
| 605 return RemoveDownloads( | |
| 606 base::Bind(&RemoveDownloadBetween, remove_begin, remove_end)); | |
| 607 } | 600 } |
| 608 | 601 |
| 609 int DownloadManagerImpl::RemoveDownloads(base::Time remove_begin) { | 602 int DownloadManagerImpl::RemoveDownloads(base::Time remove_begin) { |
| 610 return RemoveDownloadsBetween(remove_begin, base::Time()); | 603 const base::Callback<bool(const GURL&)> empty_filter = |
| 604 base::Bind(&EmptyFilter); |
| 605 return RemoveDownloadsByURLAndTime( |
| 606 empty_filter, remove_begin, base::Time()); |
| 611 } | 607 } |
| 612 | 608 |
| 613 int DownloadManagerImpl::RemoveAllDownloads() { | 609 int DownloadManagerImpl::RemoveAllDownloads() { |
| 610 const base::Callback<bool(const GURL&)> empty_filter = |
| 611 base::Bind(&EmptyFilter); |
| 614 // The null times make the date range unbounded. | 612 // The null times make the date range unbounded. |
| 615 int num_deleted = RemoveDownloadsBetween(base::Time(), base::Time()); | 613 int num_deleted = RemoveDownloadsByURLAndTime( |
| 614 empty_filter, base::Time(), base::Time()); |
| 616 RecordClearAllSize(num_deleted); | 615 RecordClearAllSize(num_deleted); |
| 617 return num_deleted; | 616 return num_deleted; |
| 618 } | 617 } |
| 619 | 618 |
| 620 void DownloadManagerImpl::DownloadUrl( | 619 void DownloadManagerImpl::DownloadUrl( |
| 621 scoped_ptr<DownloadUrlParameters> params) { | 620 scoped_ptr<DownloadUrlParameters> params) { |
| 622 if (params->post_id() >= 0) { | 621 if (params->post_id() >= 0) { |
| 623 // Check this here so that the traceback is more useful. | 622 // Check this here so that the traceback is more useful. |
| 624 DCHECK(params->prefer_cache()); | 623 DCHECK(params->prefer_cache()); |
| 625 DCHECK_EQ("POST", params->method()); | 624 DCHECK_EQ("POST", params->method()); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 if (delegate_) | 738 if (delegate_) |
| 740 delegate_->OpenDownload(download); | 739 delegate_->OpenDownload(download); |
| 741 } | 740 } |
| 742 | 741 |
| 743 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { | 742 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
| 744 if (delegate_) | 743 if (delegate_) |
| 745 delegate_->ShowDownloadInShell(download); | 744 delegate_->ShowDownloadInShell(download); |
| 746 } | 745 } |
| 747 | 746 |
| 748 } // namespace content | 747 } // namespace content |
| OLD | NEW |