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

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: Leave TODO and some more clean up. 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 params->resource_context(), 128 params->resource_context(),
128 params->render_process_host_id(), 129 params->render_process_host_id(),
129 params->render_view_host_routing_id(), 130 params->render_view_host_routing_id(),
130 params->prefer_cache(), 131 params->prefer_cache(),
131 params->do_not_prompt_for_login(), 132 params->do_not_prompt_for_login(),
132 save_info.Pass(), 133 save_info.Pass(),
133 download_id, 134 download_id,
134 params->callback()); 135 params->callback());
135 } 136 }
136 137
138 // Determines if the given URL should be removed. This is the case for URLs
139 // that are same-origin with the given origin or where the given origin is
140 // unique. The latter marks a sitation where we intend to clear all URLs.
141 static bool IsRemovableURL(
142 const GURL& url, const url::Origin& origin_to_clear) {
143 url::Origin url_origin(url);
144
145 return origin_to_clear.unique() ||
146 origin_to_clear.IsSameOriginWith(url_origin);
147 }
148
137 class MapValueIteratorAdapter { 149 class MapValueIteratorAdapter {
138 public: 150 public:
139 explicit MapValueIteratorAdapter( 151 explicit MapValueIteratorAdapter(
140 base::hash_map<int64, DownloadItem*>::const_iterator iter) 152 base::hash_map<int64, DownloadItem*>::const_iterator iter)
141 : iter_(iter) { 153 : iter_(iter) {
142 } 154 }
143 ~MapValueIteratorAdapter() {} 155 ~MapValueIteratorAdapter() {}
144 156
145 DownloadItem* operator*() { return iter_->second; } 157 DownloadItem* operator*() { return iter_->second; }
146 158
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) { 570 void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) {
559 if (!download) 571 if (!download)
560 return; 572 return;
561 573
562 uint32 download_id = download->GetId(); 574 uint32 download_id = download->GetId();
563 if (downloads_.erase(download_id) == 0) 575 if (downloads_.erase(download_id) == 0)
564 return; 576 return;
565 delete download; 577 delete download;
566 } 578 }
567 579
568 int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin, 580 int DownloadManagerImpl::RemoveDownloadsBetween(
569 base::Time remove_end) { 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) &&
Paweł Hajdan Jr. 2015/07/24 09:44:17 IsRemovableURL is located far from this method whi
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 = RemoveDownloadsBetween(
611 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