#include "device/vr/orientation/orientation_session.h"
#include <utility>
#include "base/functional/bind.h"
#include "device/vr/orientation/orientation_device.h"
namespace device {
VROrientationSession::VROrientationSession(
VROrientationDevice* device,
mojo::PendingReceiver<mojom::XRFrameDataProvider> magic_window_receiver,
mojo::PendingReceiver<mojom::XRSessionController> session_receiver)
: magic_window_receiver_(this, std::move(magic_window_receiver)),
session_controller_receiver_(this, std::move(session_receiver)),
device_(device) {
magic_window_receiver_.set_disconnect_handler(
base::BindOnce(&VROrientationSession::OnMojoConnectionError,
weak_ptr_factory_.GetWeakPtr()));
session_controller_receiver_.set_disconnect_handler(
base::BindOnce(&VROrientationSession::OnMojoConnectionError,
weak_ptr_factory_.GetWeakPtr()));
}
VROrientationSession::~VROrientationSession() = default;
void VROrientationSession::GetFrameData(
mojom::XRFrameDataRequestOptionsPtr options,
mojom::XRFrameDataProvider::GetFrameDataCallback callback) {
DCHECK(!device_->HasExclusiveSession());
if (restrict_frame_data_) {
std::move(callback).Run(nullptr);
return;
}
device_->GetInlineFrameData(std::move(callback));
}
void VROrientationSession::GetEnvironmentIntegrationProvider(
mojo::PendingAssociatedReceiver<mojom::XREnvironmentIntegrationProvider>
environment_provider) {
magic_window_receiver_.ReportBadMessage(
"Environment integration is not supported.");
}
void VROrientationSession::SetFrameDataRestricted(bool frame_data_restricted) {
restrict_frame_data_ = frame_data_restricted;
}
void VROrientationSession::OnMojoConnectionError() {
magic_window_receiver_.reset();
session_controller_receiver_.reset();
device_->EndMagicWindowSession(this);
}
}