#include "weblayer/browser/background_sync/background_sync_delegate_impl.h"
#include "build/build_config.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/web_contents.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "weblayer/browser/host_content_settings_map_factory.h"
namespace weblayer {
BackgroundSyncDelegateImpl::BackgroundSyncDelegateImpl(
content::BrowserContext* browser_context)
: browser_context_(browser_context) {
DCHECK(browser_context_);
}
BackgroundSyncDelegateImpl::~BackgroundSyncDelegateImpl() = default;
#if !BUILDFLAG(IS_ANDROID)
std::unique_ptr<content::BackgroundSyncController::BackgroundSyncEventKeepAlive>
BackgroundSyncDelegateImpl::CreateBackgroundSyncEventKeepAlive() {
return nullptr;
}
#endif
void BackgroundSyncDelegateImpl::GetUkmSourceId(
const url::Origin& origin,
base::OnceCallback<void(absl::optional<ukm::SourceId>)> callback) {
ukm::SourceId source_id = ukm::ConvertToSourceId(
ukm::AssignNewSourceId(), ukm::SourceIdType::HISTORY_ID);
ukm::UkmRecorder* recorder = ukm::UkmRecorder::Get();
DCHECK(recorder);
recorder->UpdateSourceURL(source_id, origin.GetURL());
std::move(callback).Run(source_id);
}
void BackgroundSyncDelegateImpl::Shutdown() {
browser_context_ = nullptr;
}
HostContentSettingsMap*
BackgroundSyncDelegateImpl::GetHostContentSettingsMap() {
return HostContentSettingsMapFactory::GetForBrowserContext(browser_context_);
}
bool BackgroundSyncDelegateImpl::IsProfileOffTheRecord() {
DCHECK(browser_context_);
return browser_context_->IsOffTheRecord();
}
void BackgroundSyncDelegateImpl::NoteSuspendedPeriodicSyncOrigins(
std::set<url::Origin> suspended_origins) {
}
int BackgroundSyncDelegateImpl::GetSiteEngagementPenalty(const GURL& url) {
return 0;
}
#if BUILDFLAG(IS_ANDROID)
void BackgroundSyncDelegateImpl::ScheduleBrowserWakeUpWithDelay(
blink::mojom::BackgroundSyncType sync_type,
base::TimeDelta delay) {
}
void BackgroundSyncDelegateImpl::CancelBrowserWakeup(
blink::mojom::BackgroundSyncType sync_type) {
}
bool BackgroundSyncDelegateImpl::ShouldDisableBackgroundSync() {
return false;
}
bool BackgroundSyncDelegateImpl::ShouldDisableAndroidNetworkDetection() {
return true;
}
#endif
}