Commit fb936ad7 authored by Min Qin's avatar Min Qin Committed by Commit Bot

Allow in-progress downloads to show up before DownloadManagerImpl fully initializes

With the introduction of SimpleDownloadManagerCoordinator, it has 2
stages. In the first stage, OnDownloadsInitialized() will be called
for in-progress downloads. In this stage, clients should be able to
access all the in-progress downloads. In the 2nd stage,
OnDownloadsInitialized() is called for all downloads.

However, if InProgressDownloadManager is passed to a
DownloadManagerImpl, the DownloadManagerImpl will not return the
in-progress downloads on GetAllDownloads() unless it is fully initialized.
As a result, this causes a wierd issue that after stage 1, calling
GetAllDownloads() sometimes may not return all the downloads until
stage 2 completes.

BUG=942770

Change-Id: I44e589ee1bd174c5fef86ec9c8170ac94e6e1b5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1603208Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658795}
parent 9583b0ed
......@@ -1200,6 +1200,12 @@ download::DownloadItem* DownloadManagerImpl::GetDownload(uint32_t download_id) {
download::DownloadItem* DownloadManagerImpl::GetDownloadByGuid(
const std::string& guid) {
if (!in_progress_downloads_.empty()) {
for (const auto& it : in_progress_downloads_) {
if (it->GetGuid() == guid)
return it.get();
}
}
return base::ContainsKey(downloads_by_guid_, guid) ? downloads_by_guid_[guid]
: nullptr;
}
......@@ -1227,9 +1233,10 @@ void DownloadManagerImpl::OnUrlDownloadStopped(
void DownloadManagerImpl::GetAllDownloads(
download::SimpleDownloadManager::DownloadVector* downloads) {
for (const auto& it : downloads_) {
for (const auto& it : downloads_)
downloads->push_back(it.second.get());
}
for (const auto& it : in_progress_downloads_)
downloads->push_back(it.get());
}
void DownloadManagerImpl::OpenDownload(download::DownloadItemImpl* download) {
......
......@@ -765,7 +765,10 @@ TEST_F(DownloadManagerTest, OnInProgressDownloadsLoaded) {
EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _))
.WillOnce(Return());
OnInProgressDownloadManagerInitialized();
ASSERT_FALSE(download_manager_->GetDownloadByGuid(kGuid));
ASSERT_TRUE(download_manager_->GetDownloadByGuid(kGuid));
std::vector<download::DownloadItem*> vector;
download_manager_->GetAllDownloads(&vector);
ASSERT_EQ(1u, vector.size());
EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId(_))
.WillOnce(RunCallback<0>(1));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment