OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/vr/vr_service_impl.h" |
| 6 |
| 7 #include "base/location.h" |
| 8 #include "content/browser/vr/vr_device_manager.h" |
| 9 |
| 10 namespace content { |
| 11 |
| 12 void VRServiceImpl::Create(mojo::InterfaceRequest<VRService> request) { |
| 13 VRServiceImpl* service = new VRServiceImpl(); |
| 14 mojo::BindToRequest(service, &request); |
| 15 } |
| 16 |
| 17 VRServiceImpl::VRServiceImpl() : registered_with_device_manager_(false) { |
| 18 } |
| 19 |
| 20 VRServiceImpl::~VRServiceImpl() { |
| 21 if (registered_with_device_manager_) { |
| 22 VRDeviceManager::RemoveService(this); |
| 23 } |
| 24 } |
| 25 |
| 26 VRDeviceManager* VRServiceImpl::GetDeviceManager() { |
| 27 if (!registered_with_device_manager_) { |
| 28 VRDeviceManager::AddService(this); |
| 29 registered_with_device_manager_ = true; |
| 30 } |
| 31 return VRDeviceManager::GetInstance(); |
| 32 } |
| 33 |
| 34 void VRServiceImpl::GetDevices(const GetDevicesCallback& callback) { |
| 35 callback.Run(GetDeviceManager()->GetVRDevices()); |
| 36 } |
| 37 |
| 38 void VRServiceImpl::GetSensorState(uint32_t index, |
| 39 const GetSensorStateCallback& callback) { |
| 40 VRDevice* device = GetDeviceManager()->GetDevice(index); |
| 41 if (device) { |
| 42 callback.Run(device->GetSensorState()); |
| 43 } else { |
| 44 callback.Run(nullptr); |
| 45 } |
| 46 } |
| 47 |
| 48 void VRServiceImpl::ResetSensor(uint32_t index) { |
| 49 VRDevice* device = GetDeviceManager()->GetDevice(index); |
| 50 if (device) |
| 51 device->ResetSensor(); |
| 52 } |
| 53 |
| 54 } // namespace content |
OLD | NEW |