Process Alt-Svc headers.
[chromium-blink-merge.git] / content / browser / vr / vr_device_manager.h
blob6c8dc9646a8d882c1b656ef1aa2b8d94aaa2005a
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.
5 #ifndef CONTENT_BROWSER_VR_VR_DEVICE_MANAGER_H
6 #define CONTENT_BROWSER_VR_VR_DEVICE_MANAGER_H
8 #include <map>
9 #include <vector>
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"
21 namespace content {
23 class VRDeviceManager : public VRService, public mojo::ErrorHandler {
24 public:
25 ~VRDeviceManager() override;
27 static void BindRequest(mojo::InterfaceRequest<VRService> request);
29 // Returns the VRDeviceManager singleton.
30 static VRDeviceManager* GetInstance();
32 mojo::Array<VRDeviceInfoPtr> GetVRDevices();
33 VRDevice* GetDevice(unsigned int index);
35 private:
36 friend class VRDeviceManagerTest;
38 VRDeviceManager();
39 // Constructor for testing.
40 explicit VRDeviceManager(scoped_ptr<VRDeviceProvider> provider);
42 static void SetInstance(VRDeviceManager* service);
43 static bool HasInstance();
45 void InitializeProviders();
46 void RegisterProvider(scoped_ptr<VRDeviceProvider> provider);
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;
54 // mojo::ErrorHandler implementation
55 void OnConnectionError() override;
57 using ProviderList = std::vector<linked_ptr<VRDeviceProvider>>;
58 ProviderList providers_;
60 // Devices are owned by their providers.
61 using DeviceMap = std::map<unsigned int, VRDevice*>;
62 DeviceMap devices_;
64 bool vr_initialized_;
66 mojo::WeakBindingSet<VRService> bindings_;
68 // For testing. If true will not delete self when consumer count reaches 0.
69 bool keep_alive_;
71 base::ThreadChecker thread_checker_;
73 DISALLOW_COPY_AND_ASSIGN(VRDeviceManager);
76 } // namespace content
78 #endif // CONTENT_BROWSER_VR_VR_DEVICE_MANAGER_H