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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 GetVRDevices(service); |
72 | 72 |
73 services_.push_back(service); | 73 services_.insert(service); |
74 } | 74 } |
75 | 75 |
76 void VRDeviceManager::RemoveService(VRServiceImpl* service) { | 76 void VRDeviceManager::RemoveService(VRServiceImpl* service) { |
77 services_.erase(std::remove(services_.begin(), services_.end(), service), | |
78 services_.end()); | |
79 | |
80 for (auto device : devices_) { | |
81 device.second->RemoveService(service); | |
82 } | |
83 | 77 |
84 if (service->listening_for_activate()) { | 78 if (service->listening_for_activate()) { |
85 ListeningForActivateChanged(false); | 79 ListeningForActivateChanged(false); |
86 } | 80 } |
87 | 81 |
| 82 services_.erase(service); |
| 83 |
88 if (services_.empty() && !keep_alive_) { | 84 if (services_.empty() && !keep_alive_) { |
89 // Delete the device manager when it has no active connections. | 85 // Delete the device manager when it has no active connections. |
90 delete g_vr_device_manager; | 86 delete g_vr_device_manager; |
91 } | 87 } |
92 } | 88 } |
93 | 89 |
94 bool VRDeviceManager::GetVRDevices(VRServiceImpl* service) { | 90 bool VRDeviceManager::GetVRDevices(VRServiceImpl* service) { |
95 DCHECK(thread_checker_.CalledOnValidThread()); | 91 DCHECK(thread_checker_.CalledOnValidThread()); |
96 | 92 |
97 InitializeProviders(); | 93 InitializeProviders(); |
98 | 94 |
99 std::vector<VRDevice*> devices; | 95 std::vector<VRDevice*> devices; |
100 for (const auto& provider : providers_) | 96 for (const auto& provider : providers_) |
101 provider->GetDevices(&devices); | 97 provider->GetDevices(&devices); |
102 | 98 |
103 if (devices.empty()) | 99 if (devices.empty()) |
104 return false; | 100 return false; |
105 | 101 |
106 for (auto* device : devices) { | 102 for (auto* device : devices) { |
107 if (device->id() == VR_DEVICE_LAST_ID) | 103 if (device->id() == VR_DEVICE_LAST_ID) |
108 continue; | 104 continue; |
109 | 105 |
110 if (devices_.find(device->id()) == devices_.end()) | 106 if (devices_.find(device->id()) == devices_.end()) |
111 devices_[device->id()] = device; | 107 devices_[device->id()] = device; |
112 | 108 |
113 device->AddService(service); | 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); |
114 } | 113 } |
115 | 114 |
116 return true; | 115 return true; |
117 } | 116 } |
118 | 117 |
119 unsigned int VRDeviceManager::GetNumberOfConnectedDevices() { | 118 unsigned int VRDeviceManager::GetNumberOfConnectedDevices() { |
120 DCHECK(thread_checker_.CalledOnValidThread()); | 119 DCHECK(thread_checker_.CalledOnValidThread()); |
121 | 120 |
122 return static_cast<unsigned int>(devices_.size()); | 121 return static_cast<unsigned int>(devices_.size()); |
123 } | 122 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 for (const auto& provider : providers_) | 187 for (const auto& provider : providers_) |
189 provider->PollEvents(); | 188 provider->PollEvents(); |
190 } | 189 } |
191 | 190 |
192 void VRDeviceManager::StopSchedulingPollEvents() { | 191 void VRDeviceManager::StopSchedulingPollEvents() { |
193 if (has_scheduled_poll_) | 192 if (has_scheduled_poll_) |
194 timer_.Stop(); | 193 timer_.Stop(); |
195 } | 194 } |
196 | 195 |
197 } // namespace device | 196 } // namespace device |
OLD | NEW |