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

[Background Fetch] Register Offline Item Aggregator in incognito mode

Bug: 766082
Change-Id: Idd4a607177f0bbe44fac8dd9e7cd9fe357dbf4ef
Reviewed-on: https://chromium-review.googlesource.com/1170906Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585219}
parent 5d47524b
...@@ -4,12 +4,18 @@ ...@@ -4,12 +4,18 @@
#include "chrome/browser/background_fetch/background_fetch_delegate_factory.h" #include "chrome/browser/background_fetch/background_fetch_delegate_factory.h"
#include "base/strings/string_number_conversions.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 "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"
#include "content/public/browser/background_fetch_delegate.h" #include "content/public/browser/background_fetch_delegate.h"
namespace {
constexpr char kBackgroundFetchNamespacePrefix[] = "background_fetch_";
} // namespace
// static // static
BackgroundFetchDelegateImpl* BackgroundFetchDelegateFactory::GetForProfile( BackgroundFetchDelegateImpl* BackgroundFetchDelegateFactory::GetForProfile(
Profile* profile) { Profile* profile) {
...@@ -33,5 +39,17 @@ BackgroundFetchDelegateFactory::~BackgroundFetchDelegateFactory() {} ...@@ -33,5 +39,17 @@ BackgroundFetchDelegateFactory::~BackgroundFetchDelegateFactory() {}
KeyedService* BackgroundFetchDelegateFactory::BuildServiceInstanceFor( KeyedService* BackgroundFetchDelegateFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
return new BackgroundFetchDelegateImpl(Profile::FromBrowserContext(context)); // Number of offline content aggregator registrations. There can be multiple
// incognito profiles created, and the provided namespace needs to be unique.
static int num_registrations = 0;
std::string provider_namespace =
kBackgroundFetchNamespacePrefix + base::IntToString(++num_registrations);
return new BackgroundFetchDelegateImpl(Profile::FromBrowserContext(context),
provider_namespace);
}
content::BrowserContext* BackgroundFetchDelegateFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextOwnInstanceInIncognito(context);
} }
...@@ -24,11 +24,10 @@ class BackgroundFetchDelegateFactory ...@@ -24,11 +24,10 @@ class BackgroundFetchDelegateFactory
BackgroundFetchDelegateFactory(); BackgroundFetchDelegateFactory();
~BackgroundFetchDelegateFactory() override; ~BackgroundFetchDelegateFactory() override;
// BrowserContextKeyedBaseFactory methods:
// TODO(crbug.com/766082): Override GetBrowserContextToUse to handle Incognito
// mode.
KeyedService* BuildServiceInstanceFor( KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override; content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDelegateFactory); DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDelegateFactory);
}; };
......
...@@ -26,13 +26,15 @@ ...@@ -26,13 +26,15 @@
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
BackgroundFetchDelegateImpl::BackgroundFetchDelegateImpl(Profile* profile) BackgroundFetchDelegateImpl::BackgroundFetchDelegateImpl(
Profile* profile,
const std::string& provider_namespace)
: profile_(profile), : profile_(profile),
offline_content_aggregator_( offline_content_aggregator_(
OfflineContentAggregatorFactory::GetForBrowserContext(profile)), OfflineContentAggregatorFactory::GetForBrowserContext(profile)),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
DCHECK(profile_); DCHECK(profile_);
offline_content_aggregator_->RegisterProvider("background_fetch", this); offline_content_aggregator_->RegisterProvider(provider_namespace, this);
} }
BackgroundFetchDelegateImpl::~BackgroundFetchDelegateImpl() = default; BackgroundFetchDelegateImpl::~BackgroundFetchDelegateImpl() = default;
......
...@@ -39,7 +39,8 @@ class BackgroundFetchDelegateImpl ...@@ -39,7 +39,8 @@ class BackgroundFetchDelegateImpl
public offline_items_collection::OfflineContentProvider, public offline_items_collection::OfflineContentProvider,
public KeyedService { public KeyedService {
public: public:
explicit BackgroundFetchDelegateImpl(Profile* profile); BackgroundFetchDelegateImpl(Profile* profile,
const std::string& provider_namespace);
~BackgroundFetchDelegateImpl() override; ~BackgroundFetchDelegateImpl() override;
......
...@@ -20,7 +20,6 @@ OfflineContentAggregatorFactory::GetInstance() { ...@@ -20,7 +20,6 @@ OfflineContentAggregatorFactory::GetInstance() {
offline_items_collection::OfflineContentAggregator* offline_items_collection::OfflineContentAggregator*
OfflineContentAggregatorFactory::GetForBrowserContext( OfflineContentAggregatorFactory::GetForBrowserContext(
content::BrowserContext* context) { content::BrowserContext* context) {
DCHECK(!context->IsOffTheRecord());
return static_cast<offline_items_collection::OfflineContentAggregator*>( return static_cast<offline_items_collection::OfflineContentAggregator*>(
GetInstance()->GetServiceForBrowserContext(context, true)); GetInstance()->GetServiceForBrowserContext(context, true));
} }
...@@ -34,6 +33,7 @@ OfflineContentAggregatorFactory::~OfflineContentAggregatorFactory() = default; ...@@ -34,6 +33,7 @@ OfflineContentAggregatorFactory::~OfflineContentAggregatorFactory() = default;
KeyedService* OfflineContentAggregatorFactory::BuildServiceInstanceFor( KeyedService* OfflineContentAggregatorFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
DCHECK(!context->IsOffTheRecord());
return new offline_items_collection::OfflineContentAggregator(); return new offline_items_collection::OfflineContentAggregator();
} }
......
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