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