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 3fcb33ef51edfe4b895112a7ce292e14f8af65c4..dc224c95cdf0a5849f8951835dcbada29b544a16 100644 |
--- a/content/browser/download/download_manager_impl.cc |
+++ b/content/browser/download/download_manager_impl.cc |
@@ -106,6 +106,7 @@ class DownloadItemFactoryImpl : public DownloadItemFactory { |
DownloadItemImpl* CreatePersistedItem( |
DownloadItemImplDelegate* delegate, |
+ const std::string& guid, |
uint32_t download_id, |
const base::FilePath& current_path, |
const base::FilePath& target_path, |
@@ -125,25 +126,10 @@ class DownloadItemFactoryImpl : public DownloadItemFactory { |
bool opened, |
const net::BoundNetLog& bound_net_log) override { |
return new DownloadItemImpl( |
- delegate, |
- download_id, |
- current_path, |
- target_path, |
- url_chain, |
- referrer_url, |
- mime_type, |
- original_mime_type, |
- start_time, |
- end_time, |
- etag, |
- last_modified, |
- received_bytes, |
- total_bytes, |
- state, |
- danger_type, |
- interrupt_reason, |
- opened, |
- bound_net_log); |
+ delegate, guid, download_id, current_path, target_path, url_chain, |
+ referrer_url, mime_type, original_mime_type, start_time, end_time, etag, |
+ last_modified, received_bytes, total_bytes, state, danger_type, |
+ interrupt_reason, opened, bound_net_log); |
} |
DownloadItemImpl* CreateActiveItem( |
@@ -197,6 +183,7 @@ DownloadItemImpl* DownloadManagerImpl::CreateActiveItem( |
DownloadItemImpl* download = |
item_factory_->CreateActiveItem(this, id, info, bound_net_log); |
downloads_[id] = download; |
+ downloads_by_guid_[download->GetGuid()] = download; |
return download; |
} |
@@ -285,6 +272,7 @@ void DownloadManagerImpl::Shutdown() { |
download->Cancel(false); |
} |
STLDeleteValues(&downloads_); |
+ downloads_by_guid_.clear(); |
url_downloaders_.clear(); |
// We'll have nothing more to report to the observers after this point. |
@@ -450,6 +438,8 @@ void DownloadManagerImpl::CreateSavePackageDownloadItemWithId( |
this, id, main_file_path, page_url, mime_type, std::move(request_handle), |
bound_net_log); |
downloads_[download_item->GetId()] = download_item; |
+ DCHECK(!ContainsKey(downloads_by_guid_, download_item->GetGuid())); |
+ downloads_by_guid_[download_item->GetGuid()] = download_item; |
FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated( |
this, download_item)); |
if (!item_created.is_null()) |
@@ -495,6 +485,8 @@ void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) { |
if (!download) |
return; |
+ downloads_by_guid_.erase(download->GetGuid()); |
+ |
uint32_t download_id = download->GetId(); |
if (downloads_.erase(download_id) == 0) |
return; |
@@ -596,6 +588,7 @@ void DownloadManagerImpl::RemoveObserver(Observer* observer) { |
} |
DownloadItem* DownloadManagerImpl::CreateDownloadItem( |
+ const std::string& guid, |
uint32_t id, |
const base::FilePath& current_path, |
const base::FilePath& target_path, |
@@ -617,27 +610,14 @@ DownloadItem* DownloadManagerImpl::CreateDownloadItem( |
NOTREACHED(); |
return NULL; |
} |
+ DCHECK(!ContainsKey(downloads_by_guid_, guid)); |
DownloadItemImpl* item = item_factory_->CreatePersistedItem( |
- this, |
- id, |
- current_path, |
- target_path, |
- url_chain, |
- referrer_url, |
- mime_type, |
- original_mime_type, |
- start_time, |
- end_time, |
- etag, |
- last_modified, |
- received_bytes, |
- total_bytes, |
- state, |
- danger_type, |
- interrupt_reason, |
- opened, |
+ this, guid, id, current_path, target_path, url_chain, referrer_url, |
+ mime_type, original_mime_type, start_time, end_time, etag, last_modified, |
+ received_bytes, total_bytes, state, danger_type, interrupt_reason, opened, |
net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD)); |
downloads_[id] = item; |
+ downloads_by_guid_[guid] = item; |
FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); |
DVLOG(20) << __FUNCTION__ << "() download = " << item->DebugString(true); |
return item; |
@@ -668,7 +648,14 @@ int DownloadManagerImpl::NonMaliciousInProgressCount() const { |
} |
DownloadItem* DownloadManagerImpl::GetDownload(uint32_t download_id) { |
- return ContainsKey(downloads_, download_id) ? downloads_[download_id] : NULL; |
+ return ContainsKey(downloads_, download_id) ? downloads_[download_id] |
+ : nullptr; |
+} |
+ |
+DownloadItem* DownloadManagerImpl::GetDownloadByGuid(const std::string& guid) { |
+ DCHECK(guid == base::ToUpperASCII(guid)); |
+ return ContainsKey(downloads_by_guid_, guid) ? downloads_by_guid_[guid] |
+ : nullptr; |
} |
void DownloadManagerImpl::GetAllDownloads(DownloadVector* downloads) { |