| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 bool VRDeviceManager::HasInstance() { | 62 bool VRDeviceManager::HasInstance() { |
| 63 // For testing. Checks to see if a VRDeviceManager instance is active. | 63 // For testing. Checks to see if a VRDeviceManager instance is active. |
| 64 return !!g_vr_device_manager; | 64 return !!g_vr_device_manager; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void VRDeviceManager::AddService(VRServiceImpl* service) { | 67 void VRDeviceManager::AddService(VRServiceImpl* service) { |
| 68 // Loop through any currently active devices and send Connected messages to | 68 // Loop through any currently active devices and send Connected messages to |
| 69 // the service. Future devices that come online will send a Connected message | 69 // the service. Future devices that come online will send a Connected message |
| 70 // when they are created. | 70 // when they are created. |
| 71 GetVRDevices(service); | 71 DCHECK(thread_checker_.CalledOnValidThread()); |
| 72 |
| 73 InitializeProviders(); |
| 74 |
| 75 std::vector<VRDevice*> devices; |
| 76 for (const auto& provider : providers_) { |
| 77 provider->GetDevices(&devices); |
| 78 } |
| 79 |
| 80 for (auto* device : devices) { |
| 81 if (device->id() == VR_DEVICE_LAST_ID) { |
| 82 continue; |
| 83 } |
| 84 |
| 85 if (devices_.find(device->id()) == devices_.end()) { |
| 86 devices_[device->id()] = device; |
| 87 } |
| 88 |
| 89 service->ConnectDevice(device); |
| 90 } |
| 72 | 91 |
| 73 services_.insert(service); | 92 services_.insert(service); |
| 74 } | 93 } |
| 75 | 94 |
| 76 void VRDeviceManager::RemoveService(VRServiceImpl* service) { | 95 void VRDeviceManager::RemoveService(VRServiceImpl* service) { |
| 77 | 96 |
| 78 if (service->listening_for_activate()) { | 97 if (service->listening_for_activate()) { |
| 79 ListeningForActivateChanged(false); | 98 ListeningForActivateChanged(false); |
| 80 } | 99 } |
| 81 | 100 |
| 82 services_.erase(service); | 101 services_.erase(service); |
| 83 | 102 |
| 84 if (services_.empty() && !keep_alive_) { | 103 if (services_.empty() && !keep_alive_) { |
| 85 // Delete the device manager when it has no active connections. | 104 // Delete the device manager when it has no active connections. |
| 86 delete g_vr_device_manager; | 105 delete g_vr_device_manager; |
| 87 } | 106 } |
| 88 } | 107 } |
| 89 | 108 |
| 90 bool VRDeviceManager::GetVRDevices(VRServiceImpl* service) { | |
| 91 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 92 | |
| 93 InitializeProviders(); | |
| 94 | |
| 95 std::vector<VRDevice*> devices; | |
| 96 for (const auto& provider : providers_) | |
| 97 provider->GetDevices(&devices); | |
| 98 | |
| 99 if (devices.empty()) | |
| 100 return false; | |
| 101 | |
| 102 for (auto* device : devices) { | |
| 103 if (device->id() == VR_DEVICE_LAST_ID) | |
| 104 continue; | |
| 105 | |
| 106 if (devices_.find(device->id()) == devices_.end()) | |
| 107 devices_[device->id()] = device; | |
| 108 | |
| 109 // Create a VRDisplayImpl for this service/device pair and attach | |
| 110 // the VRDisplayImpl to the device. | |
| 111 VRDisplayImpl* display_impl = service->GetVRDisplayImpl(device); | |
| 112 device->AddDisplay(display_impl); | |
| 113 } | |
| 114 | |
| 115 return true; | |
| 116 } | |
| 117 | |
| 118 unsigned int VRDeviceManager::GetNumberOfConnectedDevices() { | 109 unsigned int VRDeviceManager::GetNumberOfConnectedDevices() { |
| 119 DCHECK(thread_checker_.CalledOnValidThread()); | 110 DCHECK(thread_checker_.CalledOnValidThread()); |
| 120 | 111 |
| 121 return static_cast<unsigned int>(devices_.size()); | 112 return static_cast<unsigned int>(devices_.size()); |
| 122 } | 113 } |
| 123 | 114 |
| 124 void VRDeviceManager::ListeningForActivateChanged(bool listening) { | 115 void VRDeviceManager::ListeningForActivateChanged(bool listening) { |
| 125 DCHECK(thread_checker_.CalledOnValidThread()); | 116 DCHECK(thread_checker_.CalledOnValidThread()); |
| 126 | 117 |
| 127 bool activate_listeners = listening; | 118 bool activate_listeners = listening; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 for (const auto& provider : providers_) | 178 for (const auto& provider : providers_) |
| 188 provider->PollEvents(); | 179 provider->PollEvents(); |
| 189 } | 180 } |
| 190 | 181 |
| 191 void VRDeviceManager::StopSchedulingPollEvents() { | 182 void VRDeviceManager::StopSchedulingPollEvents() { |
| 192 if (has_scheduled_poll_) | 183 if (has_scheduled_poll_) |
| 193 timer_.Stop(); | 184 timer_.Stop(); |
| 194 } | 185 } |
| 195 | 186 |
| 196 } // namespace device | 187 } // namespace device |
| OLD | NEW |