#ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_SERVICE_IMPL_H_
#define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_SERVICE_IMPL_H_
#include <string>
#include <utility>
#include <vector>
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h"
#include "content/browser/background_fetch/background_fetch_context.h"
#include "content/common/content_export.h"
#include "net/base/isolation_info.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/background_fetch/background_fetch.mojom.h"
namespace net {
class NetworkAnonymizationKey;
}
namespace content {
struct ServiceWorkerVersionBaseInfo;
class CONTENT_EXPORT BackgroundFetchServiceImpl
: public blink::mojom::BackgroundFetchService {
public:
BackgroundFetchServiceImpl(
scoped_refptr<BackgroundFetchContext> background_fetch_context,
blink::StorageKey storage_key,
net::IsolationInfo isolation_info,
RenderProcessHost* rph,
RenderFrameHostImpl* rfh);
BackgroundFetchServiceImpl(const BackgroundFetchServiceImpl&) = delete;
BackgroundFetchServiceImpl& operator=(const BackgroundFetchServiceImpl&) =
delete;
~BackgroundFetchServiceImpl() override;
static void CreateForWorker(
const net::NetworkIsolationKey& network_isolation_key,
const ServiceWorkerVersionBaseInfo& info,
mojo::PendingReceiver<blink::mojom::BackgroundFetchService> receiver);
static void CreateForFrame(
RenderFrameHost* render_frame_host,
mojo::PendingReceiver<blink::mojom::BackgroundFetchService> receiver);
void Fetch(int64_t service_worker_registration_id,
const std::string& developer_id,
std::vector<blink::mojom::FetchAPIRequestPtr> requests,
blink::mojom::BackgroundFetchOptionsPtr options,
const SkBitmap& icon,
blink::mojom::BackgroundFetchUkmDataPtr ukm_data,
FetchCallback callback) override;
void GetIconDisplaySize(GetIconDisplaySizeCallback callback) override;
void GetRegistration(int64_t service_worker_registration_id,
const std::string& developer_id,
GetRegistrationCallback callback) override;
void GetDeveloperIds(int64_t service_worker_registration_id,
GetDeveloperIdsCallback callback) override;
private:
[[nodiscard]] bool ValidateDeveloperId(const std::string& developer_id);
[[nodiscard]] bool ValidateUniqueId(const std::string& unique_id);
[[nodiscard]] bool ValidateRequests(
const std::vector<blink::mojom::FetchAPIRequestPtr>& requests);
scoped_refptr<BackgroundFetchContext> background_fetch_context_;
const blink::StorageKey storage_key_;
net::IsolationInfo isolation_info_;
int rph_id_;
GlobalRenderFrameHostId rfh_id_;
SEQUENCE_CHECKER(sequence_checker_);
};
}
#endif