Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(442)

Side by Side Diff: device/vr/vr_device_manager.cc

Issue 2510993002: Notify VRDeviceProviders when there are pages listening for vrdisplayactivate (Closed)
Patch Set: Rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/vr/vr_device_manager.h ('k') | device/vr/vr_device_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 13
14 #if defined(OS_ANDROID) 14 #if defined(OS_ANDROID)
15 #include "device/vr/android/gvr/gvr_device_provider.h" 15 #include "device/vr/android/gvr/gvr_device_provider.h"
16 #endif 16 #endif
17 17
18 namespace device { 18 namespace device {
19 19
20 namespace { 20 namespace {
21 VRDeviceManager* g_vr_device_manager = nullptr; 21 VRDeviceManager* g_vr_device_manager = nullptr;
22 } 22 }
23 23
24 VRDeviceManager::VRDeviceManager() 24 VRDeviceManager::VRDeviceManager()
25 : vr_initialized_(false), 25 : vr_initialized_(false),
26 keep_alive_(false), 26 keep_alive_(false),
27 has_scheduled_poll_(false) { 27 has_scheduled_poll_(false),
28 has_activate_listeners_(false) {
28 // Register VRDeviceProviders for the current platform 29 // Register VRDeviceProviders for the current platform
29 #if defined(OS_ANDROID) 30 #if defined(OS_ANDROID)
30 RegisterProvider(base::MakeUnique<GvrDeviceProvider>()); 31 RegisterProvider(base::MakeUnique<GvrDeviceProvider>());
31 #endif 32 #endif
32 } 33 }
33 34
34 VRDeviceManager::VRDeviceManager(std::unique_ptr<VRDeviceProvider> provider) 35 VRDeviceManager::VRDeviceManager(std::unique_ptr<VRDeviceProvider> provider)
35 : vr_initialized_(false), keep_alive_(true), has_scheduled_poll_(false) { 36 : vr_initialized_(false), keep_alive_(true), has_scheduled_poll_(false) {
36 thread_checker_.DetachFromThread(); 37 thread_checker_.DetachFromThread();
37 RegisterProvider(std::move(provider)); 38 RegisterProvider(std::move(provider));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 74 }
74 75
75 void VRDeviceManager::RemoveService(VRServiceImpl* service) { 76 void VRDeviceManager::RemoveService(VRServiceImpl* service) {
76 services_.erase(std::remove(services_.begin(), services_.end(), service), 77 services_.erase(std::remove(services_.begin(), services_.end(), service),
77 services_.end()); 78 services_.end());
78 79
79 for (auto device : devices_) { 80 for (auto device : devices_) {
80 device.second->RemoveService(service); 81 device.second->RemoveService(service);
81 } 82 }
82 83
84 if (service->listening_for_activate()) {
85 ListeningForActivateChanged(false);
86 }
87
83 if (services_.empty() && !keep_alive_) { 88 if (services_.empty() && !keep_alive_) {
84 // Delete the device manager when it has no active connections. 89 // Delete the device manager when it has no active connections.
85 delete g_vr_device_manager; 90 delete g_vr_device_manager;
86 } 91 }
87 } 92 }
88 93
89 bool VRDeviceManager::GetVRDevices(VRServiceImpl* service) { 94 bool VRDeviceManager::GetVRDevices(VRServiceImpl* service) {
90 DCHECK(thread_checker_.CalledOnValidThread()); 95 DCHECK(thread_checker_.CalledOnValidThread());
91 96
92 InitializeProviders(); 97 InitializeProviders();
(...skipping 17 matching lines...) Expand all
110 115
111 return true; 116 return true;
112 } 117 }
113 118
114 unsigned int VRDeviceManager::GetNumberOfConnectedDevices() { 119 unsigned int VRDeviceManager::GetNumberOfConnectedDevices() {
115 DCHECK(thread_checker_.CalledOnValidThread()); 120 DCHECK(thread_checker_.CalledOnValidThread());
116 121
117 return static_cast<unsigned int>(devices_.size()); 122 return static_cast<unsigned int>(devices_.size());
118 } 123 }
119 124
125 void VRDeviceManager::ListeningForActivateChanged(bool listening) {
126 DCHECK(thread_checker_.CalledOnValidThread());
127
128 bool activate_listeners = listening;
129 if (!activate_listeners) {
130 for (const auto& service : services_) {
131 if (service->listening_for_activate()) {
132 activate_listeners = true;
133 break;
134 }
135 }
136 }
137
138 // Notify all the providers if this changes
139 if (has_activate_listeners_ != activate_listeners) {
140 has_activate_listeners_ = activate_listeners;
141 for (const auto& provider : providers_)
142 provider->SetListeningForActivate(has_activate_listeners_);
143 }
144 }
145
120 VRDevice* VRDeviceManager::GetDevice(unsigned int index) { 146 VRDevice* VRDeviceManager::GetDevice(unsigned int index) {
121 DCHECK(thread_checker_.CalledOnValidThread()); 147 DCHECK(thread_checker_.CalledOnValidThread());
122 148
123 if (index == 0) { 149 if (index == 0) {
124 return NULL; 150 return NULL;
125 } 151 }
126 152
127 DeviceMap::iterator iter = devices_.find(index); 153 DeviceMap::iterator iter = devices_.find(index);
128 if (iter == devices_.end()) { 154 if (iter == devices_.end()) {
129 return nullptr; 155 return nullptr;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 for (const auto& provider : providers_) 188 for (const auto& provider : providers_)
163 provider->PollEvents(); 189 provider->PollEvents();
164 } 190 }
165 191
166 void VRDeviceManager::StopSchedulingPollEvents() { 192 void VRDeviceManager::StopSchedulingPollEvents() {
167 if (has_scheduled_poll_) 193 if (has_scheduled_poll_)
168 timer_.Stop(); 194 timer_.Stop();
169 } 195 }
170 196
171 } // namespace device 197 } // namespace device
OLDNEW
« no previous file with comments | « device/vr/vr_device_manager.h ('k') | device/vr/vr_device_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698