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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/download/download_manager_impl.cc
diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc
index ce39612f65fec16ac9b6887d8034575d3c119ba1..091accce873d83f22b6a88423c639d1b691d5f4c 100644
--- a/content/browser/download/download_manager_impl.cc
+++ b/content/browser/download/download_manager_impl.cc
@@ -44,6 +44,7 @@
#include "net/base/request_priority.h"
#include "net/base/upload_bytes_element_reader.h"
#include "net/url_request/url_request_context.h"
+#include "url/origin.h"
namespace content {
namespace {
@@ -134,6 +135,17 @@ void BeginDownload(scoped_ptr<DownloadUrlParameters> params,
params->callback());
}
+// Determines if the given URL should be removed. This is the case for URLs
+// that are same-origin with the given origin or where the given origin is
+// unique. The latter marks a sitation where we intend to clear all URLs.
+static bool IsRemovableURL(
+ const GURL& url, const url::Origin& origin_to_clear) {
+ url::Origin url_origin(url);
+
+ return origin_to_clear.unique() ||
+ origin_to_clear.IsSameOriginWith(url_origin);
+}
+
class MapValueIteratorAdapter {
public:
explicit MapValueIteratorAdapter(
@@ -565,8 +577,10 @@ void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) {
delete download;
}
-int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin,
- base::Time remove_end) {
+int DownloadManagerImpl::RemoveDownloadsBetween(
+ const url::Origin& origin_to_clear,
+ base::Time remove_begin,
+ base::Time remove_end) {
int count = 0;
DownloadMap::const_iterator it = downloads_.begin();
while (it != downloads_.end()) {
@@ -575,7 +589,8 @@ int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin,
// Increment done here to protect against invalidation below.
++it;
- if (download->GetStartTime() >= remove_begin &&
+ if (IsRemovableURL(download->GetURL(), origin_to_clear) &&
Paweł Hajdan Jr. 2015/07/24 09:44:17 IsRemovableURL is located far from this method whi
+ download->GetStartTime() >= remove_begin &&
(remove_end.is_null() || download->GetStartTime() < remove_end) &&
(download->GetState() != DownloadItem::IN_PROGRESS)) {
// Erases the download from downloads_.
@@ -587,12 +602,13 @@ int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin,
}
int DownloadManagerImpl::RemoveDownloads(base::Time remove_begin) {
- return RemoveDownloadsBetween(remove_begin, base::Time());
+ return RemoveDownloadsBetween(url::Origin(), remove_begin, base::Time());
}
int DownloadManagerImpl::RemoveAllDownloads() {
// The null times make the date range unbounded.
- int num_deleted = RemoveDownloadsBetween(base::Time(), base::Time());
+ int num_deleted = RemoveDownloadsBetween(
+ url::Origin(), base::Time(), base::Time());
RecordClearAllSize(num_deleted);
return num_deleted;
}
« 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