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

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

Issue 1251243003: Support restricting browsing data removal for downloads by origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Apply auto-formatting. Created 5 years, 4 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 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
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
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 // Determines if the given URL should be removed. This is the case for URLs
569 base::Time remove_end) { 570 // that are same-origin with the given origin or where the given origin is
571 // unique. The latter marks a sitation where we intend to clear all URLs.
572 static bool IsRemovableURL(const GURL& url,
Bernhard Bauer 2015/08/04 07:49:20 Move this into an anonymous namespace instead of d
Timo Reimann 2015/08/04 15:00:26 Originally, I had it in an anonymous namespace and
Bernhard Bauer 2015/08/04 15:05:06 I have seen separate anonymous namespaces; I don't
573 const url::Origin& origin_to_clear) {
574 url::Origin url_origin(url);
575
576 return origin_to_clear.unique() ||
577 origin_to_clear.IsSameOriginWith(url_origin);
578 }
579
580 int DownloadManagerImpl::RemoveDownloadsBetween(
581 const url::Origin& origin_to_clear,
582 base::Time remove_begin,
583 base::Time remove_end) {
570 int count = 0; 584 int count = 0;
571 DownloadMap::const_iterator it = downloads_.begin(); 585 DownloadMap::const_iterator it = downloads_.begin();
572 while (it != downloads_.end()) { 586 while (it != downloads_.end()) {
573 DownloadItemImpl* download = it->second; 587 DownloadItemImpl* download = it->second;
574 588
575 // Increment done here to protect against invalidation below. 589 // Increment done here to protect against invalidation below.
576 ++it; 590 ++it;
577 591
578 if (download->GetStartTime() >= remove_begin && 592 if (IsRemovableURL(download->GetURL(), origin_to_clear) &&
593 download->GetStartTime() >= remove_begin &&
579 (remove_end.is_null() || download->GetStartTime() < remove_end) && 594 (remove_end.is_null() || download->GetStartTime() < remove_end) &&
580 (download->GetState() != DownloadItem::IN_PROGRESS)) { 595 (download->GetState() != DownloadItem::IN_PROGRESS)) {
581 // Erases the download from downloads_. 596 // Erases the download from downloads_.
582 download->Remove(); 597 download->Remove();
583 count++; 598 count++;
584 } 599 }
585 } 600 }
586 return count; 601 return count;
587 } 602 }
588 603
589 int DownloadManagerImpl::RemoveDownloads(base::Time remove_begin) { 604 int DownloadManagerImpl::RemoveDownloads(base::Time remove_begin) {
590 return RemoveDownloadsBetween(remove_begin, base::Time()); 605 return RemoveDownloadsBetween(url::Origin(), remove_begin, base::Time());
591 } 606 }
592 607
593 int DownloadManagerImpl::RemoveAllDownloads() { 608 int DownloadManagerImpl::RemoveAllDownloads() {
594 // The null times make the date range unbounded. 609 // The null times make the date range unbounded.
595 int num_deleted = RemoveDownloadsBetween(base::Time(), base::Time()); 610 int num_deleted =
611 RemoveDownloadsBetween(url::Origin(), base::Time(), base::Time());
596 RecordClearAllSize(num_deleted); 612 RecordClearAllSize(num_deleted);
597 return num_deleted; 613 return num_deleted;
598 } 614 }
599 615
600 void DownloadManagerImpl::DownloadUrl( 616 void DownloadManagerImpl::DownloadUrl(
601 scoped_ptr<DownloadUrlParameters> params) { 617 scoped_ptr<DownloadUrlParameters> params) {
602 if (params->post_id() >= 0) { 618 if (params->post_id() >= 0) {
603 // Check this here so that the traceback is more useful. 619 // Check this here so that the traceback is more useful.
604 DCHECK(params->prefer_cache()); 620 DCHECK(params->prefer_cache());
605 DCHECK_EQ("POST", params->method()); 621 DCHECK_EQ("POST", params->method());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 if (delegate_) 732 if (delegate_)
717 delegate_->OpenDownload(download); 733 delegate_->OpenDownload(download);
718 } 734 }
719 735
720 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { 736 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) {
721 if (delegate_) 737 if (delegate_)
722 delegate_->ShowDownloadInShell(download); 738 delegate_->ShowDownloadInShell(download);
723 } 739 }
724 740
725 } // namespace content 741 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_manager_impl.h ('k') | content/browser/download/download_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698