Chromium Code Reviews| 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; |
| } |