Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_service_impl.h" | 5 #include "device/vr/vr_service_impl.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 18 matching lines...) Expand all Loading... | |
| 29 mojo::MakeStrongBinding(base::MakeUnique<VRServiceImpl>(), | 29 mojo::MakeStrongBinding(base::MakeUnique<VRServiceImpl>(), |
| 30 std::move(request)); | 30 std::move(request)); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void VRServiceImpl::SetClient(mojom::VRServiceClientPtr service_client, | 33 void VRServiceImpl::SetClient(mojom::VRServiceClientPtr service_client, |
| 34 const SetClientCallback& callback) { | 34 const SetClientCallback& callback) { |
| 35 DCHECK(!client_.get()); | 35 DCHECK(!client_.get()); |
| 36 client_ = std::move(service_client); | 36 client_ = std::move(service_client); |
| 37 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); | 37 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); |
| 38 // Once a client has been connected AddService will force any VRDisplays to | 38 // Once a client has been connected AddService will force any VRDisplays to |
| 39 // send OnConnected to it so that it's populated with the currently active | 39 // send ConnectDevice to it so that it's populated with the currently active |
| 40 // displays. Thereafer it will stay up to date by virtue of listening for new | 40 // displays. Thereafter it will stay up to date by virtue of listening for new |
| 41 // connected events. | 41 // connected events. |
| 42 device_manager->AddService(this); | 42 device_manager->AddService(this); |
| 43 callback.Run(device_manager->GetNumberOfConnectedDevices()); | 43 callback.Run(device_manager->GetNumberOfConnectedDevices()); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void VRServiceImpl::ConnectDevice(VRDevice* device) { | 46 void VRServiceImpl::ConnectDevice(VRDevice* device) { |
| 47 DCHECK(displays_.count(device) == 0); | 47 DCHECK(displays_.count(device) == 0); |
| 48 base::Callback<void(mojom::VRDisplayInfoPtr)> on_created = | 48 base::Callback<void(mojom::VRDisplayInfoPtr)> on_created = |
| 49 base::Bind(&VRServiceImpl::OnVRDisplayInfoCreated, | 49 base::Bind(&VRServiceImpl::OnVRDisplayInfoCreated, |
| 50 weak_ptr_factory_.GetWeakPtr(), device); | 50 weak_ptr_factory_.GetWeakPtr(), device); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 62 void VRServiceImpl::OnVRDisplayInfoCreated( | 62 void VRServiceImpl::OnVRDisplayInfoCreated( |
| 63 VRDevice* device, | 63 VRDevice* device, |
| 64 mojom::VRDisplayInfoPtr display_info) { | 64 mojom::VRDisplayInfoPtr display_info) { |
| 65 // TODO(crbug/701027): make sure that client_ is never null by initializing it | 65 // TODO(crbug/701027): make sure that client_ is never null by initializing it |
| 66 // in the constructor. | 66 // in the constructor. |
| 67 if (!client_) { | 67 if (!client_) { |
| 68 DLOG(ERROR) << "Cannot create VR display because connection to render " | 68 DLOG(ERROR) << "Cannot create VR display because connection to render " |
| 69 "process is not established"; | 69 "process is not established"; |
| 70 return; | 70 return; |
| 71 } | 71 } |
| 72 if (!display_info) { | |
| 73 // We cannot instantiate a display with a null display info. | |
|
amp
2017/03/24 22:33:31
Would be nice to call out (until we fix it) the re
tiborg
2017/03/27 14:53:25
Added a comment to clarify.
| |
| 74 return; | |
| 75 } | |
| 72 displays_[device] = base::MakeUnique<VRDisplayImpl>( | 76 displays_[device] = base::MakeUnique<VRDisplayImpl>( |
| 73 device, this, client_.get(), std::move(display_info)); | 77 device, this, client_.get(), std::move(display_info)); |
| 74 } | 78 } |
| 75 | 79 |
| 76 VRDisplayImpl* VRServiceImpl::GetVRDisplayImplForTesting(VRDevice* device) { | 80 VRDisplayImpl* VRServiceImpl::GetVRDisplayImplForTesting(VRDevice* device) { |
| 77 auto it = displays_.find(device); | 81 auto it = displays_.find(device); |
| 78 return (it == displays_.end()) ? nullptr : it->second.get(); | 82 return (it == displays_.end()) ? nullptr : it->second.get(); |
| 79 } | 83 } |
| 80 | 84 |
| 81 } // namespace device | 85 } // namespace device |
| OLD | NEW |