Commit 6647b9fb authored by Alexander Cooper's avatar Alexander Cooper Committed by Commit Bot

Create public interfaces for BrowserXrRuntime

Creates interfaces for BrowserXrRuntime to be consumed by classes that
will remain in chrome/. This updates existing usages that will no longer
be able to access the BrowserXRRuntimeImpl class to use the public
interface (primarily this is everything outside of vr/service).

Note that although right now BrowserXRRuntimeImpl lives in chrome/, it
will soon be moving to content/, once the remaining dependencies for the
rest of vr/service have been broken (so as to avoid over-exposing
methods needed by these classes to talk to each other). Currently the
only way to get a BrowserXRRuntime is via the XRRuntimeManager. While
some of the XRRuntimeManager methods will be moved to a public interface
in future changes, it will still only be possible to get an
XRRuntimeManager (and therefore a BrowserXRRuntimeImpl) in chrome/ until
the move actually happens.

Bug: 1031622
Change-Id: I42e1cfd18842166ce1f8eeaa6003d7f84e52aef6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2103305
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750845}
parent e91e37dd
......@@ -5414,8 +5414,8 @@ jumbo_static_library("browser") {
sources += [
"component_updater/vr_assets_component_installer.cc",
"component_updater/vr_assets_component_installer.h",
"vr/service/browser_xr_runtime.cc",
"vr/service/browser_xr_runtime.h",
"vr/service/browser_xr_runtime_impl.cc",
"vr/service/browser_xr_runtime_impl.h",
"vr/service/chrome_xr_integration_client.cc",
"vr/service/chrome_xr_integration_client.h",
"vr/service/vr_service_impl.cc",
......
......@@ -16,9 +16,9 @@
#include "chrome/browser/component_updater/vr_assets_component_installer.h"
#include "chrome/browser/vr/assets_loader.h"
#include "chrome/browser/vr/metrics/metrics_helper.h"
#include "chrome/browser/vr/service/browser_xr_runtime.h"
#include "chrome/browser/vr/service/vr_service_impl.h"
#include "chrome/browser/vr/service/xr_runtime_manager.h"
#include "content/public/browser/browser_xr_runtime.h"
#include "content/public/browser/webvr_service_provider.h"
#include "device/vr/android/gvr/gvr_delegate_provider_factory.h"
#include "device/vr/android/gvr/gvr_device.h"
......@@ -36,8 +36,8 @@ namespace vr {
namespace {
void SetInlineVrEnabled(XRRuntimeManager& runtime_manager, bool enable) {
runtime_manager.ForEachRuntime([enable](BrowserXRRuntime* runtime) {
runtime->GetRuntime()->SetInlinePosesEnabled(enable);
runtime_manager.ForEachRuntime([enable](content::BrowserXRRuntime* runtime) {
runtime->SetInlinePosesEnabled(enable);
});
}
......@@ -243,12 +243,12 @@ std::unique_ptr<VrCoreInfo> VrShellDelegate::MakeVrCoreInfo(JNIEnv* env) {
Java_VrShellDelegate_getVrCoreInfo(env, j_vr_shell_delegate_)));
}
void VrShellDelegate::OnRuntimeAdded(vr::BrowserXRRuntime* runtime) {
void VrShellDelegate::OnRuntimeAdded(content::BrowserXRRuntime* runtime) {
if (vr_shell_) {
// See comment in VrShellDelegate::SetDelegate. This handles the case where
// VrShell is created before the device code is initialized (like when
// entering VR browsing on a non-webVR page).
runtime->GetRuntime()->SetInlinePosesEnabled(false);
runtime->SetInlinePosesEnabled(false);
}
}
......
......@@ -84,7 +84,7 @@ class VrShellDelegate : public device::GvrDelegateProvider,
// As for the runtimes that got added to the XRRuntimeManager before the
// VrShell got created, their poses will be turned off too on its
// creation.
void OnRuntimeAdded(vr::BrowserXRRuntime* runtime) override;
void OnRuntimeAdded(content::BrowserXRRuntime* runtime) override;
void OnPresentResult(
device::mojom::VRDisplayInfoPtr display_info,
device::mojom::XRRuntimeSessionOptionsPtr options,
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/vr/service/browser_xr_runtime.h"
#include "chrome/browser/vr/service/browser_xr_runtime_impl.h"
#include <algorithm>
#include <memory>
......@@ -236,7 +236,7 @@ content::WebContents* GetWebContents(int render_process_id,
#endif
} // anonymous namespace
BrowserXRRuntime::BrowserXRRuntime(
BrowserXRRuntimeImpl::BrowserXRRuntimeImpl(
device::mojom::XRDeviceId id,
mojo::PendingRemote<device::mojom::XRRuntime> runtime,
device::mojom::VRDisplayInfoPtr display_info)
......@@ -248,11 +248,11 @@ BrowserXRRuntime::BrowserXRRuntime(
// so we won't be called after runtime_ is destroyed.
runtime_->ListenToDeviceChanges(
receiver_.BindNewEndpointAndPassRemote(),
base::BindOnce(&BrowserXRRuntime::OnDisplayInfoChanged,
base::BindOnce(&BrowserXRRuntimeImpl::OnDisplayInfoChanged,
base::Unretained(this)));
// TODO(crbug.com/1031622): Convert this to a query for the client off of
// ContentBrowserClient once BrowserXrRuntime moves to content.
// ContentBrowserClient once BrowserXRRuntimeImpl moves to content.
auto* integration_client = ChromeXrIntegrationClient::GetInstance();
if (integration_client)
......@@ -270,7 +270,7 @@ BrowserXRRuntime::BrowserXRRuntime(
#endif
}
BrowserXRRuntime::~BrowserXRRuntime() {
BrowserXRRuntimeImpl::~BrowserXRRuntimeImpl() {
DVLOG(2) << __func__ << ": id=" << id_;
if (install_finished_callback_) {
......@@ -278,7 +278,7 @@ BrowserXRRuntime::~BrowserXRRuntime() {
}
}
void BrowserXRRuntime::ExitActiveImmersiveSession() {
void BrowserXRRuntimeImpl::ExitActiveImmersiveSession() {
DVLOG(2) << __func__;
auto* service = GetServiceWithActiveImmersiveSession();
if (service) {
......@@ -286,7 +286,7 @@ void BrowserXRRuntime::ExitActiveImmersiveSession() {
}
}
bool BrowserXRRuntime::SupportsFeature(
bool BrowserXRRuntimeImpl::SupportsFeature(
device::mojom::XRSessionFeature feature) const {
switch (id_) {
// Test/fake devices support all features.
......@@ -334,7 +334,7 @@ bool BrowserXRRuntime::SupportsFeature(
NOTREACHED();
}
bool BrowserXRRuntime::SupportsAllFeatures(
bool BrowserXRRuntimeImpl::SupportsAllFeatures(
const std::vector<device::mojom::XRSessionFeature>& features) const {
for (const auto& feature : features) {
if (!SupportsFeature(feature))
......@@ -344,7 +344,7 @@ bool BrowserXRRuntime::SupportsAllFeatures(
return true;
}
bool BrowserXRRuntime::SupportsCustomIPD() const {
bool BrowserXRRuntimeImpl::SupportsCustomIPD() const {
switch (id_) {
case device::mojom::XRDeviceId::ARCORE_DEVICE_ID:
case device::mojom::XRDeviceId::WEB_TEST_DEVICE_ID:
......@@ -373,7 +373,7 @@ bool BrowserXRRuntime::SupportsCustomIPD() const {
NOTREACHED();
}
bool BrowserXRRuntime::SupportsNonEmulatedHeight() const {
bool BrowserXRRuntimeImpl::SupportsNonEmulatedHeight() const {
switch (id_) {
case device::mojom::XRDeviceId::ARCORE_DEVICE_ID:
case device::mojom::XRDeviceId::WEB_TEST_DEVICE_ID:
......@@ -399,7 +399,7 @@ bool BrowserXRRuntime::SupportsNonEmulatedHeight() const {
NOTREACHED();
}
void BrowserXRRuntime::OnDisplayInfoChanged(
void BrowserXRRuntimeImpl::OnDisplayInfoChanged(
device::mojom::VRDisplayInfoPtr vr_device_info) {
bool had_display_info = !!display_info_;
display_info_ = ValidateVRDisplayInfo(vr_device_info.get(), id_);
......@@ -410,12 +410,12 @@ void BrowserXRRuntime::OnDisplayInfoChanged(
}
// Notify observers of the new display info.
for (BrowserXRRuntimeObserver& observer : observers_) {
for (Observer& observer : observers_) {
observer.SetVRDisplayInfo(display_info_.Clone());
}
}
void BrowserXRRuntime::StopImmersiveSession(
void BrowserXRRuntimeImpl::StopImmersiveSession(
VRServiceImpl::ExitPresentCallback on_exited) {
DVLOG(2) << __func__;
if (immersive_session_controller_) {
......@@ -425,14 +425,14 @@ void BrowserXRRuntime::StopImmersiveSession(
presenting_service_ = nullptr;
}
for (BrowserXRRuntimeObserver& observer : observers_) {
for (Observer& observer : observers_) {
observer.SetWebXRWebContents(nullptr);
}
}
std::move(on_exited).Run();
}
void BrowserXRRuntime::OnExitPresent() {
void BrowserXRRuntimeImpl::OnExitPresent() {
DVLOG(2) << __func__;
if (presenting_service_) {
presenting_service_->OnExitPresent();
......@@ -440,19 +440,19 @@ void BrowserXRRuntime::OnExitPresent() {
}
}
void BrowserXRRuntime::OnVisibilityStateChanged(
void BrowserXRRuntimeImpl::OnVisibilityStateChanged(
device::mojom::XRVisibilityState visibility_state) {
for (VRServiceImpl* service : services_) {
service->OnVisibilityStateChanged(visibility_state);
}
}
void BrowserXRRuntime::OnServiceAdded(VRServiceImpl* service) {
void BrowserXRRuntimeImpl::OnServiceAdded(VRServiceImpl* service) {
DVLOG(2) << __func__ << ": id=" << id_;
services_.insert(service);
}
void BrowserXRRuntime::OnServiceRemoved(VRServiceImpl* service) {
void BrowserXRRuntimeImpl::OnServiceRemoved(VRServiceImpl* service) {
DVLOG(2) << __func__ << ": id=" << id_;
DCHECK(service);
services_.erase(service);
......@@ -461,28 +461,28 @@ void BrowserXRRuntime::OnServiceRemoved(VRServiceImpl* service) {
}
}
void BrowserXRRuntime::ExitPresent(
void BrowserXRRuntimeImpl::ExitPresent(
VRServiceImpl* service,
VRServiceImpl::ExitPresentCallback on_exited) {
DVLOG(2) << __func__ << ": id=" << id_ << " service=" << service
<< " presenting_service_=" << presenting_service_;
if (service == presenting_service_) {
runtime_->ShutdownSession(
base::BindOnce(&BrowserXRRuntime::StopImmersiveSession,
base::BindOnce(&BrowserXRRuntimeImpl::StopImmersiveSession,
weak_ptr_factory_.GetWeakPtr(), std::move(on_exited)));
}
}
void BrowserXRRuntime::SetFramesThrottled(const VRServiceImpl* service,
bool throttled) {
void BrowserXRRuntimeImpl::SetFramesThrottled(const VRServiceImpl* service,
bool throttled) {
if (service == presenting_service_) {
for (BrowserXRRuntimeObserver& observer : observers_) {
for (Observer& observer : observers_) {
observer.SetFramesThrottled(throttled);
}
}
}
void BrowserXRRuntime::RequestSession(
void BrowserXRRuntimeImpl::RequestSession(
VRServiceImpl* service,
const device::mojom::XRRuntimeSessionOptionsPtr& options,
RequestSessionCallback callback) {
......@@ -491,12 +491,12 @@ void BrowserXRRuntime::RequestSession(
// destroyed.
runtime_->RequestSession(
options->Clone(),
base::BindOnce(&BrowserXRRuntime::OnRequestSessionResult,
base::BindOnce(&BrowserXRRuntimeImpl::OnRequestSessionResult,
base::Unretained(this), service->GetWeakPtr(),
options->Clone(), std::move(callback)));
}
void BrowserXRRuntime::OnRequestSessionResult(
void BrowserXRRuntimeImpl::OnRequestSessionResult(
base::WeakPtr<VRServiceImpl> service,
device::mojom::XRRuntimeSessionOptionsPtr options,
RequestSessionCallback callback,
......@@ -509,12 +509,13 @@ void BrowserXRRuntime::OnRequestSessionResult(
presenting_service_ = service.get();
immersive_session_controller_.Bind(
std::move(immersive_session_controller));
immersive_session_controller_.set_disconnect_handler(base::BindOnce(
&BrowserXRRuntime::OnImmersiveSessionError, base::Unretained(this)));
immersive_session_controller_.set_disconnect_handler(
base::BindOnce(&BrowserXRRuntimeImpl::OnImmersiveSessionError,
base::Unretained(this)));
// Notify observers that we have started presentation.
content::WebContents* web_contents = service->GetWebContents();
for (BrowserXRRuntimeObserver& observer : observers_) {
for (Observer& observer : observers_) {
observer.SetWebXRWebContents(web_contents);
}
}
......@@ -532,7 +533,7 @@ void BrowserXRRuntime::OnRequestSessionResult(
}
}
void BrowserXRRuntime::ShowConsentPrompt(
void BrowserXRRuntimeImpl::ShowConsentPrompt(
int render_process_id,
int render_frame_id,
XrConsentPromptLevel consent_level,
......@@ -554,7 +555,7 @@ void BrowserXRRuntime::ShowConsentPrompt(
#endif
}
void BrowserXRRuntime::EnsureInstalled(
void BrowserXRRuntimeImpl::EnsureInstalled(
int render_process_id,
int render_frame_id,
base::OnceCallback<void(bool)> install_callback) {
......@@ -580,22 +581,35 @@ void BrowserXRRuntime::EnsureInstalled(
install_helper_->EnsureInstalled(
render_process_id, render_frame_id,
base::BindOnce(&BrowserXRRuntime::OnInstallFinished,
base::BindOnce(&BrowserXRRuntimeImpl::OnInstallFinished,
weak_ptr_factory_.GetWeakPtr()));
}
void BrowserXRRuntime::OnInstallFinished(bool succeeded) {
void BrowserXRRuntimeImpl::OnInstallFinished(bool succeeded) {
DCHECK(install_finished_callback_);
std::move(install_finished_callback_).Run(succeeded);
}
void BrowserXRRuntime::OnImmersiveSessionError() {
void BrowserXRRuntimeImpl::OnImmersiveSessionError() {
DVLOG(2) << __func__ << ": id=" << id_;
StopImmersiveSession(base::DoNothing());
}
void BrowserXRRuntime::BeforeRuntimeRemoved() {
void BrowserXRRuntimeImpl::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
observer->SetVRDisplayInfo(display_info_.Clone());
}
void BrowserXRRuntimeImpl::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
void BrowserXRRuntimeImpl::SetInlinePosesEnabled(bool enabled) {
runtime_->SetInlinePosesEnabled(enabled);
}
void BrowserXRRuntimeImpl::BeforeRuntimeRemoved() {
DVLOG(1) << __func__ << ": id=" << id_;
// If the device process crashes or otherwise gets removed, it's a race as to
......
......@@ -2,8 +2,8 @@
// 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_BROWSER_XR_RUNTIME_H_
#define CHROME_BROWSER_VR_SERVICE_BROWSER_XR_RUNTIME_H_
#ifndef CHROME_BROWSER_VR_SERVICE_BROWSER_XR_RUNTIME_IMPL_H_
#define CHROME_BROWSER_VR_SERVICE_BROWSER_XR_RUNTIME_IMPL_H_
#include <set>
#include <vector>
......@@ -12,6 +12,7 @@
#include "base/observer_list_types.h"
#include "chrome/browser/vr/service/vr_service_impl.h"
#include "chrome/browser/vr/service/xr_consent_helper.h"
#include "content/public/browser/browser_xr_runtime.h"
#include "content/public/browser/render_frame_host.h"
#include "device/vr/public/mojom/isolated_xr_service.mojom-forward.h"
#include "device/vr/public/mojom/vr_service.mojom-forward.h"
......@@ -21,43 +22,24 @@
#include "mojo/public/cpp/bindings/remote.h"
namespace content {
class WebContents;
class XrInstallHelper;
}
} // namespace content
namespace vr {
// This interface is implemented by classes that wish to observer the state of
// the XR service for a particular runtime. In particular, observers may
// currently know when the browser considers a WebContents presenting to an
// immersive headset. Implementers of this interface will be called on the main
// browser thread. Currently this is used on Windows to drive overlays.
class BrowserXRRuntimeObserver : public base::CheckedObserver {
public:
virtual void SetVRDisplayInfo(
device::mojom::VRDisplayInfoPtr display_info) = 0;
// The parameter |contents| is set when a page starts an immersive WebXR
// session. There can only be at most one active immersive session for the
// XRRuntime. Set to null when there is no active immersive session.
virtual void SetWebXRWebContents(content::WebContents* contents) = 0;
virtual void SetFramesThrottled(bool throttled) = 0;
};
// This class wraps a physical device's interfaces, and registers for events.
// There is one BrowserXRRuntime per physical device runtime. It manages
// There is one BrowserXRRuntimeImpl per physical device runtime. It manages
// browser-side handling of state, like which VRServiceImpl is listening for
// device activation.
class BrowserXRRuntime : public device::mojom::XRRuntimeEventListener {
class BrowserXRRuntimeImpl : public content::BrowserXRRuntime,
public device::mojom::XRRuntimeEventListener {
public:
using RequestSessionCallback =
base::OnceCallback<void(device::mojom::XRSessionPtr)>;
explicit BrowserXRRuntime(
explicit BrowserXRRuntimeImpl(
device::mojom::XRDeviceId id,
mojo::PendingRemote<device::mojom::XRRuntime> runtime,
device::mojom::VRDisplayInfoPtr info);
~BrowserXRRuntime() override;
~BrowserXRRuntimeImpl() override;
void ExitActiveImmersiveSession();
bool SupportsFeature(device::mojom::XRSessionFeature feature) const;
......@@ -93,16 +75,13 @@ class BrowserXRRuntime : public device::mojom::XRRuntimeEventListener {
return display_info_.Clone();
}
// Methods called to support metrics/overlays on Windows.
void AddObserver(BrowserXRRuntimeObserver* observer) {
observers_.AddObserver(observer);
observer->SetVRDisplayInfo(display_info_.Clone());
}
void RemoveObserver(BrowserXRRuntimeObserver* observer) {
observers_.RemoveObserver(observer);
}
device::mojom::XRDeviceId GetId() const { return id_; }
// BrowserXRRuntime
void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override;
void SetInlinePosesEnabled(bool enabled) override;
// Called to allow the runtime to conduct any cleanup it needs to do before it
// is removed.
void BeforeRuntimeRemoved();
......@@ -139,14 +118,14 @@ class BrowserXRRuntime : public device::mojom::XRRuntimeEventListener {
mojo::AssociatedReceiver<device::mojom::XRRuntimeEventListener> receiver_{
this};
base::ObserverList<BrowserXRRuntimeObserver> observers_;
base::ObserverList<Observer> observers_;
std::unique_ptr<XrConsentHelper> consent_helper_;
std::unique_ptr<content::XrInstallHelper> install_helper_;
base::OnceCallback<void(bool)> install_finished_callback_;
base::WeakPtrFactory<BrowserXRRuntime> weak_ptr_factory_{this};
base::WeakPtrFactory<BrowserXRRuntimeImpl> weak_ptr_factory_{this};
};
} // namespace vr
#endif // CHROME_BROWSER_VR_SERVICE_BROWSER_XR_RUNTIME_H_
#endif // CHROME_BROWSER_VR_SERVICE_BROWSER_XR_RUNTIME_IMPL_H_
......@@ -17,7 +17,7 @@
#include "chrome/browser/vr/metrics/session_metrics_helper.h"
#include "chrome/browser/vr/metrics/webxr_session_tracker.h"
#include "chrome/browser/vr/mode.h"
#include "chrome/browser/vr/service/browser_xr_runtime.h"
#include "chrome/browser/vr/service/browser_xr_runtime_impl.h"
#include "chrome/browser/vr/service/xr_runtime_manager.h"
#include "chrome/common/chrome_switches.h"
#include "components/permissions/permission_manager.h"
......@@ -47,7 +47,7 @@ device::mojom::XRRuntimeSessionOptionsPtr GetRuntimeOptions(
vr::XrConsentPromptLevel GetRequiredConsentLevel(
device::mojom::XRSessionMode mode,
const vr::BrowserXRRuntime* runtime,
const vr::BrowserXRRuntimeImpl* runtime,
const std::set<device::mojom::XRSessionFeature>& requested_features) {
if (base::Contains(
requested_features,
......@@ -422,7 +422,7 @@ void VRServiceImpl::RequestSession(
}
void VRServiceImpl::ShowConsentPrompt(SessionRequestData request,
BrowserXRRuntime* runtime) {
BrowserXRRuntimeImpl* runtime) {
DVLOG(2) << __func__;
DCHECK(request.options);
DCHECK(runtime);
......@@ -509,7 +509,7 @@ void VRServiceImpl::OnConsentResult(SessionRequestData request,
}
void VRServiceImpl::EnsureRuntimeInstalled(SessionRequestData request,
BrowserXRRuntime* runtime) {
BrowserXRRuntimeImpl* runtime) {
DVLOG(2) << __func__;
// If we were not provided the runtime, try to get it again.
......@@ -606,7 +606,7 @@ void VRServiceImpl::SupportsSession(
}
void VRServiceImpl::ExitPresent(ExitPresentCallback on_exited) {
BrowserXRRuntime* immersive_runtime =
BrowserXRRuntimeImpl* immersive_runtime =
runtime_manager_->GetCurrentlyPresentingImmersiveRuntime();
DVLOG(2) << __func__ << ": !!immersive_runtime=" << !!immersive_runtime;
if (immersive_runtime) {
......@@ -619,7 +619,7 @@ void VRServiceImpl::ExitPresent(ExitPresentCallback on_exited) {
void VRServiceImpl::SetFramesThrottled(bool throttled) {
if (throttled != frames_throttled_) {
frames_throttled_ = throttled;
BrowserXRRuntime* immersive_runtime =
BrowserXRRuntimeImpl* immersive_runtime =
runtime_manager_->GetCurrentlyPresentingImmersiveRuntime();
if (immersive_runtime) {
immersive_runtime->SetFramesThrottled(this, frames_throttled_);
......
......@@ -35,7 +35,7 @@ namespace vr {
class XRRuntimeManager;
class XRRuntimeManagerTest;
class BrowserXRRuntime;
class BrowserXRRuntimeImpl;
// Browser process implementation of the VRService mojo interface. Instantiated
// through Mojo once the user loads a page containing WebXR.
......@@ -73,7 +73,7 @@ class VRServiceImpl : public device::mojom::VRService,
// it.
void OnInlineSessionDisconnected(mojo::RemoteSetElementId session_id);
// Notifications/calls from BrowserXRRuntime:
// Notifications/calls from BrowserXRRuntimeImpl:
void OnExitPresent();
void OnVisibilityStateChanged(
device::mojom::XRVisibilityState visibility_state);
......@@ -134,7 +134,8 @@ class VRServiceImpl : public device::mojom::VRService,
// has already been granted), then it will directly call
// EnsureRuntimeInstalled. DoRequestSession will continue with OnInline or
// OnImmersive SessionCreated depending on the type of session created.
void ShowConsentPrompt(SessionRequestData request, BrowserXRRuntime* runtime);
void ShowConsentPrompt(SessionRequestData request,
BrowserXRRuntimeImpl* runtime);
void OnConsentResult(SessionRequestData request,
XrConsentPromptLevel consent_level,
......@@ -144,7 +145,7 @@ class VRServiceImpl : public device::mojom::VRService,
ContentSetting setting_value);
void EnsureRuntimeInstalled(SessionRequestData request,
BrowserXRRuntime* runtime);
BrowserXRRuntimeImpl* runtime);
void OnInstallResult(SessionRequestData request_data, bool install_succeeded);
void DoRequestSession(SessionRequestData request);
......
......@@ -12,7 +12,7 @@
#include "base/memory/singleton.h"
#include "base/trace_event/common/trace_event_common.h"
#include "build/build_config.h"
#include "chrome/browser/vr/service/browser_xr_runtime.h"
#include "chrome/browser/vr/service/browser_xr_runtime_impl.h"
#include "chrome/common/chrome_features.h"
#include "content/public/browser/device_service.h"
#include "content/public/common/content_features.h"
......@@ -174,7 +174,8 @@ void XRRuntimeManager::RemoveService(VRServiceImpl* service) {
}
}
BrowserXRRuntime* XRRuntimeManager::GetRuntime(device::mojom::XRDeviceId id) {
BrowserXRRuntimeImpl* XRRuntimeManager::GetRuntime(
device::mojom::XRDeviceId id) {
auto it = runtimes_.find(id);
if (it == runtimes_.end())
return nullptr;
......@@ -182,9 +183,9 @@ BrowserXRRuntime* XRRuntimeManager::GetRuntime(device::mojom::XRDeviceId id) {
return it->second.get();
}
BrowserXRRuntime* XRRuntimeManager::GetRuntimeForOptions(
BrowserXRRuntimeImpl* XRRuntimeManager::GetRuntimeForOptions(
device::mojom::XRSessionOptions* options) {
BrowserXRRuntime* runtime = nullptr;
BrowserXRRuntimeImpl* runtime = nullptr;
switch (options->mode) {
case device::mojom::XRSessionMode::kImmersiveAr:
runtime = GetRuntime(device::mojom::XRDeviceId::ARCORE_DEVICE_ID);
......@@ -206,7 +207,7 @@ BrowserXRRuntime* XRRuntimeManager::GetRuntimeForOptions(
: nullptr;
}
BrowserXRRuntime* XRRuntimeManager::GetImmersiveVrRuntime() {
BrowserXRRuntimeImpl* XRRuntimeManager::GetImmersiveVrRuntime() {
#if defined(OS_ANDROID)
auto* gvr = GetRuntime(device::mojom::XRDeviceId::GVR_DEVICE_ID);
if (gvr)
......@@ -240,7 +241,7 @@ BrowserXRRuntime* XRRuntimeManager::GetImmersiveVrRuntime() {
return nullptr;
}
BrowserXRRuntime* XRRuntimeManager::GetImmersiveArRuntime() {
BrowserXRRuntimeImpl* XRRuntimeManager::GetImmersiveArRuntime() {
device::mojom::XRSessionOptions options = {};
options.mode = device::mojom::XRSessionMode::kImmersiveAr;
return GetRuntimeForOptions(&options);
......@@ -294,7 +295,8 @@ device::mojom::VRDisplayInfoPtr XRRuntimeManager::GetCurrentVRDisplayInfo(
return device_info;
}
BrowserXRRuntime* XRRuntimeManager::GetCurrentlyPresentingImmersiveRuntime() {
BrowserXRRuntimeImpl*
XRRuntimeManager::GetCurrentlyPresentingImmersiveRuntime() {
auto* vr_runtime = GetImmersiveVrRuntime();
if (vr_runtime && vr_runtime->GetServiceWithActiveImmersiveSession()) {
return vr_runtime;
......@@ -420,8 +422,8 @@ void XRRuntimeManager::AddRuntime(
TRACE_EVENT_INSTANT1("xr", "AddRuntime", TRACE_EVENT_SCOPE_THREAD, "id", id);
runtimes_[id] = std::make_unique<BrowserXRRuntime>(id, std::move(runtime),
std::move(info));
runtimes_[id] = std::make_unique<BrowserXRRuntimeImpl>(id, std::move(runtime),
std::move(info));
for (XRRuntimeManagerObserver& obs : g_xr_runtime_manager_observers.Get())
obs.OnRuntimeAdded(runtimes_[id].get());
......@@ -446,7 +448,7 @@ void XRRuntimeManager::RemoveRuntime(device::mojom::XRDeviceId id) {
// Remove the runtime from runtimes_ before notifying services that it was
// removed, since they will query for runtimes in RuntimesChanged.
std::unique_ptr<BrowserXRRuntime> removed_runtime = std::move(it->second);
std::unique_ptr<BrowserXRRuntimeImpl> removed_runtime = std::move(it->second);
runtimes_.erase(it);
for (VRServiceImpl* service : services_)
......
......@@ -18,6 +18,7 @@
#include "base/optional.h"
#include "base/threading/thread_checker.h"
#include "base/timer/timer.h"
#include "chrome/browser/vr/service/browser_xr_runtime_impl.h"
#include "chrome/browser/vr/service/vr_service_impl.h"
#include "chrome/browser/vr/service/xr_runtime_manager_observer.h"
#include "device/vr/public/mojom/vr_service.mojom-forward.h"
......@@ -30,7 +31,7 @@ class VRDeviceProvider;
namespace vr {
class BrowserXRRuntime;
// class BrowserXRRuntimeImpl;
class XRRuntimeManagerTest;
// Singleton used to provide the platform's XR Runtimes to VRServiceImpl
......@@ -70,21 +71,21 @@ class XRRuntimeManager : public base::RefCounted<XRRuntimeManager> {
void AddService(VRServiceImpl* service);
void RemoveService(VRServiceImpl* service);
BrowserXRRuntime* GetRuntime(device::mojom::XRDeviceId id);
BrowserXRRuntimeImpl* GetRuntime(device::mojom::XRDeviceId id);
bool HasRuntime(device::mojom::XRDeviceId id);
BrowserXRRuntime* GetRuntimeForOptions(
BrowserXRRuntimeImpl* GetRuntimeForOptions(
device::mojom::XRSessionOptions* options);
// Gets the system default immersive-vr runtime if available.
BrowserXRRuntime* GetImmersiveVrRuntime();
BrowserXRRuntimeImpl* GetImmersiveVrRuntime();
// Gets the system default immersive-ar runtime if available.
BrowserXRRuntime* GetImmersiveArRuntime();
BrowserXRRuntimeImpl* GetImmersiveArRuntime();
// Gets the runtime matching a currently-active immersive session, if any.
// This is either the VR or AR runtime, or null if there's no matching
// runtime or if there's no active immersive session.
BrowserXRRuntime* GetCurrentlyPresentingImmersiveRuntime();
BrowserXRRuntimeImpl* GetCurrentlyPresentingImmersiveRuntime();
device::mojom::VRDisplayInfoPtr GetCurrentVRDisplayInfo(
VRServiceImpl* service);
......@@ -133,9 +134,10 @@ class XRRuntimeManager : public base::RefCounted<XRRuntimeManager> {
ProviderList providers_;
// XRRuntimes are owned by their providers, each correspond to a
// BrowserXRRuntime that is owned by XRRuntimeManager.
using DeviceRuntimeMap = base::small_map<
std::map<device::mojom::XRDeviceId, std::unique_ptr<BrowserXRRuntime>>>;
// BrowserXRRuntimeImpl that is owned by XRRuntimeManager.
using DeviceRuntimeMap =
base::small_map<std::map<device::mojom::XRDeviceId,
std::unique_ptr<BrowserXRRuntimeImpl>>>;
DeviceRuntimeMap runtimes_;
bool providers_initialized_ = false;
......
......@@ -9,13 +9,15 @@
#include "chrome/browser/vr/vr_export.h"
#include "device/vr/public/mojom/vr_service.mojom-forward.h"
namespace vr {
namespace content {
class BrowserXRRuntime;
}
namespace vr {
class VR_EXPORT XRRuntimeManagerObserver : public base::CheckedObserver {
public:
virtual void OnRuntimeAdded(vr::BrowserXRRuntime* runtime) = 0;
virtual void OnRuntimeAdded(content::BrowserXRRuntime* runtime) = 0;
};
} // namespace vr
......
......@@ -15,7 +15,6 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/usb/usb_tab_helper.h"
#include "chrome/browser/vr/service/browser_xr_runtime.h"
#include "chrome/browser/vr/service/xr_runtime_manager.h"
#include "chrome/browser/vr/vr_tab_helper.h"
#include "chrome/browser/vr/win/vr_browser_renderer_thread_win.h"
......@@ -131,7 +130,7 @@ VRUiHostImpl::VRUiHostImpl(
auto* runtime_manager = XRRuntimeManager::GetInstanceIfCreated();
DCHECK(runtime_manager != nullptr);
BrowserXRRuntime* runtime = runtime_manager->GetRuntime(device_id);
BrowserXRRuntimeImpl* runtime = runtime_manager->GetRuntime(device_id);
if (runtime) {
runtime->AddObserver(this);
}
......@@ -144,9 +143,9 @@ VRUiHostImpl::~VRUiHostImpl() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DVLOG(1) << __func__;
// We don't call BrowserXRRuntime::RemoveObserver, because if we are being
// We don't call BrowserXRRuntimeImpl::RemoveObserver, because if we are being
// destroyed, it means the corresponding device has been removed from
// XRRuntimeManager, and the BrowserXRRuntime has been destroyed.
// XRRuntimeManager, and the BrowserXRRuntimeImpl has been destroyed.
if (web_contents_)
SetWebXRWebContents(nullptr);
}
......
......@@ -12,11 +12,12 @@
#include "base/threading/thread_checker.h"
#include "chrome/browser/media/webrtc/desktop_media_picker_manager.h"
#include "chrome/browser/vr/model/capturing_state_model.h"
#include "chrome/browser/vr/service/browser_xr_runtime.h"
#include "components/bubble/bubble_manager.h"
#include "components/permissions/permission_request_manager.h"
#include "content/public/browser/browser_xr_runtime.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/xr_integration_client.h"
#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/geolocation_config.mojom.h"
......@@ -29,7 +30,7 @@ class VRBrowserRendererThreadWin;
// component. Used on the browser's main thread.
class VRUiHostImpl : public content::VrUiHost,
public permissions::PermissionRequestManager::Observer,
public BrowserXRRuntimeObserver,
public content::BrowserXRRuntime::Observer,
public BubbleManager::BubbleManagerObserver,
public DesktopMediaPickerManager::DialogObserver {
public:
......@@ -66,7 +67,7 @@ class VRUiHostImpl : public content::VrUiHost,
CapturingStateModel* active_capture_state_model_; // Not owned.
};
// BrowserXRRuntimeObserver implementation.
// content::BrowserXRRuntime::Observer implementation.
void SetWebXRWebContents(content::WebContents* contents) override;
void SetVRDisplayInfo(device::mojom::VRDisplayInfoPtr display_info) override;
void SetFramesThrottled(bool throttled) override;
......
......@@ -510,6 +510,7 @@ jumbo_source_set("browser_sources") {
if (enable_vr) {
sources += [
"browser_xr_runtime.h",
"xr_install_helper.h",
"xr_integration_client.cc",
"xr_integration_client.h",
......
// Copyright 2020 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 CONTENT_PUBLIC_BROWSER_BROWSER_XR_RUNTIME_H_
#define CONTENT_PUBLIC_BROWSER_BROWSER_XR_RUNTIME_H_
#include "base/observer_list_types.h"
#include "content/common/content_export.h"
#include "device/vr/public/mojom/vr_service.mojom-forward.h"
namespace content {
class WebContents;
}
namespace content {
// This interface allows observing the state of the XR service for a particular
// runtime. In particular, observers may currently know when the browser
// considers a WebContents presenting to an immersive headset. Implementers of
// this interface will be called on the main browser thread. Currently this is
// used on Windows to drive overlays.
class CONTENT_EXPORT BrowserXRRuntime {
public:
class Observer : public base::CheckedObserver {
public:
virtual void SetVRDisplayInfo(
device::mojom::VRDisplayInfoPtr display_info) {}
// The parameter |contents| is set when a page starts an immersive WebXR
// session. There can only be at most one active immersive session for the
// XRRuntime. Set to null when there is no active immersive session.
virtual void SetWebXRWebContents(content::WebContents* contents) {}
virtual void SetFramesThrottled(bool throttled) {}
};
virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
virtual void SetInlinePosesEnabled(bool enabled) = 0;
};
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_BROWSER_XR_RUNTIME_H_
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