Commit 7a7288d7 authored by amp's avatar amp Committed by Commit Bot

[WebVR] Only count devices that have successfully connected.

This allows the navigator.GetVRDisplays() promise to resolve when the
underlying VR libraries are not installed or out of date.

BUG=727969

Review-Url: https://codereview.chromium.org/2915993004
Cr-Commit-Position: refs/heads/master@{#476516}
parent 62433b1a
......@@ -15,7 +15,9 @@
namespace device {
VRServiceImpl::VRServiceImpl()
: listening_for_activate_(false), weak_ptr_factory_(this) {}
: listening_for_activate_(false),
connected_devices_(0),
weak_ptr_factory_(this) {}
VRServiceImpl::~VRServiceImpl() {
// Destroy VRDisplay before calling RemoveService below. RemoveService might
......@@ -35,13 +37,12 @@ void VRServiceImpl::SetClient(mojom::VRServiceClientPtr service_client,
SetClientCallback callback) {
DCHECK(!client_.get());
client_ = std::move(service_client);
VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
// Once a client has been connected AddService will force any VRDisplays to
// send ConnectDevice to it so that it's populated with the currently active
// displays. Thereafter it will stay up to date by virtue of listening for new
// connected events.
device_manager->AddService(this);
std::move(callback).Run(device_manager->GetNumberOfConnectedDevices());
VRDeviceManager::GetInstance()->AddService(this);
std::move(callback).Run(connected_devices_);
}
void VRServiceImpl::ConnectDevice(VRDevice* device) {
......@@ -70,14 +71,16 @@ void VRServiceImpl::OnVRDisplayInfoCreated(
"process is not established";
return;
}
if (!display_info) {
// If we get passed a null display info it means the device does not exist.
// This can happen for example if VR services are not installed. We will not
// instantiate a display in this case.
// instantiate a display in this case and don't count it as connected.
return;
}
displays_[device] = base::MakeUnique<VRDisplayImpl>(
device, this, client_.get(), std::move(display_info));
connected_devices_++;
}
VRDisplayImpl* VRServiceImpl::GetVRDisplayImplForTesting(VRDevice* device) {
......
......@@ -60,6 +60,7 @@ class VRServiceImpl : public mojom::VRService {
mojom::VRServiceClientPtr client_;
bool listening_for_activate_;
unsigned connected_devices_;
base::WeakPtrFactory<VRServiceImpl> weak_ptr_factory_;
......
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