Commit ab12365a authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

[Background Fetch] Show paused fetches on browser restart.

Paused fetch notifications were not displayed on browser start-up. This
means that the fetch could not be resumed and is forever paused.

The state of the entry needs to be exposed on DS initialization, so
that paused items can notify the OfflineContentAggregator and display a
notification.

Bug: 889423
Change-Id: Ia61c903f6234264821aad20b7bb93d6a3fdeb447
Reviewed-on: https://chromium-review.googlesource.com/c/1251630Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597204}
parent f194e1ec
......@@ -240,7 +240,7 @@ public class SystemDownloadNotifier2 implements DownloadNotifier {
getDownloadNotificationService().notifyDownloadPaused(info.getContentId(),
info.getFileName(), true, false, info.isOffTheRecord(),
info.getIsTransient(), info.getIcon(), info.getOriginalUrl(),
info.getShouldPromoteOrigin(), false, false, info.getPendingState());
info.getShouldPromoteOrigin(), false, true, info.getPendingState());
break;
case NotificationType.SUCCEEDED:
final int notificationId =
......
......@@ -8,6 +8,7 @@
#include "chrome/browser/background_fetch/background_fetch_delegate_impl.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/download/download_service_factory.h"
#include "chrome/browser/offline_items_collection/offline_content_aggregator_factory.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
......@@ -35,6 +36,7 @@ BackgroundFetchDelegateFactory::BackgroundFetchDelegateFactory()
BrowserContextDependencyManager::GetInstance()) {
DependsOn(DownloadServiceFactory::GetInstance());
DependsOn(HostContentSettingsMapFactory::GetInstance());
DependsOn(OfflineContentAggregatorFactory::GetInstance());
}
BackgroundFetchDelegateFactory::~BackgroundFetchDelegateFactory() {}
......
......@@ -628,6 +628,22 @@ bool BackgroundFetchDelegateImpl::IsGuidOutstanding(
outstanding_guids.end();
}
void BackgroundFetchDelegateImpl::RestartPausedDownload(
const std::string& download_guid) {
auto job_it = download_job_unique_id_map_.find(download_guid);
if (job_it == download_job_unique_id_map_.end())
return;
const std::string& unique_id = job_it->second;
DCHECK(job_details_map_.find(unique_id) != job_details_map_.end());
JobDetails& job_details = job_details_map_.find(unique_id)->second;
job_details.paused = true;
UpdateOfflineItemAndUpdateObservers(&job_details);
}
std::set<std::string> BackgroundFetchDelegateImpl::TakeOutstandingGuids() {
std::set<std::string> outstanding_guids;
for (auto& job_id_details : job_details_map_) {
......
......@@ -108,6 +108,10 @@ class BackgroundFetchDelegateImpl
// Fetch.
bool IsGuidOutstanding(const std::string& guid) const;
// Notifies the OfflineContentAggregator of an interrupted download that is
// in a paused state.
void RestartPausedDownload(const std::string& download_guid);
// Returns the set of download GUIDs that have started but did not finish
// according to Background Fetch. Clears out all references to outstanding
// GUIDs.
......
......@@ -9,6 +9,7 @@
#include <utility>
#include "base/threading/sequenced_task_runner_handle.h"
#include "chrome/browser/after_startup_task_utils.h"
#include "chrome/browser/background_fetch/background_fetch_delegate_impl.h"
#include "chrome/browser/download/download_service_factory.h"
#include "components/download/public/background_service/download_metadata.h"
......@@ -61,9 +62,18 @@ void BackgroundFetchDownloadClient::OnServiceInitialized(
if (download.completion_info) {
// The download finished but was not persisted.
OnDownloadSucceeded(download.guid, *download.completion_info);
return;
}
// The download is resuming, and will call the appropriate functions.
// The download is active, and will call the appropriate functions.
if (download.paused) {
// We need to resurface the notification in a paused state.
AfterStartupTaskUtils::PostTask(
FROM_HERE, base::SequencedTaskRunnerHandle::Get(),
base::BindOnce(&BackgroundFetchDelegateImpl::RestartPausedDownload,
GetDelegate()->GetWeakPtr(), download.guid));
}
}
// There is also the case that the Download Service is not aware of the GUID.
......
......@@ -92,6 +92,7 @@ DownloadMetaData BuildDownloadMetaData(Entry* entry, DownloadDriver* driver) {
DCHECK(entry);
DownloadMetaData meta_data;
meta_data.guid = entry->guid;
meta_data.paused = entry->state == Entry::State::PAUSED;
if (entry->state == Entry::State::COMPLETE) {
meta_data.completion_info =
CompletionInfo(entry->target_file_path, entry->bytes_downloaded,
......
......@@ -45,13 +45,13 @@ bool CompletionInfo::operator==(const CompletionInfo& other) const {
other.response_headers.get());
}
DownloadMetaData::DownloadMetaData() : current_size(0u) {}
DownloadMetaData::DownloadMetaData() : current_size(0u), paused(false) {}
DownloadMetaData::DownloadMetaData(const DownloadMetaData& other) = default;
bool DownloadMetaData::operator==(const DownloadMetaData& other) const {
return guid == other.guid && current_size == other.current_size &&
completion_info == other.completion_info;
completion_info == other.completion_info && paused == other.paused;
}
DownloadMetaData::~DownloadMetaData() = default;
......
......@@ -61,6 +61,9 @@ struct DownloadMetaData {
// uncompleted download.
uint64_t current_size;
// Whether the entry is currently paused by the client.
bool paused;
// Info about successfully completed download, or null for in-progress
// download. Failed download will not be persisted and exposed as meta data.
base::Optional<CompletionInfo> completion_info;
......
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