| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 service->ConnectDevice(device); | 89 service->ConnectDevice(device); |
| 90 } | 90 } |
| 91 | 91 |
| 92 services_.insert(service); | 92 services_.insert(service); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void VRDeviceManager::RemoveService(VRServiceImpl* service) { | 95 void VRDeviceManager::RemoveService(VRServiceImpl* service) { |
| 96 | 96 |
| 97 if (service->listening_for_activate()) { | 97 if (service->listening_for_activate()) { |
| 98 ListeningForActivateChanged(false); | 98 ListeningForActivateChanged(false, service); |
| 99 } | 99 } |
| 100 | 100 |
| 101 services_.erase(service); | 101 services_.erase(service); |
| 102 | 102 |
| 103 if (services_.empty() && !keep_alive_) { | 103 if (services_.empty() && !keep_alive_) { |
| 104 // Delete the device manager when it has no active connections. | 104 // Delete the device manager when it has no active connections. |
| 105 delete g_vr_device_manager; | 105 delete g_vr_device_manager; |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 unsigned int VRDeviceManager::GetNumberOfConnectedDevices() { | 109 unsigned int VRDeviceManager::GetNumberOfConnectedDevices() { |
| 110 DCHECK(thread_checker_.CalledOnValidThread()); | 110 DCHECK(thread_checker_.CalledOnValidThread()); |
| 111 | 111 |
| 112 return static_cast<unsigned int>(devices_.size()); | 112 return static_cast<unsigned int>(devices_.size()); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void VRDeviceManager::ListeningForActivateChanged(bool listening) { | 115 void VRDeviceManager::ListeningForActivateChanged(bool listening, |
| 116 VRServiceImpl* service) { |
| 116 DCHECK(thread_checker_.CalledOnValidThread()); | 117 DCHECK(thread_checker_.CalledOnValidThread()); |
| 117 | 118 |
| 119 if (listening) { |
| 120 most_recently_listening_for_activate_ = service; |
| 121 } |
| 122 |
| 118 bool activate_listeners = listening; | 123 bool activate_listeners = listening; |
| 119 if (!activate_listeners) { | 124 if (!activate_listeners) { |
| 120 for (auto* service : services_) { | 125 for (auto* service : services_) { |
| 121 if (service->listening_for_activate()) { | 126 if (service->listening_for_activate()) { |
| 122 activate_listeners = true; | 127 activate_listeners = true; |
| 123 break; | 128 break; |
| 124 } | 129 } |
| 125 } | 130 } |
| 126 } | 131 } |
| 127 | 132 |
| 128 // Notify all the providers if this changes | 133 // Notify all the providers if this changes |
| 129 if (has_activate_listeners_ != activate_listeners) { | 134 if (has_activate_listeners_ != activate_listeners) { |
| 130 has_activate_listeners_ = activate_listeners; | 135 has_activate_listeners_ = activate_listeners; |
| 131 for (const auto& provider : providers_) | 136 for (const auto& provider : providers_) |
| 132 provider->SetListeningForActivate(has_activate_listeners_); | 137 provider->SetListeningForActivate(has_activate_listeners_); |
| 133 } | 138 } |
| 134 } | 139 } |
| 135 | 140 |
| 141 bool VRDeviceManager::IsMostRecentlyListeningForActivate( |
| 142 VRServiceImpl* service) { |
| 143 if (!service) |
| 144 return false; |
| 145 return service == most_recently_listening_for_activate_; |
| 146 } |
| 147 |
| 136 VRDevice* VRDeviceManager::GetDevice(unsigned int index) { | 148 VRDevice* VRDeviceManager::GetDevice(unsigned int index) { |
| 137 DCHECK(thread_checker_.CalledOnValidThread()); | 149 DCHECK(thread_checker_.CalledOnValidThread()); |
| 138 | 150 |
| 139 if (index == 0) { | 151 if (index == 0) { |
| 140 return NULL; | 152 return NULL; |
| 141 } | 153 } |
| 142 | 154 |
| 143 DeviceMap::iterator iter = devices_.find(index); | 155 DeviceMap::iterator iter = devices_.find(index); |
| 144 if (iter == devices_.end()) { | 156 if (iter == devices_.end()) { |
| 145 return nullptr; | 157 return nullptr; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 for (const auto& provider : providers_) | 190 for (const auto& provider : providers_) |
| 179 provider->PollEvents(); | 191 provider->PollEvents(); |
| 180 } | 192 } |
| 181 | 193 |
| 182 void VRDeviceManager::StopSchedulingPollEvents() { | 194 void VRDeviceManager::StopSchedulingPollEvents() { |
| 183 if (has_scheduled_poll_) | 195 if (has_scheduled_poll_) |
| 184 timer_.Stop(); | 196 timer_.Stop(); |
| 185 } | 197 } |
| 186 | 198 |
| 187 } // namespace device | 199 } // namespace device |
| OLD | NEW |