#ifndef SERVICES_NETWORK_DEVICE_BOUND_SESSION_MANAGER_H_
#define SERVICES_NETWORK_DEVICE_BOUND_SESSION_MANAGER_H_
#include <vector>
#include "base/callback_list.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/device_bound_sessions/session_error.h"
#include "services/network/public/mojom/device_bound_sessions.mojom.h"
namespace net::device_bound_sessions {
class SessionService;
struct SessionKey;
}
namespace network {
class CookieManager;
class COMPONENT_EXPORT(NETWORK_SERVICE) DeviceBoundSessionManager
: public mojom::DeviceBoundSessionManager {
public:
static std::unique_ptr<DeviceBoundSessionManager> Create(
net::device_bound_sessions::SessionService* service,
CookieManager* cookie_manager);
~DeviceBoundSessionManager() override;
void AddReceiver(
mojo::PendingReceiver<mojom::DeviceBoundSessionManager> receiver);
void GetAllSessions(GetAllSessionsCallback callback) override;
void DeleteSession(
net::device_bound_sessions::DeletionReason reason,
const net::device_bound_sessions::SessionKey& session_key) override;
void DeleteAllSessions(net::device_bound_sessions::DeletionReason reason,
std::optional<base::Time> created_after_time,
std::optional<base::Time> created_before_time,
network::mojom::ClearDataFilterPtr filter,
base::OnceClosure completion_callback) override;
void AddObserver(
const GURL& url,
mojo::PendingRemote<network::mojom::DeviceBoundSessionAccessObserver>
observer) override;
void CreateBoundSessions(
std::vector<net::device_bound_sessions::SessionParams> params,
const std::vector<uint8_t>& wrapped_key,
const std::vector<net::CanonicalCookie>& cookies_to_set,
const net::CookieOptions& cookie_options,
CreateBoundSessionsCallback callback) override;
private:
struct ObserverRegistration {
ObserverRegistration();
~ObserverRegistration();
mojo::Remote<network::mojom::DeviceBoundSessionAccessObserver> remote;
base::ScopedClosureRunner subscription;
};
explicit DeviceBoundSessionManager(
net::device_bound_sessions::SessionService* service,
CookieManager* cookie_manager);
void RemoveObserver(ObserverRegistration* registration);
void OnCreateBoundSessionsAdded(
const std::vector<net::CanonicalCookie>& cookies_to_set,
const net::CookieOptions& cookie_options,
CreateBoundSessionsCallback callback,
std::vector<net::device_bound_sessions::SessionError::ErrorType>
session_errors);
raw_ptr<net::device_bound_sessions::SessionService> service_;
raw_ptr<CookieManager> cookie_manager_;
mojo::ReceiverSet<network::mojom::DeviceBoundSessionManager> receivers_;
std::vector<std::unique_ptr<ObserverRegistration>> observer_registrations_;
base::WeakPtrFactory<DeviceBoundSessionManager> weak_factory_{this};
};
}
#endif