Chromium Code Reviews| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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_.push_back(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(std::remove(services_.begin(), services_.end(), service), | |
|
mthiesse
2016/11/29 16:35:13
Perhaps services_ should be a set too? We don't ex
shaobo.yan
2016/11/30 00:32:54
Yes, I think set could be a better solution.
shaobo.yan
2016/11/30 02:54:43
Done.
| |
| 83 services_.end()); | |
| 84 | |
| 88 if (services_.empty() && !keep_alive_) { | 85 if (services_.empty() && !keep_alive_) { |
| 89 // Delete the device manager when it has no active connections. | 86 // Delete the device manager when it has no active connections. |
| 90 delete g_vr_device_manager; | 87 delete g_vr_device_manager; |
| 91 } | 88 } |
| 92 } | 89 } |
| 93 | 90 |
| 94 bool VRDeviceManager::GetVRDevices(VRServiceImpl* service) { | 91 bool VRDeviceManager::GetVRDevices(VRServiceImpl* service) { |
| 95 DCHECK(thread_checker_.CalledOnValidThread()); | 92 DCHECK(thread_checker_.CalledOnValidThread()); |
| 96 | 93 |
| 97 InitializeProviders(); | 94 InitializeProviders(); |
| 98 | 95 |
| 99 std::vector<VRDevice*> devices; | 96 std::vector<VRDevice*> devices; |
| 100 for (const auto& provider : providers_) | 97 for (const auto& provider : providers_) |
| 101 provider->GetDevices(&devices); | 98 provider->GetDevices(&devices); |
| 102 | 99 |
| 103 if (devices.empty()) | 100 if (devices.empty()) |
| 104 return false; | 101 return false; |
| 105 | 102 |
| 106 for (auto* device : devices) { | 103 for (auto* device : devices) { |
| 107 if (device->id() == VR_DEVICE_LAST_ID) | 104 if (device->id() == VR_DEVICE_LAST_ID) |
| 108 continue; | 105 continue; |
| 109 | 106 |
| 110 if (devices_.find(device->id()) == devices_.end()) | 107 if (devices_.find(device->id()) == devices_.end()) |
| 111 devices_[device->id()] = device; | 108 devices_[device->id()] = device; |
| 112 | 109 |
| 113 device->AddService(service); | 110 // Create a VRDisplayImpl for this service/device pair and attach |
| 111 // the VRDisplayImpl to the device. | |
| 112 VRDisplayImpl* display_impl = service->GetVRDisplayImpl(device); | |
| 113 device->AddDisplay(display_impl); | |
| 114 } | 114 } |
| 115 | 115 |
| 116 return true; | 116 return true; |
| 117 } | 117 } |
| 118 | 118 |
| 119 unsigned int VRDeviceManager::GetNumberOfConnectedDevices() { | 119 unsigned int VRDeviceManager::GetNumberOfConnectedDevices() { |
| 120 DCHECK(thread_checker_.CalledOnValidThread()); | 120 DCHECK(thread_checker_.CalledOnValidThread()); |
| 121 | 121 |
| 122 return static_cast<unsigned int>(devices_.size()); | 122 return static_cast<unsigned int>(devices_.size()); |
| 123 } | 123 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 for (const auto& provider : providers_) | 188 for (const auto& provider : providers_) |
| 189 provider->PollEvents(); | 189 provider->PollEvents(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void VRDeviceManager::StopSchedulingPollEvents() { | 192 void VRDeviceManager::StopSchedulingPollEvents() { |
| 193 if (has_scheduled_poll_) | 193 if (has_scheduled_poll_) |
| 194 timer_.Stop(); | 194 timer_.Stop(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 } // namespace device | 197 } // namespace device |
| OLD | NEW |