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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "content/public/browser/notification_types.h" | 37 #include "content/public/browser/notification_types.h" |
38 #include "content/public/browser/render_process_host.h" | 38 #include "content/public/browser/render_process_host.h" |
39 #include "content/public/browser/resource_context.h" | 39 #include "content/public/browser/resource_context.h" |
40 #include "content/public/browser/web_contents_delegate.h" | 40 #include "content/public/browser/web_contents_delegate.h" |
41 #include "content/public/common/referrer.h" | 41 #include "content/public/common/referrer.h" |
42 #include "net/base/elements_upload_data_stream.h" | 42 #include "net/base/elements_upload_data_stream.h" |
43 #include "net/base/load_flags.h" | 43 #include "net/base/load_flags.h" |
44 #include "net/base/request_priority.h" | 44 #include "net/base/request_priority.h" |
45 #include "net/base/upload_bytes_element_reader.h" | 45 #include "net/base/upload_bytes_element_reader.h" |
46 #include "net/url_request/url_request_context.h" | 46 #include "net/url_request/url_request_context.h" |
| 47 #include "url/origin.h" |
47 | 48 |
48 namespace content { | 49 namespace content { |
49 namespace { | 50 namespace { |
50 | 51 |
51 void BeginDownload(scoped_ptr<DownloadUrlParameters> params, | 52 void BeginDownload(scoped_ptr<DownloadUrlParameters> params, |
52 uint32 download_id) { | 53 uint32 download_id) { |
53 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 54 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
54 // ResourceDispatcherHost{Base} is-not-a URLRequest::Delegate, and | 55 // ResourceDispatcherHost{Base} is-not-a URLRequest::Delegate, and |
55 // DownloadUrlParameters can-not include resource_dispatcher_host_impl.h, so | 56 // DownloadUrlParameters can-not include resource_dispatcher_host_impl.h, so |
56 // we must down cast. RDHI is the only subclass of RDH as of 2012 May 4. | 57 // we must down cast. RDHI is the only subclass of RDH as of 2012 May 4. |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) { | 559 void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) { |
559 if (!download) | 560 if (!download) |
560 return; | 561 return; |
561 | 562 |
562 uint32 download_id = download->GetId(); | 563 uint32 download_id = download->GetId(); |
563 if (downloads_.erase(download_id) == 0) | 564 if (downloads_.erase(download_id) == 0) |
564 return; | 565 return; |
565 delete download; | 566 delete download; |
566 } | 567 } |
567 | 568 |
568 int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin, | 569 namespace { |
569 base::Time remove_end) { | 570 |
| 571 bool RemoveDownloadBetween(base::Time remove_begin, |
| 572 base::Time remove_end, |
| 573 const DownloadItemImpl* download_item) { |
| 574 return download_item->GetStartTime() >= remove_begin && |
| 575 (remove_end.is_null() || download_item->GetStartTime() < remove_end); |
| 576 } |
| 577 |
| 578 bool RemoveDownloadByOriginAndTime(const url::Origin& origin, |
| 579 base::Time remove_begin, |
| 580 base::Time remove_end, |
| 581 const DownloadItemImpl* download_item) { |
| 582 return origin.IsSameOriginWith(url::Origin(download_item->GetURL())) && |
| 583 RemoveDownloadBetween(remove_begin, remove_end, download_item); |
| 584 } |
| 585 |
| 586 } // namespace |
| 587 |
| 588 int DownloadManagerImpl::RemoveDownloads(const DownloadRemover& remover) { |
570 int count = 0; | 589 int count = 0; |
571 DownloadMap::const_iterator it = downloads_.begin(); | 590 DownloadMap::const_iterator it = downloads_.begin(); |
572 while (it != downloads_.end()) { | 591 while (it != downloads_.end()) { |
573 DownloadItemImpl* download = it->second; | 592 DownloadItemImpl* download = it->second; |
574 | 593 |
575 // Increment done here to protect against invalidation below. | 594 // Increment done here to protect against invalidation below. |
576 ++it; | 595 ++it; |
577 | 596 |
578 if (download->GetStartTime() >= remove_begin && | 597 if (download->GetState() != DownloadItem::IN_PROGRESS && |
579 (remove_end.is_null() || download->GetStartTime() < remove_end) && | 598 remover.Run(download)) { |
580 (download->GetState() != DownloadItem::IN_PROGRESS)) { | |
581 // Erases the download from downloads_. | |
582 download->Remove(); | 599 download->Remove(); |
583 count++; | 600 count++; |
584 } | 601 } |
585 } | 602 } |
586 return count; | 603 return count; |
587 } | 604 } |
588 | 605 |
| 606 int DownloadManagerImpl::RemoveDownloadsByOriginAndTime( |
| 607 const url::Origin& origin, |
| 608 base::Time remove_begin, |
| 609 base::Time remove_end) { |
| 610 return RemoveDownloads(base::Bind(&RemoveDownloadByOriginAndTime, |
| 611 base::ConstRef(origin), remove_begin, |
| 612 remove_end)); |
| 613 } |
| 614 |
| 615 int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin, |
| 616 base::Time remove_end) { |
| 617 return RemoveDownloads( |
| 618 base::Bind(&RemoveDownloadBetween, remove_begin, remove_end)); |
| 619 } |
| 620 |
589 int DownloadManagerImpl::RemoveDownloads(base::Time remove_begin) { | 621 int DownloadManagerImpl::RemoveDownloads(base::Time remove_begin) { |
590 return RemoveDownloadsBetween(remove_begin, base::Time()); | 622 return RemoveDownloadsBetween(remove_begin, base::Time()); |
591 } | 623 } |
592 | 624 |
593 int DownloadManagerImpl::RemoveAllDownloads() { | 625 int DownloadManagerImpl::RemoveAllDownloads() { |
594 // The null times make the date range unbounded. | 626 // The null times make the date range unbounded. |
595 int num_deleted = RemoveDownloadsBetween(base::Time(), base::Time()); | 627 int num_deleted = RemoveDownloadsBetween(base::Time(), base::Time()); |
596 RecordClearAllSize(num_deleted); | 628 RecordClearAllSize(num_deleted); |
597 return num_deleted; | 629 return num_deleted; |
598 } | 630 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 if (delegate_) | 748 if (delegate_) |
717 delegate_->OpenDownload(download); | 749 delegate_->OpenDownload(download); |
718 } | 750 } |
719 | 751 |
720 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { | 752 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
721 if (delegate_) | 753 if (delegate_) |
722 delegate_->ShowDownloadInShell(download); | 754 delegate_->ShowDownloadInShell(download); |
723 } | 755 } |
724 | 756 |
725 } // namespace content | 757 } // namespace content |
OLD | NEW |