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 #ifndef CONTENT_BROWSER_VR_VR_DEVICE_MANAGER_H | |
6 #define CONTENT_BROWSER_VR_VR_DEVICE_MANAGER_H | |
7 | |
8 #include <map> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/memory/linked_ptr.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/threading/thread_checker.h" | |
15 #include "content/browser/vr/vr_device.h" | |
16 #include "content/browser/vr/vr_device_provider.h" | |
17 #include "content/common/content_export.h" | |
18 #include "content/common/vr_service.mojom.h" | |
19 #include "mojo/common/weak_binding_set.h" | |
20 | |
21 namespace content { | |
22 | |
23 class VRDeviceManager : public VRService, public mojo::ErrorHandler { | |
24 public: | |
25 ~VRDeviceManager() override; | |
26 | |
27 static void BindRequest(mojo::InterfaceRequest<VRService> request); | |
28 | |
29 // Returns the VRDeviceManager singleton. | |
30 static VRDeviceManager* GetInstance(); | |
31 | |
32 mojo::Array<VRDeviceInfoPtr> GetVRDevices(); | |
33 VRDevice* GetDevice(unsigned int index); | |
34 | |
35 private: | |
36 friend class VRDeviceManagerTest; | |
37 | |
38 VRDeviceManager(); | |
39 // Constructor for testing. | |
40 explicit VRDeviceManager(scoped_ptr<VRDeviceProvider> provider); | |
41 | |
42 static void SetInstance(VRDeviceManager* service); | |
43 static bool HasInstance(); | |
44 | |
45 void InitializeProviders(); | |
46 void RegisterProvider(scoped_ptr<VRDeviceProvider> provider); | |
47 | |
48 // VRService implementation | |
49 void GetDevices(const GetDevicesCallback& callback) override; | |
50 void GetSensorState(uint32_t index, | |
51 const GetSensorStateCallback& callback) override; | |
52 void ResetSensor(uint32_t index) override; | |
53 | |
54 // mojo::ErrorHandler implementation | |
55 void OnConnectionError() override; | |
56 | |
57 using ProviderList = std::vector<linked_ptr<VRDeviceProvider>>; | |
58 ProviderList providers_; | |
59 | |
60 using DeviceMap = std::map<unsigned int, VRDevice*>; | |
61 DeviceMap devices_; | |
Ken Rockot(use gerrit already)
2015/06/15 18:22:55
May be worth noting that the VRDevice objects here
| |
62 | |
63 bool vr_initialized_; | |
64 | |
65 mojo::WeakBindingSet<VRService> bindings_; | |
66 | |
67 // For testing. If true will not delete self when consumer count reaches 0. | |
68 bool keep_alive_; | |
69 | |
70 base::ThreadChecker thread_checker_; | |
71 | |
72 DISALLOW_COPY_AND_ASSIGN(VRDeviceManager); | |
73 }; | |
74 | |
75 } // namespace content | |
76 | |
77 #endif // CONTENT_BROWSER_VR_VR_DEVICE_MANAGER_H | |
OLD | NEW |