| 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 ++ptr) { | 512 ++ptr) { |
| 513 if (ptr->get() == downloader) { | 513 if (ptr->get() == downloader) { |
| 514 url_downloaders_.erase(ptr); | 514 url_downloaders_.erase(ptr); |
| 515 return; | 515 return; |
| 516 } | 516 } |
| 517 } | 517 } |
| 518 } | 518 } |
| 519 | 519 |
| 520 namespace { | 520 namespace { |
| 521 | 521 |
| 522 bool RemoveDownloadBetween(base::Time remove_begin, | 522 bool EmptyFilter(const GURL& url) { |
| 523 base::Time remove_end, | 523 return true; |
| 524 const DownloadItemImpl* download_item) { | 524 } |
| 525 return download_item->GetStartTime() >= remove_begin && | 525 |
| 526 bool RemoveDownloadByURLAndTime( |
| 527 const base::Callback<bool(const GURL&)>& url_filter, |
| 528 base::Time remove_begin, |
| 529 base::Time remove_end, |
| 530 const DownloadItemImpl* download_item) { |
| 531 return url_filter.Run(download_item->GetURL()) && |
| 532 download_item->GetStartTime() >= remove_begin && |
| 526 (remove_end.is_null() || download_item->GetStartTime() < remove_end); | 533 (remove_end.is_null() || download_item->GetStartTime() < remove_end); |
| 527 } | 534 } |
| 528 | 535 |
| 529 bool RemoveDownloadByOriginAndTime(const url::Origin& origin, | |
| 530 base::Time remove_begin, | |
| 531 base::Time remove_end, | |
| 532 const DownloadItemImpl* download_item) { | |
| 533 return origin.IsSameOriginWith(url::Origin(download_item->GetURL())) && | |
| 534 RemoveDownloadBetween(remove_begin, remove_end, download_item); | |
| 535 } | |
| 536 | |
| 537 } // namespace | 536 } // namespace |
| 538 | 537 |
| 539 int DownloadManagerImpl::RemoveDownloads(const DownloadRemover& remover) { | 538 int DownloadManagerImpl::RemoveDownloads(const DownloadRemover& remover) { |
| 540 int count = 0; | 539 int count = 0; |
| 541 DownloadMap::const_iterator it = downloads_.begin(); | 540 DownloadMap::const_iterator it = downloads_.begin(); |
| 542 while (it != downloads_.end()) { | 541 while (it != downloads_.end()) { |
| 543 DownloadItemImpl* download = it->second; | 542 DownloadItemImpl* download = it->second; |
| 544 | 543 |
| 545 // Increment done here to protect against invalidation below. | 544 // Increment done here to protect against invalidation below. |
| 546 ++it; | 545 ++it; |
| 547 | 546 |
| 548 if (download->GetState() != DownloadItem::IN_PROGRESS && | 547 if (download->GetState() != DownloadItem::IN_PROGRESS && |
| 549 remover.Run(download)) { | 548 remover.Run(download)) { |
| 550 download->Remove(); | 549 download->Remove(); |
| 551 count++; | 550 count++; |
| 552 } | 551 } |
| 553 } | 552 } |
| 554 return count; | 553 return count; |
| 555 } | 554 } |
| 556 | 555 |
| 557 int DownloadManagerImpl::RemoveDownloadsByOriginAndTime( | 556 int DownloadManagerImpl::RemoveDownloadsByURLAndTime( |
| 558 const url::Origin& origin, | 557 const base::Callback<bool(const GURL&)>& url_filter, |
| 559 base::Time remove_begin, | 558 base::Time remove_begin, |
| 560 base::Time remove_end) { | 559 base::Time remove_end) { |
| 561 return RemoveDownloads(base::Bind(&RemoveDownloadByOriginAndTime, | 560 return RemoveDownloads(base::Bind(&RemoveDownloadByURLAndTime, |
| 562 base::ConstRef(origin), remove_begin, | 561 url_filter, |
| 563 remove_end)); | 562 remove_begin, remove_end)); |
| 564 } | |
| 565 | |
| 566 int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin, | |
| 567 base::Time remove_end) { | |
| 568 return RemoveDownloads( | |
| 569 base::Bind(&RemoveDownloadBetween, remove_begin, remove_end)); | |
| 570 } | 563 } |
| 571 | 564 |
| 572 int DownloadManagerImpl::RemoveAllDownloads() { | 565 int DownloadManagerImpl::RemoveAllDownloads() { |
| 566 const base::Callback<bool(const GURL&)> empty_filter = |
| 567 base::Bind(&EmptyFilter); |
| 573 // The null times make the date range unbounded. | 568 // The null times make the date range unbounded. |
| 574 int num_deleted = RemoveDownloadsBetween(base::Time(), base::Time()); | 569 int num_deleted = RemoveDownloadsByURLAndTime( |
| 570 empty_filter, base::Time(), base::Time()); |
| 575 RecordClearAllSize(num_deleted); | 571 RecordClearAllSize(num_deleted); |
| 576 return num_deleted; | 572 return num_deleted; |
| 577 } | 573 } |
| 578 | 574 |
| 579 void DownloadManagerImpl::DownloadUrl( | 575 void DownloadManagerImpl::DownloadUrl( |
| 580 scoped_ptr<DownloadUrlParameters> params) { | 576 scoped_ptr<DownloadUrlParameters> params) { |
| 581 if (params->post_id() >= 0) { | 577 if (params->post_id() >= 0) { |
| 582 // Check this here so that the traceback is more useful. | 578 // Check this here so that the traceback is more useful. |
| 583 DCHECK(params->prefer_cache()); | 579 DCHECK(params->prefer_cache()); |
| 584 DCHECK_EQ("POST", params->method()); | 580 DCHECK_EQ("POST", params->method()); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 if (delegate_) | 690 if (delegate_) |
| 695 delegate_->OpenDownload(download); | 691 delegate_->OpenDownload(download); |
| 696 } | 692 } |
| 697 | 693 |
| 698 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { | 694 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
| 699 if (delegate_) | 695 if (delegate_) |
| 700 delegate_->ShowDownloadInShell(download); | 696 delegate_->ShowDownloadInShell(download); |
| 701 } | 697 } |
| 702 | 698 |
| 703 } // namespace content | 699 } // namespace content |
| OLD | NEW |