| 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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 | 467 |
| 468 void DownloadManagerImpl::OnFileExistenceChecked(uint32 download_id, | 468 void DownloadManagerImpl::OnFileExistenceChecked(uint32 download_id, |
| 469 bool result) { | 469 bool result) { |
| 470 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 470 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 471 if (!result) { // File does not exist. | 471 if (!result) { // File does not exist. |
| 472 if (ContainsKey(downloads_, download_id)) | 472 if (ContainsKey(downloads_, download_id)) |
| 473 downloads_[download_id]->OnDownloadedFileRemoved(); | 473 downloads_[download_id]->OnDownloadedFileRemoved(); |
| 474 } | 474 } |
| 475 } | 475 } |
| 476 | 476 |
| 477 bool DownloadManagerImpl::IsRestrictedUrl( |
| 478 const GURL& url, const std::set<GURL>& restricted_urls) { |
| 479 DCHECK(!restricted_urls.empty()); |
| 480 |
| 481 return restricted_urls.find(url.GetOrigin()) != restricted_urls.end(); |
| 482 } |
| 483 |
| 477 BrowserContext* DownloadManagerImpl::GetBrowserContext() const { | 484 BrowserContext* DownloadManagerImpl::GetBrowserContext() const { |
| 478 return browser_context_; | 485 return browser_context_; |
| 479 } | 486 } |
| 480 | 487 |
| 481 void DownloadManagerImpl::CreateSavePackageDownloadItem( | 488 void DownloadManagerImpl::CreateSavePackageDownloadItem( |
| 482 const base::FilePath& main_file_path, | 489 const base::FilePath& main_file_path, |
| 483 const GURL& page_url, | 490 const GURL& page_url, |
| 484 const std::string& mime_type, | 491 const std::string& mime_type, |
| 485 scoped_ptr<DownloadRequestHandleInterface> request_handle, | 492 scoped_ptr<DownloadRequestHandleInterface> request_handle, |
| 486 const DownloadItemImplCreated& item_created) { | 493 const DownloadItemImplCreated& item_created) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) { | 565 void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) { |
| 559 if (!download) | 566 if (!download) |
| 560 return; | 567 return; |
| 561 | 568 |
| 562 uint32 download_id = download->GetId(); | 569 uint32 download_id = download->GetId(); |
| 563 if (downloads_.erase(download_id) == 0) | 570 if (downloads_.erase(download_id) == 0) |
| 564 return; | 571 return; |
| 565 delete download; | 572 delete download; |
| 566 } | 573 } |
| 567 | 574 |
| 568 int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin, | 575 int DownloadManagerImpl::RemoveDownloadsBetween( |
| 569 base::Time remove_end) { | 576 const std::set<GURL>& restricted_urls, |
| 577 base::Time remove_begin, |
| 578 base::Time remove_end) { |
| 570 int count = 0; | 579 int count = 0; |
| 571 DownloadMap::const_iterator it = downloads_.begin(); | 580 DownloadMap::const_iterator it = downloads_.begin(); |
| 572 while (it != downloads_.end()) { | 581 while (it != downloads_.end()) { |
| 573 DownloadItemImpl* download = it->second; | 582 DownloadItemImpl* download = it->second; |
| 574 | 583 |
| 575 // Increment done here to protect against invalidation below. | 584 // Increment done here to protect against invalidation below. |
| 576 ++it; | 585 ++it; |
| 577 | 586 |
| 578 if (download->GetStartTime() >= remove_begin && | 587 if ((restricted_urls.empty() || IsRestrictedUrl(download->GetURL(), |
| 588 restricted_urls)) && |
| 589 download->GetStartTime() >= remove_begin && |
| 579 (remove_end.is_null() || download->GetStartTime() < remove_end) && | 590 (remove_end.is_null() || download->GetStartTime() < remove_end) && |
| 580 (download->GetState() != DownloadItem::IN_PROGRESS)) { | 591 (download->GetState() != DownloadItem::IN_PROGRESS)) { |
| 581 // Erases the download from downloads_. | 592 // Erases the download from downloads_. |
| 582 download->Remove(); | 593 download->Remove(); |
| 583 count++; | 594 count++; |
| 584 } | 595 } |
| 585 } | 596 } |
| 586 return count; | 597 return count; |
| 587 } | 598 } |
| 588 | 599 |
| 589 int DownloadManagerImpl::RemoveDownloads(base::Time remove_begin) { | 600 int DownloadManagerImpl::RemoveDownloads(base::Time remove_begin) { |
| 590 return RemoveDownloadsBetween(remove_begin, base::Time()); | 601 return RemoveDownloadsBetween(std::set<GURL>(), remove_begin, base::Time()); |
| 591 } | 602 } |
| 592 | 603 |
| 593 int DownloadManagerImpl::RemoveAllDownloads() { | 604 int DownloadManagerImpl::RemoveAllDownloads() { |
| 594 // The null times make the date range unbounded. | 605 // The null times make the date range unbounded. |
| 595 int num_deleted = RemoveDownloadsBetween(base::Time(), base::Time()); | 606 int num_deleted = RemoveDownloadsBetween( |
| 607 std::set<GURL>(), base::Time(), base::Time()); |
| 596 RecordClearAllSize(num_deleted); | 608 RecordClearAllSize(num_deleted); |
| 597 return num_deleted; | 609 return num_deleted; |
| 598 } | 610 } |
| 599 | 611 |
| 600 void DownloadManagerImpl::DownloadUrl( | 612 void DownloadManagerImpl::DownloadUrl( |
| 601 scoped_ptr<DownloadUrlParameters> params) { | 613 scoped_ptr<DownloadUrlParameters> params) { |
| 602 if (params->post_id() >= 0) { | 614 if (params->post_id() >= 0) { |
| 603 // Check this here so that the traceback is more useful. | 615 // Check this here so that the traceback is more useful. |
| 604 DCHECK(params->prefer_cache()); | 616 DCHECK(params->prefer_cache()); |
| 605 DCHECK_EQ("POST", params->method()); | 617 DCHECK_EQ("POST", params->method()); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 if (delegate_) | 728 if (delegate_) |
| 717 delegate_->OpenDownload(download); | 729 delegate_->OpenDownload(download); |
| 718 } | 730 } |
| 719 | 731 |
| 720 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { | 732 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
| 721 if (delegate_) | 733 if (delegate_) |
| 722 delegate_->ShowDownloadInShell(download); | 734 delegate_->ShowDownloadInShell(download); |
| 723 } | 735 } |
| 724 | 736 |
| 725 } // namespace content | 737 } // namespace content |
| OLD | NEW |