Chromium Code Reviews| Index: device/vr/vr_service_impl.cc |
| diff --git a/device/vr/vr_service_impl.cc b/device/vr/vr_service_impl.cc |
| index 9d0fb36618c53e59443d23faf2597e3da3f59b4d..8d64b8e801761d875d12a51858bc19a454e9365d 100644 |
| --- a/device/vr/vr_service_impl.cc |
| +++ b/device/vr/vr_service_impl.cc |
| @@ -14,7 +14,8 @@ |
| namespace device { |
| -VRServiceImpl::VRServiceImpl() : listening_for_activate_(false) {} |
| +VRServiceImpl::VRServiceImpl() |
| + : listening_for_activate_(false), weak_ptr_factory_(this) {} |
| VRServiceImpl::~VRServiceImpl() { |
| // Destroy VRDisplay before calling RemoveService below. RemoveService might |
| @@ -29,22 +30,6 @@ void VRServiceImpl::Create(mojo::InterfaceRequest<mojom::VRService> request) { |
| std::move(request)); |
| } |
| -// Gets a VRDisplayPtr unique to this service so that the associated page can |
| -// communicate with the VRDevice. |
| -VRDisplayImpl* VRServiceImpl::GetVRDisplayImpl(VRDevice* device) { |
| - auto it = displays_.find(device); |
| - if (it != displays_.end()) |
| - return it->second.get(); |
| - |
| - VRDisplayImpl* display_impl = new VRDisplayImpl(device, this); |
| - displays_[device] = base::WrapUnique(display_impl); |
| - return display_impl; |
| -} |
| - |
| -void VRServiceImpl::RemoveDevice(VRDevice* device) { |
| - displays_.erase(device); |
| -} |
| - |
| void VRServiceImpl::SetClient(mojom::VRServiceClientPtr service_client, |
| const SetClientCallback& callback) { |
| DCHECK(!client_.get()); |
| @@ -58,10 +43,35 @@ void VRServiceImpl::SetClient(mojom::VRServiceClientPtr service_client, |
| callback.Run(device_manager->GetNumberOfConnectedDevices()); |
| } |
| +void VRServiceImpl::ConnectDevice(VRDevice* device) { |
|
amp
2017/03/13 22:26:05
There still seems to be a mismatch between display
tiborg
2017/03/13 23:00:58
I agree, it's a bit confusing. Currently a display
bajones
2017/03/13 23:04:57
Oh, and just to make things MORE confusing we're g
amp
2017/03/14 17:05:50
Yea let's handle cleaning this up in a future chan
|
| + DCHECK(displays_.count(device) == 0); |
| + // TODO(crbug/701027): make sure that client_ is never null by initializing it |
| + // in the constructor. |
| + DCHECK(client_); |
| + base::Callback<void(mojom::VRDisplayInfoPtr)> onCreated = |
| + base::Bind(&VRServiceImpl::OnVRDisplayInfoCreated, |
| + weak_ptr_factory_.GetWeakPtr(), device); |
| + device->CreateVRDisplayInfo(onCreated); |
| +} |
| + |
| void VRServiceImpl::SetListeningForActivate(bool listening) { |
| listening_for_activate_ = listening; |
| VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); |
| device_manager->ListeningForActivateChanged(listening); |
| } |
| +// Creates a VRDisplayPtr unique to this service so that the associated page can |
| +// communicate with the VRDevice. |
| +void VRServiceImpl::OnVRDisplayInfoCreated( |
| + VRDevice* device, |
| + mojom::VRDisplayInfoPtr display_info) { |
| + displays_[device] = base::MakeUnique<VRDisplayImpl>( |
| + device, this, client_.get(), std::move(display_info)); |
| +} |
| + |
| +VRDisplayImpl* VRServiceImpl::GetVRDisplayImpl(VRDevice* device) { |
| + auto it = displays_.find(device); |
| + return (it == displays_.end()) ? nullptr : it->second.get(); |
| +} |
| + |
| } // namespace device |