Commit 0f8779d0 authored by Bill Orr's avatar Bill Orr Committed by Commit Bot

Remove IsFallbackDevice from VRDevice.

This change removes a synchronous call from browser code into VRDevice,
in anticipation of making VRDevice a mojo interface.

Browser-side now controls whether a device is fallback.

The change here is temporary until further refactors to support XR.
Fallback devices will be removed, and requestSession will have more logic
to determine which device should be returned.

Change-Id: I4707eecf3a0ca8356f7139934c2e1fc79f934d37
Reviewed-on: https://chromium-review.googlesource.com/1080039Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Bill Orr <billorr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#563057}
parent f0f9de6c
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
namespace vr { namespace vr {
BrowserXrDevice::BrowserXrDevice(device::VRDevice* device) BrowserXrDevice::BrowserXrDevice(device::VRDevice* device, bool is_fallback)
: device_(device), weak_ptr_factory_(this) { : device_(device), is_fallback_(is_fallback), weak_ptr_factory_(this) {
device_->SetVRDeviceEventListener(this); device_->SetVRDeviceEventListener(this);
} }
......
...@@ -17,7 +17,7 @@ class VRDisplayHost; ...@@ -17,7 +17,7 @@ class VRDisplayHost;
// listening for device activation. // listening for device activation.
class BrowserXrDevice : public device::VRDeviceEventListener { class BrowserXrDevice : public device::VRDeviceEventListener {
public: public:
explicit BrowserXrDevice(device::VRDevice* device); explicit BrowserXrDevice(device::VRDevice* device, bool is_fallback);
~BrowserXrDevice() override; ~BrowserXrDevice() override;
device::VRDevice* GetDevice() { return device_; } device::VRDevice* GetDevice() { return device_; }
...@@ -42,6 +42,9 @@ class BrowserXrDevice : public device::VRDeviceEventListener { ...@@ -42,6 +42,9 @@ class BrowserXrDevice : public device::VRDeviceEventListener {
VRDisplayHost* GetPresentingDisplayHost() { return presenting_display_host_; } VRDisplayHost* GetPresentingDisplayHost() { return presenting_display_host_; }
void UpdateListeningForActivate(VRDisplayHost* display); void UpdateListeningForActivate(VRDisplayHost* display);
// Methods called by VRDeviceManager to inspect the device.
bool IsFallbackDevice() { return is_fallback_; }
private: private:
void OnListeningForActivate(bool is_listening); void OnListeningForActivate(bool is_listening);
void OnRequestPresentResult( void OnRequestPresentResult(
...@@ -56,6 +59,7 @@ class BrowserXrDevice : public device::VRDeviceEventListener { ...@@ -56,6 +59,7 @@ class BrowserXrDevice : public device::VRDeviceEventListener {
std::set<VRDisplayHost*> displays_; std::set<VRDisplayHost*> displays_;
VRDisplayHost* listening_for_activation_display_host_ = nullptr; VRDisplayHost* listening_for_activation_display_host_ = nullptr;
VRDisplayHost* presenting_display_host_ = nullptr; VRDisplayHost* presenting_display_host_ = nullptr;
bool is_fallback_;
base::WeakPtrFactory<BrowserXrDevice> weak_ptr_factory_; base::WeakPtrFactory<BrowserXrDevice> weak_ptr_factory_;
}; };
......
...@@ -45,6 +45,7 @@ VRDeviceManager* VRDeviceManager::GetInstance() { ...@@ -45,6 +45,7 @@ VRDeviceManager* VRDeviceManager::GetInstance() {
if (!g_vr_device_manager) { if (!g_vr_device_manager) {
// Register VRDeviceProviders for the current platform // Register VRDeviceProviders for the current platform
ProviderList providers; ProviderList providers;
ProviderList fallback_providers;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// TODO(https://crbug.com/828321): when we support multiple devices and // TODO(https://crbug.com/828321): when we support multiple devices and
...@@ -77,13 +78,13 @@ VRDeviceManager* VRDeviceManager::GetInstance() { ...@@ -77,13 +78,13 @@ VRDeviceManager* VRDeviceManager::GetInstance() {
content::ServiceManagerConnection* connection = content::ServiceManagerConnection* connection =
content::ServiceManagerConnection::GetForProcess(); content::ServiceManagerConnection::GetForProcess();
if (connection) { if (connection) {
providers.emplace_back( fallback_providers.emplace_back(
std::make_unique<device::VROrientationDeviceProvider>( std::make_unique<device::VROrientationDeviceProvider>(
connection->GetConnector())); connection->GetConnector()));
} }
} }
new VRDeviceManager(std::move(providers)); new VRDeviceManager(std::move(providers), std::move(fallback_providers));
} }
return g_vr_device_manager; return g_vr_device_manager;
} }
...@@ -92,8 +93,10 @@ bool VRDeviceManager::HasInstance() { ...@@ -92,8 +93,10 @@ bool VRDeviceManager::HasInstance() {
return g_vr_device_manager != nullptr; return g_vr_device_manager != nullptr;
} }
VRDeviceManager::VRDeviceManager(ProviderList providers) VRDeviceManager::VRDeviceManager(ProviderList providers,
: providers_(std::move(providers)) { ProviderList fallback_providers)
: providers_(std::move(providers)),
fallback_providers_(std::move(fallback_providers)) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
CHECK(!g_vr_device_manager); CHECK(!g_vr_device_manager);
g_vr_device_manager = this; g_vr_device_manager = this;
...@@ -113,8 +116,7 @@ void VRDeviceManager::AddService(VRServiceImpl* service) { ...@@ -113,8 +116,7 @@ void VRDeviceManager::AddService(VRServiceImpl* service) {
InitializeProviders(); InitializeProviders();
for (const DeviceMap::value_type& map_entry : devices_) { for (const DeviceMap::value_type& map_entry : devices_) {
if (!map_entry.second->GetDevice()->IsFallbackDevice() || if (!map_entry.second->IsFallbackDevice() || devices_.size() == 1)
devices_.size() == 1)
service->ConnectDevice(map_entry.second.get()); service->ConnectDevice(map_entry.second.get());
} }
...@@ -134,7 +136,7 @@ void VRDeviceManager::RemoveService(VRServiceImpl* service) { ...@@ -134,7 +136,7 @@ void VRDeviceManager::RemoveService(VRServiceImpl* service) {
} }
} }
void VRDeviceManager::AddDevice(device::VRDevice* device) { void VRDeviceManager::AddDevice(bool is_fallback, device::VRDevice* device) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(devices_.find(device->GetId()) == devices_.end()); DCHECK(devices_.find(device->GetId()) == devices_.end());
// Ignore any devices with VR_DEVICE_LAST_ID, which is used to prevent // Ignore any devices with VR_DEVICE_LAST_ID, which is used to prevent
...@@ -146,15 +148,15 @@ void VRDeviceManager::AddDevice(device::VRDevice* device) { ...@@ -146,15 +148,15 @@ void VRDeviceManager::AddDevice(device::VRDevice* device) {
// TODO(offenwanger): This has the potential to cause device change events to // TODO(offenwanger): This has the potential to cause device change events to
// fire in rapid succession. This should be discussed and resolved when we // fire in rapid succession. This should be discussed and resolved when we
// start to actually add and remove devices. // start to actually add and remove devices.
if (devices_.size() == 1 && if (devices_.size() == 1 && devices_.begin()->second->IsFallbackDevice()) {
devices_.begin()->second->GetDevice()->IsFallbackDevice()) {
BrowserXrDevice* device = devices_.begin()->second.get(); BrowserXrDevice* device = devices_.begin()->second.get();
for (VRServiceImpl* service : services_) for (VRServiceImpl* service : services_)
service->RemoveDevice(device); service->RemoveDevice(device);
} }
devices_[device->GetId()] = std::make_unique<BrowserXrDevice>(device); devices_[device->GetId()] =
if (!device->IsFallbackDevice() || devices_.size() == 1) { std::make_unique<BrowserXrDevice>(device, is_fallback);
if (!is_fallback || devices_.size() == 1) {
BrowserXrDevice* device_to_add = devices_[device->GetId()].get(); BrowserXrDevice* device_to_add = devices_[device->GetId()].get();
for (VRServiceImpl* service : services_) for (VRServiceImpl* service : services_)
service->ConnectDevice(device_to_add); service->ConnectDevice(device_to_add);
...@@ -173,8 +175,7 @@ void VRDeviceManager::RemoveDevice(device::VRDevice* device) { ...@@ -173,8 +175,7 @@ void VRDeviceManager::RemoveDevice(device::VRDevice* device) {
devices_.erase(it); devices_.erase(it);
if (devices_.size() == 1 && if (devices_.size() == 1 && devices_.begin()->second->IsFallbackDevice()) {
devices_.begin()->second->GetDevice()->IsFallbackDevice()) {
BrowserXrDevice* device = devices_.begin()->second.get(); BrowserXrDevice* device = devices_.begin()->second.get();
for (VRServiceImpl* service : services_) for (VRServiceImpl* service : services_)
service->ConnectDevice(device); service->ConnectDevice(device);
...@@ -205,12 +206,23 @@ void VRDeviceManager::InitializeProviders() { ...@@ -205,12 +206,23 @@ void VRDeviceManager::InitializeProviders() {
return; return;
for (const auto& provider : providers_) { for (const auto& provider : providers_) {
provider->Initialize(base::BindRepeating(&VRDeviceManager::AddDevice, provider->Initialize(
base::Unretained(this)), base::BindRepeating(&VRDeviceManager::AddDevice, base::Unretained(this),
base::BindRepeating(&VRDeviceManager::RemoveDevice, false /* is_fallback */),
base::Unretained(this)), base::BindRepeating(&VRDeviceManager::RemoveDevice,
base::BindOnce(&VRDeviceManager::OnProviderInitialized, base::Unretained(this)),
base::Unretained(this))); base::BindOnce(&VRDeviceManager::OnProviderInitialized,
base::Unretained(this)));
}
for (const auto& provider : fallback_providers_) {
provider->Initialize(
base::BindRepeating(&VRDeviceManager::AddDevice, base::Unretained(this),
true /* is_fallback */),
base::BindRepeating(&VRDeviceManager::RemoveDevice,
base::Unretained(this)),
base::BindOnce(&VRDeviceManager::OnProviderInitialized,
base::Unretained(this)));
} }
providers_initialized_ = true; providers_initialized_ = true;
...@@ -227,7 +239,8 @@ void VRDeviceManager::OnProviderInitialized() { ...@@ -227,7 +239,8 @@ void VRDeviceManager::OnProviderInitialized() {
bool VRDeviceManager::AreAllProvidersInitialized() { bool VRDeviceManager::AreAllProvidersInitialized() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
return num_initialized_providers_ == providers_.size(); return num_initialized_providers_ ==
providers_.size() + fallback_providers_.size();
} }
size_t VRDeviceManager::NumberOfConnectedServices() { size_t VRDeviceManager::NumberOfConnectedServices() {
......
...@@ -53,7 +53,8 @@ class VR_EXPORT VRDeviceManager { ...@@ -53,7 +53,8 @@ class VR_EXPORT VRDeviceManager {
using ProviderList = std::vector<std::unique_ptr<device::VRDeviceProvider>>; using ProviderList = std::vector<std::unique_ptr<device::VRDeviceProvider>>;
// Used by tests to supply providers. // Used by tests to supply providers.
explicit VRDeviceManager(ProviderList providers); explicit VRDeviceManager(ProviderList providers,
ProviderList fallback_providers);
// Used by tests to check on device state. // Used by tests to check on device state.
device::VRDevice* GetDevice(unsigned int index); device::VRDevice* GetDevice(unsigned int index);
...@@ -65,10 +66,11 @@ class VR_EXPORT VRDeviceManager { ...@@ -65,10 +66,11 @@ class VR_EXPORT VRDeviceManager {
void OnProviderInitialized(); void OnProviderInitialized();
bool AreAllProvidersInitialized(); bool AreAllProvidersInitialized();
void AddDevice(device::VRDevice* device); void AddDevice(bool is_fallback, device::VRDevice* device);
void RemoveDevice(device::VRDevice* device); void RemoveDevice(device::VRDevice* device);
ProviderList providers_; ProviderList providers_;
ProviderList fallback_providers_;
// VRDevices are owned by their providers, each correspond to a // VRDevices are owned by their providers, each correspond to a
// BrowserXrDevice that is owned by VRDeviceManager. // BrowserXrDevice that is owned by VRDeviceManager.
......
...@@ -25,8 +25,9 @@ namespace { ...@@ -25,8 +25,9 @@ namespace {
class VRDeviceManagerForTesting : public VRDeviceManager { class VRDeviceManagerForTesting : public VRDeviceManager {
public: public:
explicit VRDeviceManagerForTesting(ProviderList providers) explicit VRDeviceManagerForTesting(ProviderList providers,
: VRDeviceManager(std::move(providers)) {} ProviderList fallback_providers)
: VRDeviceManager(std::move(providers), std::move(fallback_providers)) {}
~VRDeviceManagerForTesting() override = default; ~VRDeviceManagerForTesting() override = default;
size_t NumberOfConnectedServices() { size_t NumberOfConnectedServices() {
...@@ -62,7 +63,9 @@ class VRDeviceManagerTest : public testing::Test { ...@@ -62,7 +63,9 @@ class VRDeviceManagerTest : public testing::Test {
provider_ = new device::FakeVRDeviceProvider(); provider_ = new device::FakeVRDeviceProvider();
providers.emplace_back( providers.emplace_back(
std::unique_ptr<device::FakeVRDeviceProvider>(provider_)); std::unique_ptr<device::FakeVRDeviceProvider>(provider_));
new VRDeviceManagerForTesting(std::move(providers)); std::vector<std::unique_ptr<device::VRDeviceProvider>> fallback_providers;
new VRDeviceManagerForTesting(std::move(providers),
std::move(fallback_providers));
} }
void TearDown() override { EXPECT_FALSE(VRDeviceManager::HasInstance()); } void TearDown() override { EXPECT_FALSE(VRDeviceManager::HasInstance()); }
......
...@@ -204,8 +204,4 @@ Quaternion VROrientationDevice::WorldSpaceToUserOrientedSpace(Quaternion q) { ...@@ -204,8 +204,4 @@ Quaternion VROrientationDevice::WorldSpaceToUserOrientedSpace(Quaternion q) {
return q; return q;
} }
bool VROrientationDevice::IsFallbackDevice() {
return true;
};
} // namespace device } // namespace device
...@@ -46,8 +46,6 @@ class DEVICE_VR_EXPORT VROrientationDevice : public VRDeviceBase, ...@@ -46,8 +46,6 @@ class DEVICE_VR_EXPORT VROrientationDevice : public VRDeviceBase,
void OnMagicWindowPoseRequest( void OnMagicWindowPoseRequest(
mojom::VRMagicWindowProvider::GetPoseCallback callback) override; mojom::VRMagicWindowProvider::GetPoseCallback callback) override;
bool IsFallbackDevice() override;
// Indicates whether the device was able to connect to orientation events. // Indicates whether the device was able to connect to orientation events.
bool IsAvailable() const { return available_; } bool IsAvailable() const { return available_; }
......
...@@ -72,9 +72,6 @@ class DEVICE_VR_EXPORT VRDevice { ...@@ -72,9 +72,6 @@ class DEVICE_VR_EXPORT VRDevice {
mojom::VRDisplayHost::RequestPresentCallback callback) = 0; mojom::VRDisplayHost::RequestPresentCallback callback) = 0;
virtual void SetListeningForActivate(bool is_listening) = 0; virtual void SetListeningForActivate(bool is_listening) = 0;
// The fallback device should only be provided in lieu of other devices.
virtual bool IsFallbackDevice() = 0;
// TODO(mthiesse): The browser should handle browser-side exiting of // TODO(mthiesse): The browser should handle browser-side exiting of
// presentation before device/ is even aware presentation is being exited. // presentation before device/ is even aware presentation is being exited.
// Then the browser should call ExitPresent() on Device, which does device/ // Then the browser should call ExitPresent() on Device, which does device/
......
...@@ -32,10 +32,6 @@ mojom::VRDisplayInfoPtr VRDeviceBase::GetVRDisplayInfo() { ...@@ -32,10 +32,6 @@ mojom::VRDisplayInfoPtr VRDeviceBase::GetVRDisplayInfo() {
return display_info_.Clone(); return display_info_.Clone();
} }
bool VRDeviceBase::IsFallbackDevice() {
return false;
};
void VRDeviceBase::OnExitPresent() { void VRDeviceBase::OnExitPresent() {
if (listener_) if (listener_)
listener_->OnExitPresent(); listener_->OnExitPresent();
......
...@@ -39,7 +39,6 @@ class DEVICE_VR_EXPORT VRDeviceBase : public VRDevice { ...@@ -39,7 +39,6 @@ class DEVICE_VR_EXPORT VRDeviceBase : public VRDevice {
mojom::VRRequestPresentOptionsPtr present_options, mojom::VRRequestPresentOptionsPtr present_options,
mojom::VRDisplayHost::RequestPresentCallback callback) override; mojom::VRDisplayHost::RequestPresentCallback callback) override;
void ExitPresent() override; void ExitPresent() override;
bool IsFallbackDevice() override;
void SetListeningForActivate(bool is_listening) override; void SetListeningForActivate(bool is_listening) override;
bool IsAccessAllowed(VRDisplayImpl* display); bool IsAccessAllowed(VRDisplayImpl* display);
......
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