#include "content/browser/background_fetch/background_fetch_scheduler.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/metrics/field_trial_params.h"
#include "base/not_fatal_until.h"
#include "base/strings/string_number_conversions.h"
#include "content/browser/background_fetch/background_fetch_data_manager.h"
#include "content/browser/background_fetch/background_fetch_delegate_proxy.h"
#include "content/browser/background_fetch/background_fetch_job_controller.h"
#include "content/browser/background_fetch/background_fetch_registration_notifier.h"
#include "content/browser/background_fetch/background_fetch_registration_service_impl.h"
#include "content/browser/devtools/devtools_background_services_context_impl.h"
#include "content/browser/service_worker/service_worker_context_core_observer.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/public/common/content_features.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_response.mojom.h"
namespace content {
namespace {
constexpr char kMaxActiveRegistrations[] = …;
constexpr int kMaxActiveRegistrationsDefaultValue = …;
constexpr char kMaxRunningDownloads[] = …;
constexpr int kMaxRunningDownloadsDefaultValue = …;
}
BackgroundFetchError;
BackgroundFetchFailureReason;
enum class BackgroundFetchScheduler::Event { … };
BackgroundFetchScheduler::BackgroundFetchScheduler(
BackgroundFetchContext* background_fetch_context,
BackgroundFetchDataManager* data_manager,
BackgroundFetchRegistrationNotifier* registration_notifier,
BackgroundFetchDelegateProxy* delegate_proxy,
DevToolsBackgroundServicesContextImpl& devtools_context,
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context)
: … { … }
BackgroundFetchScheduler::~BackgroundFetchScheduler() = default;
BackgroundFetchScheduler::RegistrationData::RegistrationData(
const BackgroundFetchRegistrationId& registration_id,
blink::mojom::BackgroundFetchRegistrationDataPtr registration)
: … { … }
BackgroundFetchScheduler::RegistrationData::~RegistrationData() = default;
bool BackgroundFetchScheduler::ScheduleDownload() { … }
void BackgroundFetchScheduler::Abort(
const BackgroundFetchRegistrationId& registration_id,
BackgroundFetchFailureReason failure_reason,
blink::mojom::BackgroundFetchRegistrationService::AbortCallback callback) { … }
void BackgroundFetchScheduler::DidStartRequest(
const BackgroundFetchRegistrationId& registration_id,
const BackgroundFetchRequestInfo* request_info) { … }
void BackgroundFetchScheduler::DidCompleteRequest(
const BackgroundFetchRegistrationId& registration_id,
scoped_refptr<BackgroundFetchRequestInfo> request_info) { … }
void BackgroundFetchScheduler::FinishJob(
const BackgroundFetchRegistrationId& registration_id,
BackgroundFetchFailureReason failure_reason,
base::OnceCallback<void(BackgroundFetchError)> callback) { … }
void BackgroundFetchScheduler::DidMarkForDeletion(
const BackgroundFetchRegistrationId& registration_id,
bool job_started,
base::OnceCallback<void(BackgroundFetchError)> callback,
BackgroundFetchError error,
BackgroundFetchFailureReason failure_reason) { … }
void BackgroundFetchScheduler::CleanupRegistration(
const BackgroundFetchRegistrationId& registration_id) { … }
void BackgroundFetchScheduler::DispatchClickEvent(
const std::string& unique_id) { … }
std::unique_ptr<BackgroundFetchJobController>
BackgroundFetchScheduler::CreateInitializedController(
const BackgroundFetchRegistrationId& registration_id,
const blink::mojom::BackgroundFetchRegistrationData& registration_data,
blink::mojom::BackgroundFetchOptionsPtr options,
const SkBitmap& icon,
int num_completed_requests,
int num_requests,
std::vector<scoped_refptr<BackgroundFetchRequestInfo>>
active_fetch_requests,
bool start_paused,
std::optional<net::IsolationInfo> isolation_info) { … }
void BackgroundFetchScheduler::OnRegistrationCreated(
const BackgroundFetchRegistrationId& registration_id,
const blink::mojom::BackgroundFetchRegistrationData& registration_data,
blink::mojom::BackgroundFetchOptionsPtr options,
const SkBitmap& icon,
int num_requests,
bool start_paused,
net::IsolationInfo isolation_info) { … }
void BackgroundFetchScheduler::OnRegistrationLoadedAtStartup(
const BackgroundFetchRegistrationId& registration_id,
const blink::mojom::BackgroundFetchRegistrationData& registration_data,
blink::mojom::BackgroundFetchOptionsPtr options,
const SkBitmap& icon,
int num_completed_requests,
int num_requests,
std::vector<scoped_refptr<BackgroundFetchRequestInfo>>
active_fetch_requests,
std::optional<net::IsolationInfo> isolation_info) { … }
void BackgroundFetchScheduler::OnRequestCompleted(
const std::string& unique_id,
blink::mojom::FetchAPIRequestPtr request,
blink::mojom::FetchAPIResponsePtr response) { … }
void BackgroundFetchScheduler::AbortFetches(
int64_t service_worker_registration_id) { … }
void BackgroundFetchScheduler::OnRegistrationQueried(
const BackgroundFetchRegistrationId& registration_id,
blink::mojom::BackgroundFetchRegistrationData* registration_data) { … }
void BackgroundFetchScheduler::OnServiceWorkerDatabaseCorrupted(
int64_t service_worker_registration_id) { … }
void BackgroundFetchScheduler::OnRegistrationDeleted(
int64_t registration_id,
const GURL& pattern,
const blink::StorageKey& key) { … }
void BackgroundFetchScheduler::OnStorageWiped() { … }
BackgroundFetchJobController* BackgroundFetchScheduler::GetActiveController(
const BackgroundFetchRegistrationId& registration_id) { … }
BackgroundFetchJobController* BackgroundFetchScheduler::GetActiveController(
const std::string& unique_id) { … }
void BackgroundFetchScheduler::LogBackgroundFetchEventForDevTools(
Event event,
const BackgroundFetchRegistrationId& registration_id,
const BackgroundFetchRequestInfo* request_info,
std::map<std::string, std::string> metadata) { … }
void BackgroundFetchScheduler::Shutdown() { … }
}