Commit 38493bc3 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Convert XRSessionController to new Mojo types

This CL converts XRSessionController{Ptr, Request} in chrome and
device to the new Mojo type, and use
pending_remote<XRSessionController> in isolated_xr_service.mojom.

This CL also remove unnecessary InterfaceSet and it is replaced
with RemoteSet.

Bug: 955171, 965668
Change-Id: I388f1be9010b6c91a0f1fa00bfc719accd457f66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1846418
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Reviewed-by: default avatarPiotr Bialecki <bialpio@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#704562}
parent 604c46fc
......@@ -157,7 +157,7 @@ void ArCoreDevice::RequestSession(
if (session_state_->pending_request_session_callback_) {
DVLOG(1) << __func__ << ": Rejecting additional session request";
std::move(callback).Run(nullptr, nullptr);
std::move(callback).Run(nullptr, mojo::NullRemote());
return;
}
session_state_->pending_request_session_callback_ = std::move(callback);
......@@ -286,7 +286,7 @@ void ArCoreDevice::CallDeferredRequestSessionCallback(bool success) {
std::move(session_state_->pending_request_session_callback_);
if (!success) {
std::move(deferred_callback).Run(nullptr, nullptr);
std::move(deferred_callback).Run(nullptr, mojo::NullRemote());
return;
}
......@@ -311,7 +311,7 @@ void ArCoreDevice::OnCreateSessionCallback(
mojom::XRRuntime::RequestSessionCallback deferred_callback,
mojo::PendingRemote<mojom::XRFrameDataProvider> frame_data_provider,
mojom::VRDisplayInfoPtr display_info,
mojom::XRSessionControllerPtrInfo session_controller_info,
mojo::PendingRemote<mojom::XRSessionController> session_controller,
mojom::XRPresentationConnectionPtr presentation_connection) {
DVLOG(2) << __func__;
DCHECK(IsOnMainThread());
......@@ -321,9 +321,8 @@ void ArCoreDevice::OnCreateSessionCallback(
session->display_info = std::move(display_info);
session->submit_frame_sink = std::move(presentation_connection);
mojom::XRSessionControllerPtr controller(std::move(session_controller_info));
std::move(deferred_callback).Run(std::move(session), std::move(controller));
std::move(deferred_callback)
.Run(std::move(session), std::move(session_controller));
}
void ArCoreDevice::PostTaskToGlThread(base::OnceClosure task) {
......
......@@ -97,7 +97,7 @@ class ArCoreDevice : public VRDeviceBase {
mojom::XRRuntime::RequestSessionCallback deferred_callback,
mojo::PendingRemote<mojom::XRFrameDataProvider> frame_data_provider,
mojom::VRDisplayInfoPtr display_info,
mojom::XRSessionControllerPtrInfo session_controller_info,
mojo::PendingRemote<mojom::XRSessionController> session_controller,
mojom::XRPresentationConnectionPtr presentation_connection);
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
......
......@@ -18,6 +18,7 @@
#include "device/vr/public/mojom/vr_service.mojom.h"
#include "device/vr/test/fake_vr_device.h"
#include "device/vr/test/fake_vr_service_client.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -123,11 +124,12 @@ class ArCoreDeviceTest : public testing::Test {
ArCoreDeviceTest() {}
~ArCoreDeviceTest() override {}
void OnSessionCreated(mojom::XRSessionPtr session,
mojom::XRSessionControllerPtr controller) {
void OnSessionCreated(
mojom::XRSessionPtr session,
mojo::PendingRemote<mojom::XRSessionController> controller) {
DVLOG(1) << __func__;
session_ = std::move(session);
controller_ = std::move(controller);
controller_.Bind(std::move(controller));
// TODO(crbug.com/837834): verify that things fail if restricted.
// We should think through the right result here for javascript.
// If an AR page tries to hittest while not focused, should it
......@@ -211,7 +213,7 @@ class ArCoreDeviceTest : public testing::Test {
private:
std::unique_ptr<ArCoreDevice> device_;
mojom::XRSessionPtr session_;
mojom::XRSessionControllerPtr controller_;
mojo::Remote<mojom::XRSessionController> controller_;
};
TEST_F(ArCoreDeviceTest, RequestSession) {
......
......@@ -104,7 +104,6 @@ ArCoreGl::ArCoreGl(std::unique_ptr<ArImageTransport> ar_image_transport)
: gl_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
ar_image_transport_(std::move(ar_image_transport)),
webxr_(std::make_unique<vr::WebXrPresentationState>()),
session_controller_binding_(this),
environment_binding_(this) {
DVLOG(1) << __func__;
webxr_transform_ = WebXRImageTransformMatrix();
......@@ -176,11 +175,6 @@ void ArCoreGl::CreateSession(mojom::VRDisplayInfoPtr display_info,
CloseBindingsIfOpen();
mojom::XRSessionControllerPtrInfo controller_info;
session_controller_binding_.Bind(mojo::MakeRequest(&controller_info));
session_controller_binding_.set_connection_error_handler(base::BindOnce(
&ArCoreGl::OnBindingDisconnect, weak_ptr_factory_.GetWeakPtr()));
device::mojom::XRPresentationTransportOptionsPtr transport_options =
device::mojom::XRPresentationTransportOptions::New();
transport_options->wait_for_gpu_fence = true;
......@@ -203,11 +197,14 @@ void ArCoreGl::CreateSession(mojom::VRDisplayInfoPtr display_info,
std::move(create_callback)
.Run(frame_data_receiver_.BindNewPipeAndPassRemote(),
display_info_->Clone(), std::move(controller_info),
display_info_->Clone(),
session_controller_receiver_.BindNewPipeAndPassRemote(),
std::move(submit_frame_sink));
frame_data_receiver_.set_disconnect_handler(base::BindOnce(
&ArCoreGl::OnBindingDisconnect, weak_ptr_factory_.GetWeakPtr()));
session_controller_receiver_.set_disconnect_handler(base::BindOnce(
&ArCoreGl::OnBindingDisconnect, weak_ptr_factory_.GetWeakPtr()));
}
bool ArCoreGl::InitializeGl(gfx::AcceleratedWidget drawing_widget) {
......@@ -805,7 +802,7 @@ void ArCoreGl::CloseBindingsIfOpen() {
environment_binding_.Close();
frame_data_receiver_.reset();
session_controller_binding_.Close();
session_controller_receiver_.reset();
presentation_receiver_.reset();
}
......
......@@ -18,7 +18,6 @@
#include "device/vr/public/mojom/vr_service.mojom.h"
#include "device/vr/util/fps_meter.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
......@@ -53,7 +52,7 @@ class ArImageTransport;
using ArCoreGlCreateSessionCallback = base::OnceCallback<void(
mojo::PendingRemote<mojom::XRFrameDataProvider> frame_data_provider,
mojom::VRDisplayInfoPtr display_info,
mojom::XRSessionControllerPtrInfo session_controller_info,
mojo::PendingRemote<mojom::XRSessionController> session_controller,
mojom::XRPresentationConnectionPtr presentation_connection)>;
// All of this class's methods must be called on the same valid GL thread with
......@@ -203,7 +202,7 @@ class ArCoreGl : public mojom::XRFrameDataProvider,
std::vector<std::unique_ptr<ArCoreHitTestRequest>> hit_test_requests_;
mojo::Receiver<mojom::XRFrameDataProvider> frame_data_receiver_{this};
mojo::Binding<mojom::XRSessionController> session_controller_binding_;
mojo::Receiver<mojom::XRSessionController> session_controller_receiver_{this};
mojo::AssociatedBinding<mojom::XREnvironmentIntegrationProvider>
environment_binding_;
......
......@@ -243,7 +243,6 @@ component("vr_common") {
"service/browser_xr_runtime.h",
"service/gvr_consent_helper.cc",
"service/gvr_consent_helper.h",
"service/interface_set.h",
"service/vr_service_impl.cc",
"service/vr_service_impl.h",
"service/xr_device_service.cc",
......
......@@ -372,7 +372,7 @@ void BrowserXRRuntime::OnDisplayInfoChanged(
void BrowserXRRuntime::StopImmersiveSession() {
if (immersive_session_controller_) {
immersive_session_controller_ = nullptr;
immersive_session_controller_.reset();
presenting_service_ = nullptr;
for (BrowserXRRuntimeObserver& observer : observers_) {
......@@ -471,12 +471,14 @@ void BrowserXRRuntime::OnRequestSessionResult(
device::mojom::XRRuntimeSessionOptionsPtr options,
RequestSessionCallback callback,
device::mojom::XRSessionPtr session,
device::mojom::XRSessionControllerPtr immersive_session_controller) {
mojo::PendingRemote<device::mojom::XRSessionController>
immersive_session_controller) {
if (session && service) {
if (options->immersive) {
presenting_service_ = service.get();
immersive_session_controller_ = std::move(immersive_session_controller);
immersive_session_controller_.set_connection_error_handler(base::BindOnce(
immersive_session_controller_.Bind(
std::move(immersive_session_controller));
immersive_session_controller_.set_disconnect_handler(base::BindOnce(
&BrowserXRRuntime::OnImmersiveSessionError, base::Unretained(this)));
// Notify observers that we have started presentation.
......@@ -492,7 +494,8 @@ void BrowserXRRuntime::OnRequestSessionResult(
if (session) {
// The service has been removed, but we still got a session, so make
// sure to clean up this weird state.
immersive_session_controller_ = std::move(immersive_session_controller);
immersive_session_controller_.Bind(
std::move(immersive_session_controller));
StopImmersiveSession();
}
}
......
......@@ -15,6 +15,8 @@
#include "device/vr/public/mojom/vr_service.mojom.h"
#include "device/vr/vr_device.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace content {
class WebContents;
......@@ -111,13 +113,15 @@ class BrowserXRRuntime : public device::mojom::XRRuntimeEventListener {
device::mojom::XRRuntimeSessionOptionsPtr options,
RequestSessionCallback callback,
device::mojom::XRSessionPtr session,
device::mojom::XRSessionControllerPtr immersive_session_controller);
mojo::PendingRemote<device::mojom::XRSessionController>
immersive_session_controller);
void OnImmersiveSessionError();
void OnInitialized();
device::mojom::XRDeviceId id_;
device::mojom::XRRuntimePtr runtime_;
device::mojom::XRSessionControllerPtr immersive_session_controller_;
mojo::Remote<device::mojom::XRSessionController>
immersive_session_controller_;
std::set<VRServiceImpl*> services_;
device::mojom::VRDisplayInfoPtr display_info_;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_VR_SERVICE_INTERFACE_SET_H_
#define CHROME_BROWSER_VR_SERVICE_INTERFACE_SET_H_
#include <set>
#include "base/bind.h"
#include "base/callback.h"
namespace vr {
// Class used to store mojo InterfacePtrs. It will auto-manage its contents
// (ex. on connection error, the InterfacePtr will be removed from the set).
// The class is heavily based on mojo::InterfacePtrSet, but because
// mojo::InterfacePtrSet does not notify on removal of the interface from the
// collection, it cannot be used for some of the scenarios.
// TODO(https://crbug.com/965668) - remove this class and use InterfacePtrSet
// once it starts exposing required functionality.
template <typename InterfacePtr>
class InterfaceSet {
public:
~InterfaceSet() {
for (auto& it : interface_ptrs_) {
it.second.reset();
}
}
// Add |interface_ptr| to the set. Returns id that can be used to identify
// added pointer. The error handler that might have been registered on
// |interface_ptr| will be replaced. Instead, to get notified on connection
// error, please register a connection error handler with InterfaceSet.
size_t AddPtr(InterfacePtr interface_ptr) {
size_t id = next_id_++;
auto it = interface_ptrs_.emplace(id, std::move(interface_ptr));
it.first->second.set_connection_error_handler(base::BindOnce(
&InterfaceSet::HandleConnectionError, base::Unretained(this),
id)); // Unretained is safe as this class owns the Ptrs.
return id;
}
template <typename FunctionType>
void ForAllPtrs(FunctionType function) {
for (const auto& it : interface_ptrs_) {
function(it.second.get());
}
}
// Registers a function that will be called when some InterfacePtr gets
// disconnected. When connection error is detected on one of the InterfacePtrs
// in the collection, the registered handler will be called with an id of that
// InterfacePtr.
void set_connection_error_handler(
base::RepeatingCallback<void(size_t)> error_handler) {
error_handler_ = std::move(error_handler);
}
private:
void HandleConnectionError(size_t id) {
auto it = interface_ptrs_.find(id);
DCHECK(it != interface_ptrs_.end());
interface_ptrs_.erase(it);
error_handler_.Run(id);
}
size_t next_id_ = 0;
std::unordered_map<size_t, InterfacePtr> interface_ptrs_;
base::RepeatingCallback<void(size_t)> error_handler_;
};
} // namespace vr
#endif // CHROME_BROWSER_VR_SERVICE_INTERFACE_SET_H_
......@@ -113,7 +113,7 @@ VRServiceImpl::VRServiceImpl(content::RenderFrameHost* render_frame_host)
runtime_manager_ = XRRuntimeManager::GetOrCreateInstance();
runtime_manager_->AddService(this);
magic_window_controllers_.set_connection_error_handler(base::BindRepeating(
magic_window_controllers_.set_disconnect_handler(base::BindRepeating(
&VRServiceImpl::OnInlineSessionDisconnected,
base::Unretained(this))); // Unretained is OK since the collection is
// owned by VRServiceImpl.
......@@ -217,10 +217,8 @@ void VRServiceImpl::OnWebContentsFocusChanged(content::RenderWidgetHost* host,
immersive_runtime->UpdateListeningForActivate(this);
}
magic_window_controllers_.ForAllPtrs(
[focused](device::mojom::XRSessionController* controller) {
controller->SetFrameDataRestricted(!focused);
});
for (const auto& controller : magic_window_controllers_)
controller->SetFrameDataRestricted(!focused);
}
// static
......@@ -236,7 +234,8 @@ void VRServiceImpl::OnInlineSessionCreated(
device::mojom::VRService::RequestSessionCallback callback,
const std::set<device::mojom::XRSessionFeature>& enabled_features,
device::mojom::XRSessionPtr session,
device::mojom::XRSessionControllerPtr controller) {
mojo::PendingRemote<device::mojom::XRSessionController>
pending_controller) {
if (!session) {
std::move(callback).Run(
device::mojom::RequestSessionResult::NewFailureReason(
......@@ -244,22 +243,25 @@ void VRServiceImpl::OnInlineSessionCreated(
return;
}
mojo::Remote<device::mojom::XRSessionController> controller(
std::move(pending_controller));
// Start giving out magic window data if we are focused.
controller->SetFrameDataRestricted(!in_focused_frame_);
auto id = magic_window_controllers_.AddPtr(std::move(controller));
auto id = magic_window_controllers_.Add(std::move(controller));
// Note: We might be recording an inline session that was created by WebVR.
GetSessionMetricsHelper()->RecordInlineSessionStart(id);
GetSessionMetricsHelper()->RecordInlineSessionStart(id.GetUnsafeValue());
OnSessionCreated(session_runtime_id, std::move(callback), enabled_features,
std::move(session));
}
void VRServiceImpl::OnInlineSessionDisconnected(size_t session_id) {
void VRServiceImpl::OnInlineSessionDisconnected(
mojo::RemoteSetElementId session_id) {
// Notify metrics helper that inline session was stopped.
auto* metrics_helper = GetSessionMetricsHelper();
metrics_helper->RecordInlineSessionStop(session_id);
metrics_helper->RecordInlineSessionStop(session_id.GetUnsafeValue());
}
SessionMetricsHelper* VRServiceImpl::GetSessionMetricsHelper() {
......@@ -513,8 +515,9 @@ void VRServiceImpl::DoRequestSession(
runtime->RequestSession(this, std::move(runtime_options),
std::move(immersive_callback));
} else {
base::OnceCallback<void(device::mojom::XRSessionPtr,
device::mojom::XRSessionControllerPtr)>
base::OnceCallback<void(
device::mojom::XRSessionPtr,
mojo::PendingRemote<device::mojom::XRSessionController>)>
non_immersive_callback =
base::BindOnce(&VRServiceImpl::OnInlineSessionCreated,
weak_ptr_factory_.GetWeakPtr(), session_runtime_id,
......
......@@ -14,7 +14,6 @@
#include "base/util/type_safety/pass_key.h"
#include "chrome/browser/vr/metrics/session_metrics_helper.h"
#include "chrome/browser/vr/service/interface_set.h"
#include "chrome/browser/vr/service/xr_consent_prompt_level.h"
#include "chrome/browser/vr/vr_export.h"
#include "content/public/browser/web_contents_observer.h"
......@@ -76,7 +75,7 @@ class VR_EXPORT VRServiceImpl : public device::mojom::VRService,
// Called when inline session gets disconnected. |session_id| is the value
// returned by |magic_window_controllers_| when adding session controller to
// it.
void OnInlineSessionDisconnected(size_t session_id);
void OnInlineSessionDisconnected(mojo::RemoteSetElementId session_id);
// Notifications/calls from BrowserXRRuntime:
void OnExitPresent();
......@@ -122,7 +121,7 @@ class VR_EXPORT VRServiceImpl : public device::mojom::VRService,
device::mojom::VRService::RequestSessionCallback callback,
const std::set<device::mojom::XRSessionFeature>& enabled_features,
device::mojom::XRSessionPtr session,
device::mojom::XRSessionControllerPtr controller);
mojo::PendingRemote<device::mojom::XRSessionController> controller);
void OnSessionCreated(
device::mojom::XRDeviceId session_runtime_id,
......@@ -157,7 +156,7 @@ class VR_EXPORT VRServiceImpl : public device::mojom::VRService,
mojo::Remote<device::mojom::VRServiceClient> service_client_;
content::RenderFrameHost* render_frame_host_;
mojo::SelfOwnedReceiverRef<VRService> receiver_;
InterfaceSet<device::mojom::XRSessionControllerPtr> magic_window_controllers_;
mojo::RemoteSet<device::mojom::XRSessionController> magic_window_controllers_;
device::mojom::XRVisibilityState visibility_state_ =
device::mojom::XRVisibilityState::VISIBLE;
......
......@@ -20,6 +20,7 @@
#include "device/vr/android/gvr/gvr_device_provider.h"
#include "device/vr/android/gvr/gvr_utils.h"
#include "device/vr/jni_headers/NonPresentingGvrContext_jni.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/transform.h"
......@@ -141,9 +142,7 @@ mojom::VRDisplayInfoPtr CreateVRDisplayInfo(gvr::GvrApi* gvr_api,
} // namespace
GvrDevice::GvrDevice()
: VRDeviceBase(mojom::XRDeviceId::GVR_DEVICE_ID),
exclusive_controller_binding_(this) {
GvrDevice::GvrDevice() : VRDeviceBase(mojom::XRDeviceId::GVR_DEVICE_ID) {
GvrDelegateProviderFactory::SetDevice(this);
}
......@@ -156,7 +155,8 @@ GvrDevice::~GvrDevice() {
}
if (pending_request_session_callback_) {
std::move(pending_request_session_callback_).Run(nullptr, nullptr);
std::move(pending_request_session_callback_)
.Run(nullptr, mojo::NullRemote());
}
GvrDelegateProviderFactory::SetDevice(nullptr);
......@@ -171,7 +171,7 @@ void GvrDevice::RequestSession(
mojom::XRRuntime::RequestSessionCallback callback) {
// We can only process one request at a time.
if (pending_request_session_callback_) {
std::move(callback).Run(nullptr, nullptr);
std::move(callback).Run(nullptr, mojo::NullRemote());
return;
}
pending_request_session_callback_ = std::move(callback);
......@@ -189,25 +189,26 @@ void GvrDevice::OnStartPresentResult(
DCHECK(pending_request_session_callback_);
if (!session) {
std::move(pending_request_session_callback_).Run(nullptr, nullptr);
std::move(pending_request_session_callback_)
.Run(nullptr, mojo::NullRemote());
return;
}
OnStartPresenting();
mojom::XRSessionControllerPtr session_controller;
// Close the binding to ensure any previous sessions were closed.
// TODO(billorr): Only do this in OnPresentingControllerMojoConnectionError.
exclusive_controller_binding_.Close();
exclusive_controller_binding_.Bind(mojo::MakeRequest(&session_controller));
exclusive_controller_receiver_.reset();
std::move(pending_request_session_callback_)
.Run(std::move(session),
exclusive_controller_receiver_.BindNewPipeAndPassRemote());
// Unretained is safe because the error handler won't be called after the
// binding has been destroyed.
exclusive_controller_binding_.set_connection_error_handler(
exclusive_controller_receiver_.set_disconnect_handler(
base::BindOnce(&GvrDevice::OnPresentingControllerMojoConnectionError,
base::Unretained(this)));
std::move(pending_request_session_callback_)
.Run(std::move(session), std::move(session_controller));
}
// XRSessionController
......@@ -225,7 +226,7 @@ void GvrDevice::StopPresenting() {
if (delegate_provider)
delegate_provider->ExitWebVRPresent();
OnExitPresent();
exclusive_controller_binding_.Close();
exclusive_controller_receiver_.reset();
}
void GvrDevice::OnListeningForActivate(bool listening) {
......@@ -312,13 +313,15 @@ void GvrDevice::OnInitRequestSessionFinished(
DCHECK(pending_request_session_callback_);
if (!success) {
std::move(pending_request_session_callback_).Run(nullptr, nullptr);
std::move(pending_request_session_callback_)
.Run(nullptr, mojo::NullRemote());
return;
}
GvrDelegateProvider* delegate_provider = GetGvrDelegateProvider();
if (!delegate_provider) {
std::move(pending_request_session_callback_).Run(nullptr, nullptr);
std::move(pending_request_session_callback_)
.Run(nullptr, mojo::NullRemote());
return;
}
......
......@@ -12,6 +12,7 @@
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
#include "device/vr/vr_device_base.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr_types.h"
namespace device {
......@@ -63,7 +64,8 @@ class DEVICE_VR_EXPORT GvrDevice : public VRDeviceBase,
bool paused_ = true;
mojo::Binding<mojom::XRSessionController> exclusive_controller_binding_;
mojo::Receiver<mojom::XRSessionController> exclusive_controller_receiver_{
this};
mojom::XRRuntime::RequestSessionCallback pending_request_session_callback_;
......
......@@ -16,6 +16,7 @@
#include "device/vr/oculus/oculus_render_loop.h"
#include "device/vr/oculus/oculus_type_converters.h"
#include "device/vr/util/transform_utils.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/libovr/src/Include/OVR_CAPI.h"
#include "third_party/libovr/src/Include/OVR_CAPI_D3D.h"
#include "ui/gfx/geometry/angle_conversions.h"
......@@ -95,7 +96,6 @@ mojom::VRDisplayInfoPtr CreateVRDisplayInfo(mojom::XRDeviceId id,
OculusDevice::OculusDevice()
: VRDeviceBase(mojom::XRDeviceId::OCULUS_DEVICE_ID),
main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
exclusive_controller_binding_(this),
gamepad_provider_factory_binding_(this),
compositor_host_binding_(this),
weak_ptr_factory_(this) {
......@@ -137,7 +137,7 @@ void OculusDevice::RequestSession(
mojom::XRRuntimeSessionOptionsPtr options,
mojom::XRRuntime::RequestSessionCallback callback) {
if (!EnsureValidDisplayInfo()) {
std::move(callback).Run(nullptr, nullptr);
std::move(callback).Run(nullptr, mojo::NullRemote());
return;
}
......@@ -149,7 +149,7 @@ void OculusDevice::RequestSession(
render_loop_->Start();
if (!render_loop_->IsRunning()) {
std::move(callback).Run(nullptr, nullptr);
std::move(callback).Run(nullptr, mojo::NullRemote());
StartOvrSession();
return;
}
......@@ -214,7 +214,7 @@ void OculusDevice::OnRequestSessionResult(
mojom::XRSessionPtr session) {
outstanding_session_requests_count_--;
if (!result) {
std::move(callback).Run(nullptr, nullptr);
std::move(callback).Run(nullptr, mojo::NullRemote());
// Start magic window again.
if (outstanding_session_requests_count_ == 0)
......@@ -224,18 +224,17 @@ void OculusDevice::OnRequestSessionResult(
OnStartPresenting();
mojom::XRSessionControllerPtr session_controller;
exclusive_controller_binding_.Bind(mojo::MakeRequest(&session_controller));
session->display_info = display_info_.Clone();
std::move(callback).Run(
std::move(session),
exclusive_controller_receiver_.BindNewPipeAndPassRemote());
// Unretained is safe because the error handler won't be called after the
// binding has been destroyed.
exclusive_controller_binding_.set_connection_error_handler(
exclusive_controller_receiver_.set_disconnect_handler(
base::BindOnce(&OculusDevice::OnPresentingControllerMojoConnectionError,
base::Unretained(this)));
session->display_info = display_info_.Clone();
std::move(callback).Run(std::move(session), std::move(session_controller));
}
bool OculusDevice::IsAvailable() {
......@@ -254,7 +253,7 @@ void OculusDevice::OnPresentingControllerMojoConnectionError() {
FROM_HERE, base::BindOnce(&XRCompositorCommon::ExitPresent,
base::Unretained(render_loop_.get())));
OnExitPresent();
exclusive_controller_binding_.Close();
exclusive_controller_receiver_.reset();
}
void OculusDevice::OnPresentationEnded() {
......
......@@ -13,6 +13,7 @@
#include "device/vr/vr_device_base.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "third_party/libovr/src/Include/OVR_CAPI.h"
namespace device {
......@@ -71,7 +72,8 @@ class DEVICE_VR_EXPORT OculusDevice
ovrSession session_ = nullptr;
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
mojo::Binding<mojom::XRSessionController> exclusive_controller_binding_;
mojo::Receiver<mojom::XRSessionController> exclusive_controller_receiver_{
this};
mojo::Binding<mojom::IsolatedXRGamepadProviderFactory>
gamepad_provider_factory_binding_;
mojo::PendingReceiver<mojom::IsolatedXRGamepadProvider> provider_receiver_;
......
......@@ -16,6 +16,7 @@
#include "build/build_config.h"
#include "device/vr/openvr/openvr_render_loop.h"
#include "device/vr/openvr/openvr_type_converters.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/openvr/src/headers/openvr.h"
#include "ui/gfx/geometry/angle_conversions.h"
......@@ -123,7 +124,6 @@ mojom::VRDisplayInfoPtr CreateVRDisplayInfo(vr::IVRSystem* vr_system,
OpenVRDevice::OpenVRDevice()
: VRDeviceBase(device::mojom::XRDeviceId::OPENVR_DEVICE_ID),
main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
exclusive_controller_binding_(this),
gamepad_provider_factory_binding_(this),
compositor_host_binding_(this) {
render_loop_ = std::make_unique<OpenVRRenderLoop>();
......@@ -167,7 +167,7 @@ void OpenVRDevice::RequestSession(
mojom::XRRuntimeSessionOptionsPtr options,
mojom::XRRuntime::RequestSessionCallback callback) {
if (!EnsureValidDisplayInfo()) {
std::move(callback).Run(nullptr, nullptr);
std::move(callback).Run(nullptr, mojo::NullRemote());
return;
}
......@@ -177,7 +177,7 @@ void OpenVRDevice::RequestSession(
render_loop_->Start();
if (!render_loop_->IsRunning()) {
std::move(callback).Run(nullptr, nullptr);
std::move(callback).Run(nullptr, mojo::NullRemote());
return;
}
......@@ -255,24 +255,23 @@ void OpenVRDevice::OnRequestSessionResult(
outstanding_session_requests_count_--;
if (!result) {
OnPresentationEnded();
std::move(callback).Run(nullptr, nullptr);
std::move(callback).Run(nullptr, mojo::NullRemote());
return;
}
OnStartPresenting();
mojom::XRSessionControllerPtr session_controller;
exclusive_controller_binding_.Bind(mojo::MakeRequest(&session_controller));
session->display_info = display_info_.Clone();
std::move(callback).Run(
std::move(session),
exclusive_controller_receiver_.BindNewPipeAndPassRemote());
// Use of Unretained is safe because the callback will only occur if the
// binding is not destroyed.
exclusive_controller_binding_.set_connection_error_handler(
exclusive_controller_receiver_.set_disconnect_handler(
base::BindOnce(&OpenVRDevice::OnPresentingControllerMojoConnectionError,
base::Unretained(this)));
session->display_info = display_info_.Clone();
std::move(callback).Run(std::move(session), std::move(session_controller));
}
bool OpenVRDevice::IsAvailable() {
......@@ -318,7 +317,7 @@ void OpenVRDevice::OnPresentingControllerMojoConnectionError() {
// TODO(https://crbug.com/875187): Alternatively, we could recreate the
// provider on the next session, or look into why the callback gets lost.
OnExitPresent();
exclusive_controller_binding_.Close();
exclusive_controller_receiver_.reset();
}
// Only deal with events that will cause displayInfo changes for now.
......
......@@ -14,6 +14,7 @@
#include "device/vr/vr_device_base.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace device {
......@@ -74,7 +75,8 @@ class DEVICE_VR_EXPORT OpenVRDevice
std::unique_ptr<OpenVRWrapper> openvr_;
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
mojo::Binding<mojom::XRSessionController> exclusive_controller_binding_;
mojo::Receiver<mojom::XRSessionController> exclusive_controller_receiver_{
this};
mojo::Binding<mojom::IsolatedXRGamepadProviderFactory>
gamepad_provider_factory_binding_;
......
......@@ -10,6 +10,7 @@
#include "device/vr/openxr/openxr_api_wrapper.h"
#include "device/vr/openxr/openxr_render_loop.h"
#include "device/vr/util/transform_utils.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
namespace device {
......@@ -85,7 +86,6 @@ bool OpenXrDevice::IsApiAvailable() {
OpenXrDevice::OpenXrDevice()
: VRDeviceBase(device::mojom::XRDeviceId::OPENXR_DEVICE_ID),
exclusive_controller_binding_(this),
gamepad_provider_factory_binding_(this),
compositor_host_binding_(this),
weak_ptr_factory_(this) {
......@@ -132,7 +132,7 @@ void OpenXrDevice::RequestSession(
render_loop_->Start();
if (!render_loop_->IsRunning()) {
std::move(callback).Run(nullptr, nullptr);
std::move(callback).Run(nullptr, mojo::NullRemote());
return;
}
......@@ -173,21 +173,12 @@ void OpenXrDevice::OnRequestSessionResult(
bool result,
mojom::XRSessionPtr session) {
if (!result) {
std::move(callback).Run(nullptr, nullptr);
std::move(callback).Run(nullptr, mojo::NullRemote());
return;
}
OnStartPresenting();
mojom::XRSessionControllerPtr session_controller;
exclusive_controller_binding_.Bind(mojo::MakeRequest(&session_controller));
// Use of Unretained is safe because the callback will only occur if the
// binding is not destroyed.
exclusive_controller_binding_.set_connection_error_handler(
base::BindOnce(&OpenXrDevice::OnPresentingControllerMojoConnectionError,
base::Unretained(this)));
EnsureRenderLoop();
gfx::Size view_size = render_loop_->GetViewSize();
display_info_->left_eye->render_width = view_size.width();
......@@ -196,7 +187,15 @@ void OpenXrDevice::OnRequestSessionResult(
display_info_->right_eye->render_height = view_size.height();
session->display_info = display_info_.Clone();
std::move(callback).Run(std::move(session), std::move(session_controller));
std::move(callback).Run(
std::move(session),
exclusive_controller_receiver_.BindNewPipeAndPassRemote());
// Use of Unretained is safe because the callback will only occur if the
// binding is not destroyed.
exclusive_controller_receiver_.set_disconnect_handler(
base::BindOnce(&OpenXrDevice::OnPresentingControllerMojoConnectionError,
base::Unretained(this)));
}
void OpenXrDevice::OnPresentingControllerMojoConnectionError() {
......@@ -208,7 +207,7 @@ void OpenXrDevice::OnPresentingControllerMojoConnectionError() {
base::Unretained(render_loop_.get())));
}
OnExitPresent();
exclusive_controller_binding_.Close();
exclusive_controller_receiver_.reset();
}
void OpenXrDevice::SetFrameDataRestricted(bool restricted) {
......
......@@ -11,6 +11,7 @@
#include "device/vr/public/mojom/vr_service.mojom.h"
#include "device/vr/vr_device_base.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace device {
......@@ -58,7 +59,8 @@ class DEVICE_VR_EXPORT OpenXrDevice
std::unique_ptr<OpenXrRenderLoop> render_loop_;
mojo::Binding<mojom::XRSessionController> exclusive_controller_binding_;
mojo::Receiver<mojom::XRSessionController> exclusive_controller_receiver_{
this};
mojo::Binding<mojom::IsolatedXRGamepadProviderFactory>
gamepad_provider_factory_binding_;
......
......@@ -138,10 +138,10 @@ void VROrientationDevice::RequestSession(
// available when RequestSession is called for non-immersive sessions.
mojo::PendingRemote<mojom::XRFrameDataProvider> data_provider;
mojom::XRSessionControllerPtr controller;
mojo::PendingRemote<mojom::XRSessionController> controller;
magic_window_sessions_.push_back(std::make_unique<VROrientationSession>(
this, data_provider.InitWithNewPipeAndPassReceiver(),
mojo::MakeRequest(&controller)));
controller.InitWithNewPipeAndPassReceiver()));
auto session = mojom::XRSession::New();
session->data_provider = std::move(data_provider);
......
......@@ -164,10 +164,10 @@ class VROrientationDeviceTest : public testing::Test {
std::unique_ptr<VROrientationSession> MakeDisplay() {
mojo::PendingRemote<mojom::XRFrameDataProvider> data_provider;
mojom::XRSessionControllerPtr controller;
mojo::PendingRemote<mojom::XRSessionController> controller;
return std::make_unique<VROrientationSession>(
device_.get(), data_provider.InitWithNewPipeAndPassReceiver(),
mojo::MakeRequest(&controller));
controller.InitWithNewPipeAndPassReceiver());
}
void TryGetFrameData(VROrientationSession* display, bool expect_null) {
......
......@@ -14,13 +14,13 @@ namespace device {
VROrientationSession::VROrientationSession(
VROrientationDevice* device,
mojo::PendingReceiver<mojom::XRFrameDataProvider> magic_window_receiver,
mojom::XRSessionControllerRequest session_request)
mojo::PendingReceiver<mojom::XRSessionController> session_receiver)
: magic_window_receiver_(this, std::move(magic_window_receiver)),
session_controller_binding_(this, std::move(session_request)),
session_controller_receiver_(this, std::move(session_receiver)),
device_(device) {
// Unretained is safe because the binding will close when we are destroyed,
// Unretained is safe because the receiver will close when we are destroyed,
// so we won't receive any more callbacks after that.
session_controller_binding_.set_connection_error_handler(base::BindOnce(
session_controller_receiver_.set_disconnect_handler(base::BindOnce(
&VROrientationSession::OnMojoConnectionError, base::Unretained(this)));
}
......@@ -63,7 +63,7 @@ void VROrientationSession::SetFrameDataRestricted(bool frame_data_restricted) {
void VROrientationSession::OnMojoConnectionError() {
magic_window_receiver_.reset();
session_controller_binding_.Close();
session_controller_receiver_.reset();
device_->EndMagicWindowSession(this); // This call will destroy us.
}
......
......@@ -14,7 +14,6 @@
#include "device/vr/vr_device.h"
#include "device/vr/vr_export.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "ui/display/display.h"
......@@ -33,7 +32,7 @@ class DEVICE_VR_EXPORT VROrientationSession
public:
VROrientationSession(VROrientationDevice* device,
mojo::PendingReceiver<mojom::XRFrameDataProvider>,
mojom::XRSessionControllerRequest);
mojo::PendingReceiver<mojom::XRSessionController>);
~VROrientationSession() override;
void GetEnvironmentIntegrationProvider(
......@@ -54,7 +53,7 @@ class DEVICE_VR_EXPORT VROrientationSession
void OnMojoConnectionError();
mojo::Receiver<mojom::XRFrameDataProvider> magic_window_receiver_;
mojo::Binding<mojom::XRSessionController> session_controller_binding_;
mojo::Receiver<mojom::XRSessionController> session_controller_receiver_;
device::VROrientationDevice* device_;
bool restrict_frame_data_ = true;
};
......
......@@ -73,7 +73,7 @@ interface XRRuntime {
// the browser process.
RequestSession(XRRuntimeSessionOptions options) => (
XRSession? session,
XRSessionController? controller);
pending_remote<XRSessionController>? controller);
// The browser may register for changes to a device. Initial VRDisplayInfo
// will immediately be returned to the listener to prevent races.
......
......@@ -4,12 +4,12 @@
#include "device/vr/test/fake_vr_device.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "ui/gfx/transform_util.h"
namespace device {
FakeVRDevice::FakeVRDevice(mojom::XRDeviceId id)
: VRDeviceBase(id), controller_binding_(this) {
FakeVRDevice::FakeVRDevice(mojom::XRDeviceId id) : VRDeviceBase(id) {
SetVRDisplayInfo(InitBasicDevice());
}
......@@ -57,12 +57,11 @@ void FakeVRDevice::RequestSession(
OnStartPresenting();
// The current tests never use the return values, so it's fine to return
// invalid data here.
std::move(callback).Run(nullptr, nullptr);
std::move(callback).Run(nullptr, mojo::NullRemote());
}
void FakeVRDevice::OnPresentingControllerMojoConnectionError() {
OnExitPresent();
controller_binding_.Close();
}
} // namespace device
......@@ -39,8 +39,6 @@ class DEVICE_VR_EXPORT FakeVRDevice : public VRDeviceBase,
mojom::VRPosePtr pose_;
mojo::Binding<mojom::XRSessionController> controller_binding_;
DISALLOW_COPY_AND_ASSIGN(FakeVRDevice);
};
......
......@@ -15,6 +15,7 @@
#include "build/build_config.h"
#include "device/vr/util/transform_utils.h"
#include "device/vr/windows_mixed_reality/mixed_reality_renderloop.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "ui/gfx/geometry/angle_conversions.h"
namespace device {
......@@ -63,8 +64,7 @@ mojom::VRDisplayInfoPtr CreateFakeVRDisplayInfo(device::mojom::XRDeviceId id) {
MixedRealityDevice::MixedRealityDevice()
: VRDeviceBase(device::mojom::XRDeviceId::WINDOWS_MIXED_REALITY_ID),
gamepad_provider_factory_binding_(this),
compositor_host_binding_(this),
exclusive_controller_binding_(this) {
compositor_host_binding_(this) {
SetVRDisplayInfo(CreateFakeVRDisplayInfo(GetId()));
}
......@@ -104,7 +104,7 @@ void MixedRealityDevice::RequestSession(
// memory exhaustion). If the thread fails to start, then we fail to create
// a session.
if (!render_loop_->IsRunning()) {
std::move(callback).Run(nullptr, nullptr);
std::move(callback).Run(nullptr, mojo::NullRemote());
return;
}
......@@ -163,24 +163,22 @@ void MixedRealityDevice::OnRequestSessionResult(
mojom::XRSessionPtr session) {
if (!result) {
OnPresentationEnded();
std::move(callback).Run(nullptr, nullptr);
std::move(callback).Run(nullptr, mojo::NullRemote());
return;
}
OnStartPresenting();
mojom::XRSessionControllerPtr session_controller;
exclusive_controller_binding_.Bind(mojo::MakeRequest(&session_controller));
session->display_info = display_info_.Clone();
std::move(callback).Run(
std::move(session),
exclusive_controller_receiver_.BindNewPipeAndPassRemote());
// Use of Unretained is safe because the callback will only occur if the
// binding is not destroyed.
exclusive_controller_binding_.set_connection_error_handler(base::BindOnce(
exclusive_controller_receiver_.set_disconnect_handler(base::BindOnce(
&MixedRealityDevice::OnPresentingControllerMojoConnectionError,
base::Unretained(this)));
session->display_info = display_info_.Clone();
std::move(callback).Run(std::move(session), std::move(session_controller));
}
void MixedRealityDevice::GetIsolatedXRGamepadProvider(
......@@ -228,7 +226,7 @@ void MixedRealityDevice::OnPresentingControllerMojoConnectionError() {
// TODO(https://crbug.com/875187): Alternatively, we could recreate the
// provider on the next session, or look into why the callback gets lost.
OnExitPresent();
exclusive_controller_binding_.Close();
exclusive_controller_receiver_.reset();
}
} // namespace device
......@@ -15,6 +15,7 @@
#include "device/vr/windows/compositor_base.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace device {
......@@ -65,7 +66,8 @@ class DEVICE_VR_EXPORT MixedRealityDevice
mojo::Binding<mojom::XRCompositorHost> compositor_host_binding_;
mojo::PendingReceiver<mojom::ImmersiveOverlay> overlay_receiver_;
mojo::Binding<mojom::XRSessionController> exclusive_controller_binding_;
mojo::Receiver<mojom::XRSessionController> exclusive_controller_receiver_{
this};
base::WeakPtrFactory<MixedRealityDevice> weak_ptr_factory_{this};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment