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 6ea486de284d4d5e0e37bb7a7a36adb172b41a6b..8df9c4827d093a51bea002ff9c0b85b3d2905017 100644 |
| --- a/device/vr/vr_service_impl.cc |
| +++ b/device/vr/vr_service_impl.cc |
| @@ -18,74 +18,52 @@ VRServiceImpl::~VRServiceImpl() { |
| RemoveFromDeviceManager(); |
| } |
| -void VRServiceImpl::BindRequest(mojo::InterfaceRequest<VRService> request) { |
| +void VRServiceImpl::BindRequest( |
| + mojo::InterfaceRequest<mojom::VRService> request) { |
| VRServiceImpl* service = new VRServiceImpl(); |
| service->Bind(std::move(request)); |
| } |
| -void VRServiceImpl::Bind(mojo::InterfaceRequest<VRService> request) { |
| - binding_.reset(new mojo::Binding<VRService>(this, 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) { |
| + DisplayImplMap::iterator it = displays_.find(device); |
| + if (it != displays_.end()) |
| + return it->second.get(); |
| + |
| + VRDisplayImpl* display_impl = new VRDisplayImpl(device, this); |
| + displays_[device] = std::unique_ptr<VRDisplayImpl>(display_impl); |
|
dcheng
2016/11/04 05:12:21
Nit: use base::WrapUnique()
shaobo.yan
2016/11/05 08:11:39
Thx for telling me that.Updated
|
| + return display_impl; |
| +} |
| + |
| +void VRServiceImpl::Bind(mojo::InterfaceRequest<mojom::VRService> request) { |
| + binding_.reset(new mojo::Binding<mojom::VRService>(this, std::move(request))); |
|
dcheng
2016/11/04 05:12:21
This should just be a mojo::Binding<mojom::VRServi
shaobo.yan
2016/11/05 08:11:39
Does it means that we shouldn't abandon the mojo::
dcheng
2016/11/08 08:55:16
Actually, from what I can tell, we seem to create
|
| binding_->set_connection_error_handler(base::Bind( |
| &VRServiceImpl::RemoveFromDeviceManager, base::Unretained(this))); |
| } |
| void VRServiceImpl::RemoveFromDeviceManager() { |
| + displays_.clear(); |
| VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); |
| device_manager->RemoveService(this); |
| } |
| -void VRServiceImpl::SetClient(VRServiceClientPtr client) { |
| - DCHECK(!client_.get()); |
| - |
| - client_ = std::move(client); |
| - VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); |
| - device_manager->AddService(this); |
| -} |
| - |
| -void VRServiceImpl::GetDisplays(const GetDisplaysCallback& callback) { |
| - VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); |
| - callback.Run(device_manager->GetVRDevices()); |
| -} |
| - |
| -void VRServiceImpl::GetPose(uint32_t index, const GetPoseCallback& callback) { |
| - VRDevice* device = VRDeviceManager::GetAllowedDevice(this, index); |
| - |
| - if (device) { |
| - callback.Run(device->GetPose()); |
| - } else { |
| - callback.Run(nullptr); |
| - } |
| -} |
| - |
| -void VRServiceImpl::ResetPose(uint32_t index) { |
| - VRDevice* device = VRDeviceManager::GetAllowedDevice(this, index); |
| - if (device) |
| - device->ResetPose(); |
| -} |
| - |
| -void VRServiceImpl::RequestPresent(uint32_t index, |
| - bool secureOrigin, |
| - const RequestPresentCallback& callback) { |
| - VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); |
| - callback.Run(device_manager->RequestPresent(this, index, secureOrigin)); |
| +void VRServiceImpl::RemoveDevice(VRDevice* device) { |
| + displays_.erase(device); |
| } |
| -void VRServiceImpl::ExitPresent(uint32_t index) { |
| - VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); |
| - device_manager->ExitPresent(this, index); |
| -} |
| +void VRServiceImpl::SetClient(mojom::VRServiceClientPtr service_client, |
| + const SetClientCallback& callback) { |
| + DCHECK(!client_.get()); |
| -void VRServiceImpl::SubmitFrame(uint32_t index, VRPosePtr pose) { |
| + client_ = std::move(service_client); |
| VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); |
| - device_manager->SubmitFrame(this, index, std::move(pose)); |
| -} |
| - |
| -void VRServiceImpl::UpdateLayerBounds(uint32_t index, |
| - VRLayerBoundsPtr leftBounds, |
| - VRLayerBoundsPtr rightBounds) { |
| - VRDevice* device = VRDeviceManager::GetAllowedDevice(this, index); |
| - if (device) |
| - device->UpdateLayerBounds(std::move(leftBounds), std::move(rightBounds)); |
| + // Once a client has been connected AddService will force any VRDisplays to |
| + // send OnConnected to it so that it's populated with the currently active |
| + // displays. Thereafer it will stay up to date by virtue of listening for new |
| + // connected events. |
| + device_manager->AddService(this); |
| + callback.Run(device_manager->GetDevicesNum()); |
| } |
| } // namespace device |