Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: content/browser/download/download_manager_impl.cc

Issue 1603903002: Add an OriginFilterBuilder class for [white|black]listing origins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 28 matching lines...) Expand all
39 #include "content/public/browser/render_process_host.h" 39 #include "content/public/browser/render_process_host.h"
40 #include "content/public/browser/resource_context.h" 40 #include "content/public/browser/resource_context.h"
41 #include "content/public/browser/web_contents_delegate.h" 41 #include "content/public/browser/web_contents_delegate.h"
42 #include "content/public/common/referrer.h" 42 #include "content/public/common/referrer.h"
43 #include "net/base/elements_upload_data_stream.h" 43 #include "net/base/elements_upload_data_stream.h"
44 #include "net/base/load_flags.h" 44 #include "net/base/load_flags.h"
45 #include "net/base/request_priority.h" 45 #include "net/base/request_priority.h"
46 #include "net/base/upload_bytes_element_reader.h" 46 #include "net/base/upload_bytes_element_reader.h"
47 #include "net/url_request/url_request_context.h" 47 #include "net/url_request/url_request_context.h"
48 #include "url/origin.h" 48 #include "url/origin.h"
49 #include "url/origin_filter.h"
49 50
50 namespace content { 51 namespace content {
51 namespace { 52 namespace {
52 53
53 scoped_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> BeginDownload( 54 scoped_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> BeginDownload(
54 scoped_ptr<DownloadUrlParameters> params, 55 scoped_ptr<DownloadUrlParameters> params,
55 uint32_t download_id, 56 uint32_t download_id,
56 base::WeakPtr<DownloadManagerImpl> download_manager) { 57 base::WeakPtr<DownloadManagerImpl> download_manager) {
57 DCHECK_CURRENTLY_ON(BrowserThread::IO); 58 DCHECK_CURRENTLY_ON(BrowserThread::IO);
58 // ResourceDispatcherHost{Base} is-not-a URLRequest::Delegate, and 59 // ResourceDispatcherHost{Base} is-not-a URLRequest::Delegate, and
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 ++ptr) { 550 ++ptr) {
550 if (ptr->get() == downloader) { 551 if (ptr->get() == downloader) {
551 url_downloaders_.erase(ptr); 552 url_downloaders_.erase(ptr);
552 return; 553 return;
553 } 554 }
554 } 555 }
555 } 556 }
556 557
557 namespace { 558 namespace {
558 559
559 bool RemoveDownloadBetween(base::Time remove_begin, 560 bool RemoveDownloadByOriginAndTime(const url::OriginFilter* origins,
560 base::Time remove_end, 561 base::Time remove_begin,
561 const DownloadItemImpl* download_item) { 562 base::Time remove_end,
562 return download_item->GetStartTime() >= remove_begin && 563 const DownloadItemImpl* download_item) {
564 return origins->MatchesURL(download_item->GetURL()) &&
565 download_item->GetStartTime() >= remove_begin &&
563 (remove_end.is_null() || download_item->GetStartTime() < remove_end); 566 (remove_end.is_null() || download_item->GetStartTime() < remove_end);
564 } 567 }
565 568
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 569 } // namespace
575 570
576 int DownloadManagerImpl::RemoveDownloads(const DownloadRemover& remover) { 571 int DownloadManagerImpl::RemoveDownloads(const DownloadRemover& remover) {
577 int count = 0; 572 int count = 0;
578 DownloadMap::const_iterator it = downloads_.begin(); 573 DownloadMap::const_iterator it = downloads_.begin();
579 while (it != downloads_.end()) { 574 while (it != downloads_.end()) {
580 DownloadItemImpl* download = it->second; 575 DownloadItemImpl* download = it->second;
581 576
582 // Increment done here to protect against invalidation below. 577 // Increment done here to protect against invalidation below.
583 ++it; 578 ++it;
584 579
585 if (download->GetState() != DownloadItem::IN_PROGRESS && 580 if (download->GetState() != DownloadItem::IN_PROGRESS &&
586 remover.Run(download)) { 581 remover.Run(download)) {
587 download->Remove(); 582 download->Remove();
588 count++; 583 count++;
589 } 584 }
590 } 585 }
591 return count; 586 return count;
592 } 587 }
593 588
594 int DownloadManagerImpl::RemoveDownloadsByOriginAndTime( 589 int DownloadManagerImpl::RemoveDownloadsByOriginAndTime(
595 const url::Origin& origin, 590 const url::OriginFilter* origins,
596 base::Time remove_begin, 591 base::Time remove_begin,
597 base::Time remove_end) { 592 base::Time remove_end) {
598 return RemoveDownloads(base::Bind(&RemoveDownloadByOriginAndTime, 593 return RemoveDownloads(base::Bind(&RemoveDownloadByOriginAndTime,
599 base::ConstRef(origin), remove_begin, 594 base::Unretained(origins), remove_begin,
600 remove_end)); 595 remove_end));
601 } 596 }
602 597
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 }
608
609 int DownloadManagerImpl::RemoveDownloads(base::Time remove_begin) { 598 int DownloadManagerImpl::RemoveDownloads(base::Time remove_begin) {
610 return RemoveDownloadsBetween(remove_begin, base::Time()); 599 return RemoveDownloadsByOriginAndTime(url::OriginFilter::Empty().get(),
600 remove_begin, base::Time());
611 } 601 }
612 602
613 int DownloadManagerImpl::RemoveAllDownloads() { 603 int DownloadManagerImpl::RemoveAllDownloads() {
614 // The null times make the date range unbounded. 604 // The null times make the date range unbounded.
615 int num_deleted = RemoveDownloadsBetween(base::Time(), base::Time()); 605 int num_deleted = RemoveDownloadsByOriginAndTime(
606 url::OriginFilter::Empty().get(), base::Time(), base::Time());
616 RecordClearAllSize(num_deleted); 607 RecordClearAllSize(num_deleted);
617 return num_deleted; 608 return num_deleted;
618 } 609 }
619 610
620 void DownloadManagerImpl::DownloadUrl( 611 void DownloadManagerImpl::DownloadUrl(
621 scoped_ptr<DownloadUrlParameters> params) { 612 scoped_ptr<DownloadUrlParameters> params) {
622 if (params->post_id() >= 0) { 613 if (params->post_id() >= 0) {
623 // Check this here so that the traceback is more useful. 614 // Check this here so that the traceback is more useful.
624 DCHECK(params->prefer_cache()); 615 DCHECK(params->prefer_cache());
625 DCHECK_EQ("POST", params->method()); 616 DCHECK_EQ("POST", params->method());
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 if (delegate_) 730 if (delegate_)
740 delegate_->OpenDownload(download); 731 delegate_->OpenDownload(download);
741 } 732 }
742 733
743 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { 734 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) {
744 if (delegate_) 735 if (delegate_)
745 delegate_->ShowDownloadInShell(download); 736 delegate_->ShowDownloadInShell(download);
746 } 737 }
747 738
748 } // namespace content 739 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698