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 #include "content/browser/vr/vr_device_manager.h" | 5 #include "content/browser/vr/vr_device_manager.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
8 #include "third_party/WebKit/public/platform/modules/vr/WebVR.h" | 9 #include "third_party/WebKit/public/platform/modules/vr/WebVR.h" |
9 | 10 |
| 11 #if defined(OS_ANDROID) |
| 12 #include "content/browser/vr/android/cardboard/cardboard_vr_device_provider.h" |
| 13 #endif |
| 14 |
10 namespace content { | 15 namespace content { |
11 | 16 |
12 namespace { | 17 namespace { |
13 VRDeviceManager* g_vr_device_manager = nullptr; | 18 VRDeviceManager* g_vr_device_manager = nullptr; |
14 } | 19 } |
15 | 20 |
16 VRDeviceManager::VRDeviceManager() | 21 VRDeviceManager::VRDeviceManager() |
17 : vr_initialized_(false), keep_alive_(false) { | 22 : vr_initialized_(false), keep_alive_(false) { |
18 bindings_.set_error_handler(this); | 23 bindings_.set_connection_error_handler( |
| 24 base::Bind(&VRDeviceManager::OnConnectionError, base::Unretained(this))); |
19 // Register VRDeviceProviders for the current platform | 25 // Register VRDeviceProviders for the current platform |
| 26 #if defined(OS_ANDROID) |
| 27 scoped_ptr<VRDeviceProvider> cardboard_provider( |
| 28 new CardboardVRDeviceProvider()); |
| 29 RegisterProvider(cardboard_provider.Pass()); |
| 30 #endif |
20 } | 31 } |
21 | 32 |
22 VRDeviceManager::VRDeviceManager(scoped_ptr<VRDeviceProvider> provider) | 33 VRDeviceManager::VRDeviceManager(scoped_ptr<VRDeviceProvider> provider) |
23 : vr_initialized_(false), keep_alive_(true) { | 34 : vr_initialized_(false), keep_alive_(true) { |
24 thread_checker_.DetachFromThread(); | 35 thread_checker_.DetachFromThread(); |
25 RegisterProvider(provider.Pass()); | 36 RegisterProvider(provider.Pass()); |
26 SetInstance(this); | 37 SetInstance(this); |
27 } | 38 } |
28 | 39 |
29 VRDeviceManager::~VRDeviceManager() { | 40 VRDeviceManager::~VRDeviceManager() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 return !!g_vr_device_manager; | 74 return !!g_vr_device_manager; |
64 } | 75 } |
65 | 76 |
66 mojo::Array<VRDeviceInfoPtr> VRDeviceManager::GetVRDevices() { | 77 mojo::Array<VRDeviceInfoPtr> VRDeviceManager::GetVRDevices() { |
67 DCHECK(thread_checker_.CalledOnValidThread()); | 78 DCHECK(thread_checker_.CalledOnValidThread()); |
68 | 79 |
69 InitializeProviders(); | 80 InitializeProviders(); |
70 | 81 |
71 std::vector<VRDevice*> devices; | 82 std::vector<VRDevice*> devices; |
72 for (const auto& provider : providers_) | 83 for (const auto& provider : providers_) |
73 provider->GetDevices(devices); | 84 provider->GetDevices(&devices); |
74 | 85 |
75 mojo::Array<VRDeviceInfoPtr> out_devices(0); | 86 mojo::Array<VRDeviceInfoPtr> out_devices(0); |
76 for (const auto& device : devices) { | 87 for (const auto& device : devices) { |
77 if (device->id() == VR_DEVICE_LAST_ID) | 88 if (device->id() == VR_DEVICE_LAST_ID) |
78 continue; | 89 continue; |
79 | 90 |
80 if (devices_.find(device->id()) == devices_.end()) | 91 if (devices_.find(device->id()) == devices_.end()) |
81 devices_[device->id()] = device; | 92 devices_[device->id()] = device; |
82 | 93 |
83 VRDeviceInfoPtr vr_device_info = device->GetVRDevice(); | 94 VRDeviceInfoPtr vr_device_info = device->GetVRDevice(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 141 } |
131 } | 142 } |
132 | 143 |
133 void VRDeviceManager::ResetSensor(uint32_t index) { | 144 void VRDeviceManager::ResetSensor(uint32_t index) { |
134 VRDevice* device = GetDevice(index); | 145 VRDevice* device = GetDevice(index); |
135 if (device) | 146 if (device) |
136 device->ResetSensor(); | 147 device->ResetSensor(); |
137 } | 148 } |
138 | 149 |
139 } // namespace content | 150 } // namespace content |
OLD | NEW |