| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DEVICE_VR_VR_DEVICE_MANAGER_H | 5 #ifndef DEVICE_VR_VR_DEVICE_MANAGER_H |
| 6 #define DEVICE_VR_VR_DEVICE_MANAGER_H | 6 #define DEVICE_VR_VR_DEVICE_MANAGER_H |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
| 16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "device/vr/vr_client_dispatcher.h" |
| 17 #include "device/vr/vr_device.h" | 18 #include "device/vr/vr_device.h" |
| 18 #include "device/vr/vr_device_provider.h" | 19 #include "device/vr/vr_device_provider.h" |
| 19 #include "device/vr/vr_export.h" | 20 #include "device/vr/vr_export.h" |
| 20 #include "device/vr/vr_service.mojom.h" | 21 #include "device/vr/vr_service.mojom.h" |
| 22 #include "device/vr/vr_service_impl.h" |
| 21 #include "mojo/public/cpp/bindings/binding_set.h" | 23 #include "mojo/public/cpp/bindings/binding_set.h" |
| 22 | 24 |
| 23 namespace device { | 25 namespace device { |
| 24 | 26 |
| 25 class VRDeviceManager : public VRService { | 27 class VRDeviceManager : public VRClientDispatcher { |
| 26 public: | 28 public: |
| 27 DEVICE_VR_EXPORT ~VRDeviceManager() override; | 29 DEVICE_VR_EXPORT virtual ~VRDeviceManager(); |
| 28 | |
| 29 DEVICE_VR_EXPORT static void BindRequest( | |
| 30 mojo::InterfaceRequest<VRService> request); | |
| 31 | 30 |
| 32 // Returns the VRDeviceManager singleton. | 31 // Returns the VRDeviceManager singleton. |
| 33 static VRDeviceManager* GetInstance(); | 32 static VRDeviceManager* GetInstance(); |
| 34 | 33 |
| 34 // Add's a listener for device manager events. VRDeviceManager does not own |
| 35 // this object. |
| 36 void AddService(VRServiceImpl* service); |
| 37 void RemoveService(VRServiceImpl* service); |
| 38 |
| 35 DEVICE_VR_EXPORT mojo::Array<VRDisplayPtr> GetVRDevices(); | 39 DEVICE_VR_EXPORT mojo::Array<VRDisplayPtr> GetVRDevices(); |
| 36 DEVICE_VR_EXPORT VRDevice* GetDevice(unsigned int index); | 40 DEVICE_VR_EXPORT VRDevice* GetDevice(unsigned int index); |
| 37 | 41 |
| 42 void OnDeviceChanged(VRDisplayPtr device) override; |
| 43 |
| 38 private: | 44 private: |
| 39 friend class VRDeviceManagerTest; | 45 friend class VRDeviceManagerTest; |
| 40 | 46 |
| 41 VRDeviceManager(); | 47 VRDeviceManager(); |
| 42 // Constructor for testing. | 48 // Constructor for testing. |
| 43 DEVICE_VR_EXPORT explicit VRDeviceManager( | 49 DEVICE_VR_EXPORT explicit VRDeviceManager( |
| 44 std::unique_ptr<VRDeviceProvider> provider); | 50 std::unique_ptr<VRDeviceProvider> provider); |
| 45 | 51 |
| 46 static void SetInstance(VRDeviceManager* service); | 52 static void SetInstance(VRDeviceManager* service); |
| 47 static bool HasInstance(); | 53 static bool HasInstance(); |
| 48 | 54 |
| 49 void InitializeProviders(); | 55 void InitializeProviders(); |
| 50 void RegisterProvider(std::unique_ptr<VRDeviceProvider> provider); | 56 void RegisterProvider(std::unique_ptr<VRDeviceProvider> provider); |
| 51 | 57 |
| 52 // mojom::VRService implementation | |
| 53 void GetDisplays(const GetDisplaysCallback& callback) override; | |
| 54 void GetPose(uint32_t index, const GetPoseCallback& callback) override; | |
| 55 void ResetPose(uint32_t index) override; | |
| 56 | |
| 57 // Mojo connection error handler. | |
| 58 void OnConnectionError(); | |
| 59 | |
| 60 using ProviderList = std::vector<linked_ptr<VRDeviceProvider>>; | 58 using ProviderList = std::vector<linked_ptr<VRDeviceProvider>>; |
| 61 ProviderList providers_; | 59 ProviderList providers_; |
| 62 | 60 |
| 63 // Devices are owned by their providers. | 61 // Devices are owned by their providers. |
| 64 using DeviceMap = std::map<unsigned int, VRDevice*>; | 62 using DeviceMap = std::map<unsigned int, VRDevice*>; |
| 65 DeviceMap devices_; | 63 DeviceMap devices_; |
| 66 | 64 |
| 67 bool vr_initialized_; | 65 bool vr_initialized_; |
| 68 | 66 |
| 69 mojo::BindingSet<VRService> bindings_; | 67 using ServiceList = std::vector<VRServiceImpl*>; |
| 68 ServiceList services_; |
| 70 | 69 |
| 71 // For testing. If true will not delete self when consumer count reaches 0. | 70 // For testing. If true will not delete self when consumer count reaches 0. |
| 72 bool keep_alive_; | 71 bool keep_alive_; |
| 73 | 72 |
| 74 base::ThreadChecker thread_checker_; | 73 base::ThreadChecker thread_checker_; |
| 75 | 74 |
| 76 DISALLOW_COPY_AND_ASSIGN(VRDeviceManager); | 75 DISALLOW_COPY_AND_ASSIGN(VRDeviceManager); |
| 77 }; | 76 }; |
| 78 | 77 |
| 79 } // namespace content | 78 } // namespace content |
| 80 | 79 |
| 81 #endif // CONTENT_BROWSER_VR_VR_DEVICE_MANAGER_H | 80 #endif // CONTENT_BROWSER_VR_VR_DEVICE_MANAGER_H |
| OLD | NEW |