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 { ...@@ -240,7 +240,7 @@ public class SystemDownloadNotifier2 implements DownloadNotifier {
getDownloadNotificationService().notifyDownloadPaused(info.getContentId(), getDownloadNotificationService().notifyDownloadPaused(info.getContentId(),
info.getFileName(), true, false, info.isOffTheRecord(), info.getFileName(), true, false, info.isOffTheRecord(),
info.getIsTransient(), info.getIcon(), info.getOriginalUrl(), info.getIsTransient(), info.getIcon(), info.getOriginalUrl(),
info.getShouldPromoteOrigin(), false, false, info.getPendingState()); info.getShouldPromoteOrigin(), false, true, info.getPendingState());
break; break;
case NotificationType.SUCCEEDED: case NotificationType.SUCCEEDED:
final int notificationId = final int notificationId =
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "chrome/browser/background_fetch/background_fetch_delegate_impl.h" #include "chrome/browser/background_fetch/background_fetch_delegate_impl.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/download/download_service_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/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
...@@ -35,6 +36,7 @@ BackgroundFetchDelegateFactory::BackgroundFetchDelegateFactory() ...@@ -35,6 +36,7 @@ BackgroundFetchDelegateFactory::BackgroundFetchDelegateFactory()
BrowserContextDependencyManager::GetInstance()) { BrowserContextDependencyManager::GetInstance()) {
DependsOn(DownloadServiceFactory::GetInstance()); DependsOn(DownloadServiceFactory::GetInstance());
DependsOn(HostContentSettingsMapFactory::GetInstance()); DependsOn(HostContentSettingsMapFactory::GetInstance());
DependsOn(OfflineContentAggregatorFactory::GetInstance());
} }
BackgroundFetchDelegateFactory::~BackgroundFetchDelegateFactory() {} BackgroundFetchDelegateFactory::~BackgroundFetchDelegateFactory() {}
......
...@@ -628,6 +628,22 @@ bool BackgroundFetchDelegateImpl::IsGuidOutstanding( ...@@ -628,6 +628,22 @@ bool BackgroundFetchDelegateImpl::IsGuidOutstanding(
outstanding_guids.end(); 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> BackgroundFetchDelegateImpl::TakeOutstandingGuids() {
std::set<std::string> outstanding_guids; std::set<std::string> outstanding_guids;
for (auto& job_id_details : job_details_map_) { for (auto& job_id_details : job_details_map_) {
......
...@@ -108,6 +108,10 @@ class BackgroundFetchDelegateImpl ...@@ -108,6 +108,10 @@ class BackgroundFetchDelegateImpl
// Fetch. // Fetch.
bool IsGuidOutstanding(const std::string& guid) const; 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 // Returns the set of download GUIDs that have started but did not finish
// according to Background Fetch. Clears out all references to outstanding // according to Background Fetch. Clears out all references to outstanding
// GUIDs. // GUIDs.
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <utility> #include <utility>
#include "base/threading/sequenced_task_runner_handle.h" #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/background_fetch/background_fetch_delegate_impl.h"
#include "chrome/browser/download/download_service_factory.h" #include "chrome/browser/download/download_service_factory.h"
#include "components/download/public/background_service/download_metadata.h" #include "components/download/public/background_service/download_metadata.h"
...@@ -61,9 +62,18 @@ void BackgroundFetchDownloadClient::OnServiceInitialized( ...@@ -61,9 +62,18 @@ void BackgroundFetchDownloadClient::OnServiceInitialized(
if (download.completion_info) { if (download.completion_info) {
// The download finished but was not persisted. // The download finished but was not persisted.
OnDownloadSucceeded(download.guid, *download.completion_info); 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. // 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) { ...@@ -92,6 +92,7 @@ DownloadMetaData BuildDownloadMetaData(Entry* entry, DownloadDriver* driver) {
DCHECK(entry); DCHECK(entry);
DownloadMetaData meta_data; DownloadMetaData meta_data;
meta_data.guid = entry->guid; meta_data.guid = entry->guid;
meta_data.paused = entry->state == Entry::State::PAUSED;
if (entry->state == Entry::State::COMPLETE) { if (entry->state == Entry::State::COMPLETE) {
meta_data.completion_info = meta_data.completion_info =
CompletionInfo(entry->target_file_path, entry->bytes_downloaded, CompletionInfo(entry->target_file_path, entry->bytes_downloaded,
......
...@@ -45,13 +45,13 @@ bool CompletionInfo::operator==(const CompletionInfo& other) const { ...@@ -45,13 +45,13 @@ bool CompletionInfo::operator==(const CompletionInfo& other) const {
other.response_headers.get()); other.response_headers.get());
} }
DownloadMetaData::DownloadMetaData() : current_size(0u) {} DownloadMetaData::DownloadMetaData() : current_size(0u), paused(false) {}
DownloadMetaData::DownloadMetaData(const DownloadMetaData& other) = default; DownloadMetaData::DownloadMetaData(const DownloadMetaData& other) = default;
bool DownloadMetaData::operator==(const DownloadMetaData& other) const { bool DownloadMetaData::operator==(const DownloadMetaData& other) const {
return guid == other.guid && current_size == other.current_size && 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; DownloadMetaData::~DownloadMetaData() = default;
......
...@@ -61,6 +61,9 @@ struct DownloadMetaData { ...@@ -61,6 +61,9 @@ struct DownloadMetaData {
// uncompleted download. // uncompleted download.
uint64_t current_size; 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 // Info about successfully completed download, or null for in-progress
// download. Failed download will not be persisted and exposed as meta data. // download. Failed download will not be persisted and exposed as meta data.
base::Optional<CompletionInfo> completion_info; 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