#ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_REGISTRATION_NOTIFIER_H_
#define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_REGISTRATION_NOTIFIER_H_
#include <stdint.h>
#include <map>
#include <string>
#include "base/memory/weak_ptr.h"
#include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/background_fetch/background_fetch.mojom.h"
namespace content {
class CONTENT_EXPORT BackgroundFetchRegistrationNotifier {
public:
BackgroundFetchRegistrationNotifier();
BackgroundFetchRegistrationNotifier(
const BackgroundFetchRegistrationNotifier&) = delete;
BackgroundFetchRegistrationNotifier& operator=(
const BackgroundFetchRegistrationNotifier&) = delete;
~BackgroundFetchRegistrationNotifier();
void AddObserver(
const std::string& unique_id,
mojo::PendingRemote<blink::mojom::BackgroundFetchRegistrationObserver>
observer);
void Notify(
const std::string& unique_id,
const blink::mojom::BackgroundFetchRegistrationData& registration_data);
void NotifyRecordsUnavailable(const std::string& unique_id);
void NotifyRequestCompleted(const std::string& unique_id,
blink::mojom::FetchAPIRequestPtr request,
blink::mojom::FetchAPIResponsePtr response);
void AddObservedUrl(const std::string& unique_id, const GURL& url);
base::WeakPtr<BackgroundFetchRegistrationNotifier> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
private:
void OnConnectionError(
const std::string& unique_id,
blink::mojom::BackgroundFetchRegistrationObserver* observer);
std::multimap<std::string,
mojo::Remote<blink::mojom::BackgroundFetchRegistrationObserver>>
observers_;
std::map<std::string, std::set<GURL>> observed_urls_;
base::WeakPtrFactory<BackgroundFetchRegistrationNotifier> weak_factory_{this};
};
}
#endif