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 11 matching lines...) Expand all Loading... | |
| 22 } | 22 } |
| 23 | 23 |
| 24 VRDeviceManager::VRDeviceManager() | 24 VRDeviceManager::VRDeviceManager() |
| 25 : vr_initialized_(false), | 25 : vr_initialized_(false), |
| 26 presenting_service_(nullptr), | 26 presenting_service_(nullptr), |
| 27 presenting_device_(nullptr), | 27 presenting_device_(nullptr), |
| 28 keep_alive_(false), | 28 keep_alive_(false), |
| 29 has_scheduled_poll_(false) { | 29 has_scheduled_poll_(false) { |
| 30 // Register VRDeviceProviders for the current platform | 30 // Register VRDeviceProviders for the current platform |
| 31 #if defined(OS_ANDROID) | 31 #if defined(OS_ANDROID) |
| 32 RegisterProvider(base::WrapUnique(new GvrDeviceProvider())); | 32 RegisterProvider(new GvrDeviceProvider()); |
| 33 #endif | 33 #endif |
| 34 } | 34 } |
| 35 | 35 |
| 36 VRDeviceManager::VRDeviceManager(std::unique_ptr<VRDeviceProvider> provider) | 36 VRDeviceManager::VRDeviceManager(VRDeviceProvider* provider) |
|
dcheng
2016/11/08 23:05:45
This should be a scoped_refptr<VRDeviceProvider>.
mthiesse
2016/11/10 22:14:10
Done.
| |
| 37 : vr_initialized_(false), | 37 : vr_initialized_(false), |
| 38 presenting_service_(nullptr), | 38 presenting_service_(nullptr), |
| 39 presenting_device_(nullptr), | 39 presenting_device_(nullptr), |
| 40 keep_alive_(true), | 40 keep_alive_(true), |
| 41 has_scheduled_poll_(false) { | 41 has_scheduled_poll_(false) { |
| 42 thread_checker_.DetachFromThread(); | 42 thread_checker_.DetachFromThread(); |
| 43 RegisterProvider(std::move(provider)); | 43 RegisterProvider(provider); |
| 44 SetInstance(this); | 44 SetInstance(this); |
| 45 } | 45 } |
| 46 | 46 |
| 47 VRDeviceManager::~VRDeviceManager() { | 47 VRDeviceManager::~VRDeviceManager() { |
| 48 DCHECK(thread_checker_.CalledOnValidThread()); | 48 DCHECK(thread_checker_.CalledOnValidThread()); |
| 49 StopSchedulingPollEvents(); | 49 StopSchedulingPollEvents(); |
| 50 g_vr_device_manager = nullptr; | 50 g_vr_device_manager = nullptr; |
| 51 } | 51 } |
| 52 | 52 |
| 53 VRDeviceManager* VRDeviceManager::GetInstance() { | 53 VRDeviceManager* VRDeviceManager::GetInstance() { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 72 device_manager->presenting_device_->id() == index) | 72 device_manager->presenting_device_->id() == index) |
| 73 return nullptr; | 73 return nullptr; |
| 74 } | 74 } |
| 75 | 75 |
| 76 return device_manager->GetDevice(index); | 76 return device_manager->GetDevice(index); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void VRDeviceManager::SetInstance(VRDeviceManager* instance) { | 79 void VRDeviceManager::SetInstance(VRDeviceManager* instance) { |
| 80 // Unit tests can create multiple instances but only one should exist at any | 80 // Unit tests can create multiple instances but only one should exist at any |
| 81 // given time so g_vr_device_manager should only go from nullptr to | 81 // given time so g_vr_device_manager should only go from nullptr to |
| 82 // non-nullptr and vica versa. | 82 // non-nullptr and vice versa. |
| 83 CHECK_NE(!!instance, !!g_vr_device_manager); | 83 CHECK_NE(!!instance, !!g_vr_device_manager); |
| 84 g_vr_device_manager = instance; | 84 g_vr_device_manager = instance; |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool VRDeviceManager::HasInstance() { | 87 bool VRDeviceManager::HasInstance() { |
| 88 // For testing. Checks to see if a VRDeviceManager instance is active. | 88 // For testing. Checks to see if a VRDeviceManager instance is active. |
| 89 return !!g_vr_device_manager; | 89 return !!g_vr_device_manager; |
| 90 } | 90 } |
| 91 | 91 |
| 92 void VRDeviceManager::AddService(VRServiceImpl* service) { | 92 void VRDeviceManager::AddService(VRServiceImpl* service) { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 DCHECK(presenting_service_); | 280 DCHECK(presenting_service_); |
| 281 | 281 |
| 282 // Notify the presenting service that it's been forced to end presentation. | 282 // Notify the presenting service that it's been forced to end presentation. |
| 283 presenting_service_->client()->OnExitPresent(device->id()); | 283 presenting_service_->client()->OnExitPresent(device->id()); |
| 284 | 284 |
| 285 // Clear the presenting service and device. | 285 // Clear the presenting service and device. |
| 286 presenting_service_ = nullptr; | 286 presenting_service_ = nullptr; |
| 287 presenting_device_ = nullptr; | 287 presenting_device_ = nullptr; |
| 288 } | 288 } |
| 289 | 289 |
| 290 void VRDeviceManager::OnDisplayBlur(VRDevice* device) { | |
| 291 // Ensure the presenting device is the one that we've been requested to blur. | |
| 292 if (!presenting_device_ || presenting_device_ != device) | |
| 293 return; | |
| 294 | |
| 295 // Should never have a presenting device without a presenting service. | |
| 296 DCHECK(presenting_service_); | |
| 297 | |
| 298 // Notify the presenting service that it should blur. | |
| 299 presenting_service_->client()->OnDisplayBlur(device->id()); | |
| 300 } | |
| 301 | |
| 302 void VRDeviceManager::OnDisplayFocus(VRDevice* device) { | |
| 303 // Ensure the presenting device is the one that we've been requested to focus. | |
| 304 if (!presenting_device_ || presenting_device_ != device) | |
| 305 return; | |
| 306 | |
| 307 // Should never have a presenting device without a presenting service. | |
| 308 DCHECK(presenting_service_); | |
| 309 | |
| 310 // Notify the presenting service that it should focus. | |
| 311 presenting_service_->client()->OnDisplayFocus(device->id()); | |
| 312 } | |
| 313 | |
| 290 void VRDeviceManager::InitializeProviders() { | 314 void VRDeviceManager::InitializeProviders() { |
| 291 if (vr_initialized_) { | 315 if (vr_initialized_) { |
| 292 return; | 316 return; |
| 293 } | 317 } |
| 294 | 318 |
| 295 for (const auto& provider : providers_) { | 319 for (const auto& provider : providers_) { |
| 296 provider->SetClient(this); | 320 provider->SetClient(this); |
| 297 provider->Initialize(); | 321 provider->Initialize(); |
| 298 } | 322 } |
| 299 | 323 |
| 300 vr_initialized_ = true; | 324 vr_initialized_ = true; |
| 301 } | 325 } |
| 302 | 326 |
| 303 void VRDeviceManager::RegisterProvider( | 327 void VRDeviceManager::RegisterProvider(VRDeviceProvider* provider) { |
|
dcheng
2016/11/08 23:05:45
Ditto: this should also be a scoped_refptr<VRDevic
mthiesse
2016/11/10 22:14:10
Done.
| |
| 304 std::unique_ptr<VRDeviceProvider> provider) { | 328 providers_.push_back(provider); |
| 305 providers_.push_back(make_linked_ptr(provider.release())); | |
| 306 } | 329 } |
| 307 | 330 |
| 308 void VRDeviceManager::SchedulePollEvents() { | 331 void VRDeviceManager::SchedulePollEvents() { |
| 309 if (has_scheduled_poll_) | 332 if (has_scheduled_poll_) |
| 310 return; | 333 return; |
| 311 | 334 |
| 312 has_scheduled_poll_ = true; | 335 has_scheduled_poll_ = true; |
| 313 | 336 |
| 314 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(500), this, | 337 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(500), this, |
| 315 &VRDeviceManager::PollEvents); | 338 &VRDeviceManager::PollEvents); |
| 316 } | 339 } |
| 317 | 340 |
| 318 void VRDeviceManager::PollEvents() { | 341 void VRDeviceManager::PollEvents() { |
| 319 for (const auto& provider : providers_) | 342 for (const auto& provider : providers_) |
| 320 provider->PollEvents(); | 343 provider->PollEvents(); |
| 321 } | 344 } |
| 322 | 345 |
| 323 void VRDeviceManager::StopSchedulingPollEvents() { | 346 void VRDeviceManager::StopSchedulingPollEvents() { |
| 324 if (has_scheduled_poll_) | 347 if (has_scheduled_poll_) |
| 325 timer_.Stop(); | 348 timer_.Stop(); |
| 326 } | 349 } |
| 327 | 350 |
| 328 } // namespace device | 351 } // namespace device |
| OLD | NEW |