| 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 "device/vr/vr_device_manager.h" | 5 #include "device/vr/vr_device_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 return iter->second; | 120 return iter->second; |
| 121 } | 121 } |
| 122 | 122 |
| 123 // These dispatchers must use Clone() instead of std::move to ensure that | 123 // These dispatchers must use Clone() instead of std::move to ensure that |
| 124 // if there are multiple registered services they all get a copy of the data. | 124 // if there are multiple registered services they all get a copy of the data. |
| 125 void VRDeviceManager::OnDeviceChanged(VRDisplayPtr device) { | 125 void VRDeviceManager::OnDeviceChanged(VRDisplayPtr device) { |
| 126 for (const auto& service : services_) | 126 for (const auto& service : services_) |
| 127 service->client()->OnDisplayChanged(device.Clone()); | 127 service->client()->OnDisplayChanged(device.Clone()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void VRDeviceManager::OnDeviceConnectionStatusChanged(VRDevice* device, |
| 131 bool isConnected) { |
| 132 if (isConnected) { |
| 133 VRDisplayPtr vr_device_info = device->GetVRDevice(); |
| 134 if (vr_device_info.is_null()) |
| 135 return; |
| 136 |
| 137 vr_device_info->index = device->id(); |
| 138 |
| 139 for (const auto& service : services_) |
| 140 service->client()->OnDisplayConnected(vr_device_info.Clone()); |
| 141 } else { |
| 142 for (const auto& service : services_) |
| 143 service->client()->OnDisplayDisconnected(device->id()); |
| 144 } |
| 145 } |
| 146 |
| 130 void VRDeviceManager::InitializeProviders() { | 147 void VRDeviceManager::InitializeProviders() { |
| 131 if (vr_initialized_) { | 148 if (vr_initialized_) { |
| 132 return; | 149 return; |
| 133 } | 150 } |
| 134 | 151 |
| 135 for (const auto& provider : providers_) | 152 for (const auto& provider : providers_) |
| 136 provider->Initialize(); | 153 provider->Initialize(); |
| 137 | 154 |
| 138 vr_initialized_ = true; | 155 vr_initialized_ = true; |
| 139 } | 156 } |
| 140 | 157 |
| 141 void VRDeviceManager::RegisterProvider( | 158 void VRDeviceManager::RegisterProvider( |
| 142 std::unique_ptr<VRDeviceProvider> provider) { | 159 std::unique_ptr<VRDeviceProvider> provider) { |
| 143 providers_.push_back(make_linked_ptr(provider.release())); | 160 providers_.push_back(make_linked_ptr(provider.release())); |
| 144 } | 161 } |
| 145 | 162 |
| 146 void VRDeviceManager::SchedulePollEvents() { | 163 void VRDeviceManager::SchedulePollEvents() { |
| 147 if (has_scheduled_poll_) | 164 if (has_scheduled_poll_) |
| 148 return; | 165 return; |
| 149 | 166 |
| 150 has_scheduled_poll_ = true; | 167 has_scheduled_poll_ = true; |
| 151 | 168 |
| 152 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(500), this, | 169 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(500), this, |
| 153 &VRDeviceManager::PollEvents); | 170 &VRDeviceManager::PollEvents); |
| 154 } | 171 } |
| 155 | 172 |
| 156 void VRDeviceManager::PollEvents() { | 173 void VRDeviceManager::PollEvents() { |
| 157 for (const auto& provider : providers_) | 174 for (const auto& provider : providers_) |
| 158 provider->PollEvents(); | 175 provider->PollEvents(this); |
| 159 } | 176 } |
| 160 | 177 |
| 161 void VRDeviceManager::StopSchedulingPollEvents() { | 178 void VRDeviceManager::StopSchedulingPollEvents() { |
| 162 if (has_scheduled_poll_) | 179 if (has_scheduled_poll_) |
| 163 timer_.Stop(); | 180 timer_.Stop(); |
| 164 } | 181 } |
| 165 | 182 |
| 166 } // namespace device | 183 } // namespace device |
| OLD | NEW |