Commit 22b7bf72 authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

[Background Fetch] Sync provided OfflineContentProvider namespaces

This was causing callbacks (like GetVisualsForItem) to be lost since the
ContentID namespace did not match the registered OfflineContentProvider
namespace.

Change-Id: I009cbd2c38ac8d91c8c1efcd302be725c6588463
Reviewed-on: https://chromium-review.googlesource.com/1186734Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585515}
parent c8e36a21
......@@ -36,11 +36,13 @@ BackgroundFetchDelegateImpl::BackgroundFetchDelegateImpl(
Profile* profile,
const std::string& provider_namespace)
: profile_(profile),
provider_namespace_(provider_namespace),
offline_content_aggregator_(
OfflineContentAggregatorFactory::GetForBrowserContext(profile)),
weak_ptr_factory_(this) {
DCHECK(profile_);
offline_content_aggregator_->RegisterProvider(provider_namespace, this);
DCHECK(!provider_namespace_.empty());
offline_content_aggregator_->RegisterProvider(provider_namespace_, this);
}
BackgroundFetchDelegateImpl::~BackgroundFetchDelegateImpl() = default;
......@@ -65,10 +67,11 @@ void BackgroundFetchDelegateImpl::Shutdown() {
BackgroundFetchDelegateImpl::JobDetails::JobDetails(JobDetails&&) = default;
BackgroundFetchDelegateImpl::JobDetails::JobDetails(
std::unique_ptr<content::BackgroundFetchDescription> fetch_description)
std::unique_ptr<content::BackgroundFetchDescription> fetch_description,
const std::string& provider_namespace)
: cancelled(false),
offline_item(offline_items_collection::ContentId(
"background_fetch",
provider_namespace,
fetch_description->job_unique_id)),
fetch_description(std::move(fetch_description)) {
UpdateOfflineItem();
......@@ -207,7 +210,8 @@ void BackgroundFetchDelegateImpl::CreateDownloadJob(
std::string job_unique_id = fetch_description->job_unique_id;
DCHECK(!job_details_map_.count(job_unique_id));
auto emplace_result = job_details_map_.emplace(
job_unique_id, JobDetails(std::move(fetch_description)));
job_unique_id,
JobDetails(std::move(fetch_description), provider_namespace_));
const JobDetails& details = emplace_result.first->second;
for (const auto& download_guid : details.fetch_description->current_guids) {
......
......@@ -114,8 +114,9 @@ class BackgroundFetchDelegateImpl
private:
struct JobDetails {
JobDetails(JobDetails&&);
explicit JobDetails(
std::unique_ptr<content::BackgroundFetchDescription> fetch_description);
JobDetails(
std::unique_ptr<content::BackgroundFetchDescription> fetch_description,
const std::string& provider_namespace);
~JobDetails();
void UpdateOfflineItem();
......@@ -150,6 +151,10 @@ class BackgroundFetchDelegateImpl
// The profile this service is being created for.
Profile* profile_;
// The namespace provided to the |offline_content_aggregator_| and used when
// creating Content IDs.
std::string provider_namespace_;
// The BackgroundFetchDelegateImplFactory depends on the
// DownloadServiceFactory, so |download_service_| should outlive |this|.
download::DownloadService* download_service_ = nullptr;
......
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