Commit 26145324 authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[BackgroundSync] Remove chrome deps from BackgroundSyncControllerImpl.

So that it can be componentized. Chrome specific logic has been moved to
BackgroundSyncDelegateImpl.

Bug: 1087486, 1091211
Change-Id: Ie4e220c563d48072e719524aad39bed50f9b101b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2454071
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarJosh Karlin <jkarlin@chromium.org>
Reviewed-by: default avatarRayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814682}
parent 6860e109
......@@ -5,6 +5,7 @@
#include "chrome/browser/background_sync/background_sync_controller_factory.h"
#include "chrome/browser/background_sync/background_sync_controller_impl.h"
#include "chrome/browser/background_sync/background_sync_delegate_impl.h"
#include "chrome/browser/engagement/site_engagement_service_factory.h"
#include "chrome/browser/metrics/ukm_background_recorder_service.h"
#include "chrome/browser/profiles/incognito_helpers.h"
......@@ -36,7 +37,9 @@ BackgroundSyncControllerFactory::~BackgroundSyncControllerFactory() = default;
KeyedService* BackgroundSyncControllerFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new BackgroundSyncControllerImpl(Profile::FromBrowserContext(context));
return new BackgroundSyncControllerImpl(
context, std::make_unique<BackgroundSyncDelegateImpl>(
Profile::FromBrowserContext(context)));
}
content::BrowserContext*
......
......@@ -7,11 +7,6 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "chrome/browser/background_sync/background_sync_delegate_impl.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/engagement/site_engagement_service.h"
#include "chrome/browser/profiles/profile.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/history/core/browser/history_service.h"
......@@ -27,10 +22,6 @@
#include "url/gurl.h"
#include "url/origin.h"
#if defined(OS_ANDROID)
#include "chrome/browser/android/background_sync_launcher_android.h"
#endif
// static
const char BackgroundSyncControllerImpl::kFieldTrialName[] = "BackgroundSync";
const char BackgroundSyncControllerImpl::kDisabledParameterName[] = "disabled";
......@@ -58,52 +49,20 @@ const char BackgroundSyncControllerImpl::kMaxSyncEventDurationName[] =
const char BackgroundSyncControllerImpl::kMinPeriodicSyncEventsInterval[] =
"min_periodic_sync_events_interval_sec";
BackgroundSyncControllerImpl::BackgroundSyncControllerImpl(Profile* profile)
: SiteEngagementObserver(SiteEngagementService::Get(profile)),
profile_(profile),
site_engagement_service_(SiteEngagementService::Get(profile)),
background_sync_delegate_(
std::make_unique<BackgroundSyncDelegateImpl>(profile_)) {
DCHECK(profile_);
DCHECK(site_engagement_service_);
BackgroundSyncControllerImpl::BackgroundSyncControllerImpl(
content::BrowserContext* browser_context,
std::unique_ptr<background_sync::BackgroundSyncDelegate> delegate)
: browser_context_(browser_context), delegate_(std::move(delegate)) {
DCHECK(browser_context_);
DCHECK(delegate_);
background_sync_metrics_ =
std::make_unique<BackgroundSyncMetrics>(background_sync_delegate_.get());
HostContentSettingsMapFactory::GetForProfile(profile_)->AddObserver(this);
std::make_unique<BackgroundSyncMetrics>(delegate_.get());
delegate_->GetHostContentSettingsMap()->AddObserver(this);
}
BackgroundSyncControllerImpl::~BackgroundSyncControllerImpl() = default;
void BackgroundSyncControllerImpl::OnEngagementEvent(
content::WebContents* web_contents,
const GURL& url,
double score,
SiteEngagementService::EngagementType engagement_type) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (score == 0.0)
return;
auto origin = url::Origin::Create(url);
auto iter = suspended_periodic_sync_origins_.find(origin);
if (iter == suspended_periodic_sync_origins_.end())
return;
suspended_periodic_sync_origins_.erase(iter);
auto* storage_partition = content::BrowserContext::GetStoragePartitionForSite(
profile_, url, /* can_create= */ false);
if (!storage_partition)
return;
auto* background_sync_context = storage_partition->GetBackgroundSyncContext();
if (!background_sync_context)
return;
background_sync_context->RevivePeriodicBackgroundSyncRegistrations(
std::move(origin));
}
void BackgroundSyncControllerImpl::OnContentSettingChanged(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
......@@ -123,7 +82,7 @@ void BackgroundSyncControllerImpl::OnContentSettingChanged(
auto* storage_partition =
content::BrowserContext::GetStoragePartitionForSite(
profile_, origin.GetURL(), /* can_create= */ false);
browser_context_, origin.GetURL(), /* can_create= */ false);
if (!storage_partition)
continue;
......@@ -147,9 +106,8 @@ void BackgroundSyncControllerImpl::GetParameterOverrides(
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
#if defined(OS_ANDROID)
if (BackgroundSyncLauncherAndroid::ShouldDisableBackgroundSync()) {
if (delegate_->ShouldDisableBackgroundSync())
parameters->disable = true;
}
#endif
std::map<std::string, std::string> field_params;
......@@ -283,12 +241,11 @@ void BackgroundSyncControllerImpl::ScheduleBrowserWakeUpWithDelay(
base::TimeDelta delay) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (profile_->IsOffTheRecord())
if (delegate_->IsProfileOffTheRecord())
return;
#if defined(OS_ANDROID)
BackgroundSyncLauncherAndroid::ScheduleBrowserWakeUpWithDelay(sync_type,
delay);
delegate_->ScheduleBrowserWakeUpWithDelay(sync_type, delay);
#endif
}
......@@ -296,39 +253,16 @@ void BackgroundSyncControllerImpl::CancelBrowserWakeup(
blink::mojom::BackgroundSyncType sync_type) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (profile_->IsOffTheRecord())
if (delegate_->IsProfileOffTheRecord())
return;
#if defined(OS_ANDROID)
BackgroundSyncLauncherAndroid::CancelBrowserWakeup(sync_type);
delegate_->CancelBrowserWakeup(sync_type);
#endif
}
int BackgroundSyncControllerImpl::GetSiteEngagementPenalty(const GURL& url) {
blink::mojom::EngagementLevel engagement_level =
site_engagement_service_->GetEngagementLevel(url);
if (engagement_level == blink::mojom::EngagementLevel::NONE) {
suspended_periodic_sync_origins_.insert(
url::Origin::Create(url.GetOrigin()));
}
switch (engagement_level) {
case blink::mojom::EngagementLevel::NONE:
// Suspend registration until site_engagement improves.
return kEngagementLevelNonePenalty;
case blink::mojom::EngagementLevel::MINIMAL:
return kEngagementLevelMinimalPenalty;
case blink::mojom::EngagementLevel::LOW:
case blink::mojom::EngagementLevel::MEDIUM:
return kEngagementLevelLowOrMediumPenalty;
case blink::mojom::EngagementLevel::HIGH:
case blink::mojom::EngagementLevel::MAX:
// Very few sites reach max engagement level.
return kEngagementLevelHighOrMaxPenalty;
}
NOTREACHED();
return kEngagementLevelNonePenalty;
return delegate_->GetSiteEngagementPenalty(url);
}
base::TimeDelta BackgroundSyncControllerImpl::SnapToMaxOriginFrequency(
......@@ -371,8 +305,7 @@ base::TimeDelta BackgroundSyncControllerImpl::ApplyMinGapForOrigin(
bool BackgroundSyncControllerImpl::IsContentSettingBlocked(
const url::Origin& origin) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
auto* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(profile_);
auto* host_content_settings_map = delegate_->GetHostContentSettingsMap();
DCHECK(host_content_settings_map);
auto url = origin.GetURL();
......@@ -385,9 +318,8 @@ bool BackgroundSyncControllerImpl::IsContentSettingBlocked(
void BackgroundSyncControllerImpl::Shutdown() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
HostContentSettingsMapFactory::GetForProfile(profile_)->RemoveObserver(this);
// Clear the profile as we're not supposed to use it anymore.
profile_ = nullptr;
delegate_->GetHostContentSettingsMap()->RemoveObserver(this);
delegate_->Shutdown();
}
base::TimeDelta BackgroundSyncControllerImpl::GetNextEventDelay(
......@@ -406,7 +338,7 @@ base::TimeDelta BackgroundSyncControllerImpl::GetNextEventDelay(
return base::TimeDelta();
case blink::mojom::BackgroundSyncType::PERIODIC:
int site_engagement_factor =
GetSiteEngagementPenalty(registration.origin().GetURL());
delegate_->GetSiteEngagementPenalty(registration.origin().GetURL());
if (!site_engagement_factor)
return base::TimeDelta::Max();
......@@ -451,10 +383,7 @@ BackgroundSyncControllerImpl::BackgroundSyncEventKeepAliveImpl::
void BackgroundSyncControllerImpl::NoteSuspendedPeriodicSyncOrigins(
std::set<url::Origin> suspended_origins) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
for (auto& origin : suspended_origins)
suspended_periodic_sync_origins_.insert(std::move(origin));
delegate_->NoteSuspendedPeriodicSyncOrigins(std::move(suspended_origins));
}
void BackgroundSyncControllerImpl::NoteRegisteredPeriodicSyncOrigins(
......
......@@ -14,7 +14,6 @@
#include "base/macros.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/engagement/site_engagement_observer.h"
#include "components/background_sync/background_sync_delegate.h"
#include "components/background_sync/background_sync_metrics.h"
#include "components/content_settings/core/browser/content_settings_observer.h"
......@@ -24,22 +23,19 @@
#include "content/public/browser/background_sync_registration.h"
#include "content/public/browser/browser_thread.h"
#include "third_party/blink/public/mojom/background_sync/background_sync.mojom-forward.h"
#include "url/gurl.h"
namespace content {
struct BackgroundSyncParameters;
class BrowserContext;
} // namespace content
namespace url {
class Origin;
} // namespace url
class Profile;
class SiteEngagementService;
class GURL;
class BackgroundSyncControllerImpl : public content::BackgroundSyncController,
public SiteEngagementObserver,
public KeyedService,
public content_settings::Observer {
public:
......@@ -56,11 +52,6 @@ class BackgroundSyncControllerImpl : public content::BackgroundSyncController,
static const char kMaxSyncEventDurationName[];
static const char kMinPeriodicSyncEventsInterval[];
static const int kEngagementLevelNonePenalty = 0;
static const int kEngagementLevelHighOrMaxPenalty = 1;
static const int kEngagementLevelLowOrMediumPenalty = 2;
static const int kEngagementLevelMinimalPenalty = 3;
#if !defined(OS_ANDROID)
class BackgroundSyncEventKeepAliveImpl : public BackgroundSyncEventKeepAlive {
public:
......@@ -73,7 +64,9 @@ class BackgroundSyncControllerImpl : public content::BackgroundSyncController,
};
#endif
explicit BackgroundSyncControllerImpl(Profile* profile);
BackgroundSyncControllerImpl(
content::BrowserContext* browser_context,
std::unique_ptr<background_sync::BackgroundSyncDelegate> delegate);
~BackgroundSyncControllerImpl() override;
// content::BackgroundSyncController overrides.
......@@ -114,13 +107,6 @@ class BackgroundSyncControllerImpl : public content::BackgroundSyncController,
void AddToTrackedOrigins(const url::Origin& origin) override;
void RemoveFromTrackedOrigins(const url::Origin& origin) override;
// SiteEngagementObserver overrides.
void OnEngagementEvent(
content::WebContents* web_contents,
const GURL& url,
double score,
SiteEngagementService::EngagementType engagement_type) override;
// content_settings::Observer overrides.
void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
......@@ -137,7 +123,7 @@ class BackgroundSyncControllerImpl : public content::BackgroundSyncController,
// the less often periodic sync events will be fired.
// Returns kEngagementLevelNonePenalty if the engagement level is
// blink::mojom::EngagementLevel::NONE.
int GetSiteEngagementPenalty(const GURL& url);
virtual int GetSiteEngagementPenalty(const GURL& url);
// Once we've identified the minimum number of hours between each periodicsync
// event for an origin, every delay calculated for the origin should be a
......@@ -157,16 +143,11 @@ class BackgroundSyncControllerImpl : public content::BackgroundSyncController,
// KeyedService implementation.
void Shutdown() override;
Profile* profile_; // This object is owned by profile_.
// Same lifetime as |profile_|.
SiteEngagementService* site_engagement_service_;
content::BrowserContext* browser_context_;
std::unique_ptr<background_sync::BackgroundSyncDelegate>
background_sync_delegate_;
std::unique_ptr<background_sync::BackgroundSyncDelegate> delegate_;
std::unique_ptr<BackgroundSyncMetrics> background_sync_metrics_;
std::set<url::Origin> suspended_periodic_sync_origins_;
std::set<url::Origin> periodic_sync_origins_;
DISALLOW_COPY_AND_ASSIGN(BackgroundSyncControllerImpl);
......
......@@ -9,6 +9,7 @@
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
#include "chrome/browser/background_sync/background_sync_delegate_impl.h"
#include "chrome/browser/engagement/site_engagement_score.h"
#include "chrome/browser/engagement/site_engagement_service.h"
#include "chrome/browser/history/history_service_factory.h"
......@@ -70,7 +71,8 @@ class BackgroundSyncControllerImplTest : public testing::Test {
HistoryServiceFactory::GetInstance()->SetTestingFactory(
&profile_, base::BindRepeating(&BuildTestHistoryService, sub_dir));
controller_ = std::make_unique<BackgroundSyncControllerImpl>(&profile_);
controller_ = std::make_unique<BackgroundSyncControllerImpl>(
&profile_, std::make_unique<BackgroundSyncDelegateImpl>(&profile_));
}
void ResetFieldTrialList() {
......@@ -256,7 +258,7 @@ TEST_F(BackgroundSyncControllerImplTest,
delay,
base::TimeDelta::FromMilliseconds(
min_gap_between_periodic_sync_events_ms *
BackgroundSyncControllerImpl::kEngagementLevelLowOrMediumPenalty));
BackgroundSyncDelegateImpl::kEngagementLevelLowOrMediumPenalty));
// Low engagement.
SiteEngagementService::Get(&profile_)->ResetBaseScoreForURL(
......@@ -268,7 +270,7 @@ TEST_F(BackgroundSyncControllerImplTest,
delay,
base::TimeDelta::FromMilliseconds(
min_gap_between_periodic_sync_events_ms *
BackgroundSyncControllerImpl::kEngagementLevelLowOrMediumPenalty));
BackgroundSyncDelegateImpl::kEngagementLevelLowOrMediumPenalty));
// Minimal engagement.
SiteEngagementService::Get(&profile_)->ResetBaseScoreForURL(GURL(kExampleUrl),
......@@ -278,7 +280,7 @@ TEST_F(BackgroundSyncControllerImplTest,
EXPECT_EQ(delay,
base::TimeDelta::FromMilliseconds(
min_gap_between_periodic_sync_events_ms *
BackgroundSyncControllerImpl::kEngagementLevelMinimalPenalty));
BackgroundSyncDelegateImpl::kEngagementLevelMinimalPenalty));
// No engagement.
SiteEngagementService::Get(&profile_)->ResetBaseScoreForURL(GURL(kExampleUrl),
......
......@@ -4,14 +4,31 @@
#include "chrome/browser/background_sync/background_sync_delegate_impl.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/engagement/site_engagement_service.h"
#include "chrome/browser/metrics/ukm_background_recorder_service.h"
#include "chrome/browser/profiles/profile.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "content/public/browser/background_sync_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "url/origin.h"
#if defined(OS_ANDROID)
#include "chrome/browser/android/background_sync_launcher_android.h"
#endif
BackgroundSyncDelegateImpl::BackgroundSyncDelegateImpl(Profile* profile)
: ukm_background_service_(
ukm::UkmBackgroundRecorderFactory::GetForProfile(profile)) {
: SiteEngagementObserver(SiteEngagementService::Get(profile)),
profile_(profile),
ukm_background_service_(
ukm::UkmBackgroundRecorderFactory::GetForProfile(profile)),
site_engagement_service_(SiteEngagementService::Get(profile)) {
DCHECK(profile_);
DCHECK(ukm_background_service_);
DCHECK(site_engagement_service_);
off_the_record_ = profile_->IsOffTheRecord();
}
BackgroundSyncDelegateImpl::~BackgroundSyncDelegateImpl() = default;
......@@ -22,3 +39,102 @@ void BackgroundSyncDelegateImpl::GetUkmSourceId(
ukm_background_service_->GetBackgroundSourceIdIfAllowed(origin,
std::move(callback));
}
void BackgroundSyncDelegateImpl::Shutdown() {
// Clear the profile as we're not supposed to use it anymore.
profile_ = nullptr;
}
HostContentSettingsMap*
BackgroundSyncDelegateImpl::GetHostContentSettingsMap() {
return HostContentSettingsMapFactory::GetForProfile(profile_);
}
bool BackgroundSyncDelegateImpl::IsProfileOffTheRecord() {
return off_the_record_;
}
void BackgroundSyncDelegateImpl::NoteSuspendedPeriodicSyncOrigins(
std::set<url::Origin> suspended_origins) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
for (auto& origin : suspended_origins)
suspended_periodic_sync_origins_.insert(std::move(origin));
}
int BackgroundSyncDelegateImpl::GetSiteEngagementPenalty(const GURL& url) {
blink::mojom::EngagementLevel engagement_level =
site_engagement_service_->GetEngagementLevel(url);
if (engagement_level == blink::mojom::EngagementLevel::NONE) {
suspended_periodic_sync_origins_.insert(
url::Origin::Create(url.GetOrigin()));
}
switch (engagement_level) {
case blink::mojom::EngagementLevel::NONE:
// Suspend registration until site_engagement improves.
return kEngagementLevelNonePenalty;
case blink::mojom::EngagementLevel::MINIMAL:
return kEngagementLevelMinimalPenalty;
case blink::mojom::EngagementLevel::LOW:
case blink::mojom::EngagementLevel::MEDIUM:
return kEngagementLevelLowOrMediumPenalty;
case blink::mojom::EngagementLevel::HIGH:
case blink::mojom::EngagementLevel::MAX:
// Very few sites reach max engagement level.
return kEngagementLevelHighOrMaxPenalty;
}
NOTREACHED();
return kEngagementLevelNonePenalty;
}
#if defined(OS_ANDROID)
void BackgroundSyncDelegateImpl::ScheduleBrowserWakeUpWithDelay(
blink::mojom::BackgroundSyncType sync_type,
base::TimeDelta delay) {
BackgroundSyncLauncherAndroid::ScheduleBrowserWakeUpWithDelay(sync_type,
delay);
}
void BackgroundSyncDelegateImpl::CancelBrowserWakeup(
blink::mojom::BackgroundSyncType sync_type) {
BackgroundSyncLauncherAndroid::CancelBrowserWakeup(sync_type);
}
bool BackgroundSyncDelegateImpl::ShouldDisableBackgroundSync() {
return BackgroundSyncLauncherAndroid::ShouldDisableBackgroundSync();
}
#endif // defined(OS_ANDROID)
void BackgroundSyncDelegateImpl::OnEngagementEvent(
content::WebContents* web_contents,
const GURL& url,
double score,
SiteEngagementService::EngagementType engagement_type) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (score == 0.0)
return;
auto origin = url::Origin::Create(url);
auto iter = suspended_periodic_sync_origins_.find(origin);
if (iter == suspended_periodic_sync_origins_.end())
return;
suspended_periodic_sync_origins_.erase(iter);
auto* storage_partition = content::BrowserContext::GetStoragePartitionForSite(
profile_, url, /* can_create= */ false);
if (!storage_partition)
return;
auto* background_sync_context = storage_partition->GetBackgroundSyncContext();
if (!background_sync_context)
return;
background_sync_context->RevivePeriodicBackgroundSyncRegistrations(
std::move(origin));
}
......@@ -5,31 +5,64 @@
#ifndef CHROME_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_DELEGATE_IMPL_H_
#define CHROME_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_DELEGATE_IMPL_H_
#include <set>
#include "build/build_config.h"
#include "chrome/browser/engagement/site_engagement_observer.h"
#include "components/background_sync/background_sync_delegate.h"
#include "url/origin.h"
class Profile;
class HostContentSettingsMap;
namespace ukm {
class UkmBackgroundRecorderService;
} // namespace ukm
namespace url {
class Origin;
} // namespace url
// Chrome's customization of the logic in components/background_sync
class BackgroundSyncDelegateImpl
: public background_sync::BackgroundSyncDelegate {
: public background_sync::BackgroundSyncDelegate,
public SiteEngagementObserver {
public:
static const int kEngagementLevelNonePenalty = 0;
static const int kEngagementLevelHighOrMaxPenalty = 1;
static const int kEngagementLevelLowOrMediumPenalty = 2;
static const int kEngagementLevelMinimalPenalty = 3;
explicit BackgroundSyncDelegateImpl(Profile* profile);
~BackgroundSyncDelegateImpl() override;
void GetUkmSourceId(const url::Origin& origin,
base::OnceCallback<void(base::Optional<ukm::SourceId>)>
callback) override;
void Shutdown() override;
HostContentSettingsMap* GetHostContentSettingsMap() override;
bool IsProfileOffTheRecord() override;
void NoteSuspendedPeriodicSyncOrigins(
std::set<url::Origin> suspended_origins) override;
int GetSiteEngagementPenalty(const GURL& url) override;
#if defined(OS_ANDROID)
void ScheduleBrowserWakeUpWithDelay(
blink::mojom::BackgroundSyncType sync_type,
base::TimeDelta delay) override;
void CancelBrowserWakeup(blink::mojom::BackgroundSyncType sync_type) override;
bool ShouldDisableBackgroundSync() override;
#endif // defined(OS_ANDROID)
// SiteEngagementObserver overrides.
void OnEngagementEvent(
content::WebContents* web_contents,
const GURL& url,
double score,
SiteEngagementService::EngagementType engagement_type) override;
private:
Profile* profile_;
bool off_the_record_;
ukm::UkmBackgroundRecorderService* ukm_background_service_;
// Same lifetime as |profile_|.
SiteEngagementService* site_engagement_service_;
std::set<url::Origin> suspended_periodic_sync_origins_;
};
#endif // CHROME_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_DELEGATE_IMPL_H_
......@@ -5,13 +5,19 @@
#ifndef COMPONENTS_BACKGROUND_SYNC_BACKGROUND_SYNC_DELEGATE_H_
#define COMPONENTS_BACKGROUND_SYNC_BACKGROUND_SYNC_DELEGATE_H_
#include <set>
#include "base/callback.h"
#include "base/optional.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "third_party/blink/public/mojom/background_sync/background_sync.mojom-forward.h"
#include "url/origin.h"
class HostContentSettingsMap;
namespace url {
class Origin;
} // namespace url
class GURL;
namespace background_sync {
......@@ -26,6 +32,38 @@ class BackgroundSyncDelegate {
virtual void GetUkmSourceId(
const url::Origin& origin,
base::OnceCallback<void(base::Optional<ukm::SourceId>)> callback) = 0;
// Handles browser shutdown.
virtual void Shutdown() = 0;
// Returns the content settings map.
virtual HostContentSettingsMap* GetHostContentSettingsMap() = 0;
// Returns true if the profile associated with the delegate is off-the-record.
virtual bool IsProfileOffTheRecord() = 0;
// Notes the origins for which Periodic Background Sync is suspended.
virtual void NoteSuspendedPeriodicSyncOrigins(
std::set<url::Origin> suspended_origins) = 0;
// Gets the site engagement penalty to add to the Periodic Background Sync
// interval for the origin corresponding to |url|.
virtual int GetSiteEngagementPenalty(const GURL& url) = 0;
#if defined(OS_ANDROID)
// Schedules the browser to be woken up when the device is online to process
// registrations of type |sync| after a minimum delay |delay|.
virtual void ScheduleBrowserWakeUpWithDelay(
blink::mojom::BackgroundSyncType sync_type,
base::TimeDelta delay) = 0;
// Cancels browser wakeup for registrations of type |sync_type|.
virtual void CancelBrowserWakeup(
blink::mojom::BackgroundSyncType sync_type) = 0;
// Whether Background Sync should be disabled.
virtual bool ShouldDisableBackgroundSync() = 0;
#endif
};
} // namespace background_sync
......
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