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

Unified Diff: device/vr/vr_service_impl.cc

Issue 2746233002: Fixes 2D-to-WebVR site transitions when browsing in VR. (Closed)
Patch Set: Fixed export Created 3 years, 9 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/vr/vr_service_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/vr/vr_service_impl.cc
diff --git a/device/vr/vr_service_impl.cc b/device/vr/vr_service_impl.cc
index 9d0fb36618c53e59443d23faf2597e3da3f59b4d..05b75b07221d06b45bbbbd7a4705902fad213047 100644
--- a/device/vr/vr_service_impl.cc
+++ b/device/vr/vr_service_impl.cc
@@ -14,7 +14,8 @@
namespace device {
-VRServiceImpl::VRServiceImpl() : listening_for_activate_(false) {}
+VRServiceImpl::VRServiceImpl()
+ : listening_for_activate_(false), weak_ptr_factory_(this) {}
VRServiceImpl::~VRServiceImpl() {
// Destroy VRDisplay before calling RemoveService below. RemoveService might
@@ -29,22 +30,6 @@ void VRServiceImpl::Create(mojo::InterfaceRequest<mojom::VRService> request) {
std::move(request));
}
-// Gets a VRDisplayPtr unique to this service so that the associated page can
-// communicate with the VRDevice.
-VRDisplayImpl* VRServiceImpl::GetVRDisplayImpl(VRDevice* device) {
- auto it = displays_.find(device);
- if (it != displays_.end())
- return it->second.get();
-
- VRDisplayImpl* display_impl = new VRDisplayImpl(device, this);
- displays_[device] = base::WrapUnique(display_impl);
- return display_impl;
-}
-
-void VRServiceImpl::RemoveDevice(VRDevice* device) {
- displays_.erase(device);
-}
-
void VRServiceImpl::SetClient(mojom::VRServiceClientPtr service_client,
const SetClientCallback& callback) {
DCHECK(!client_.get());
@@ -58,10 +43,39 @@ void VRServiceImpl::SetClient(mojom::VRServiceClientPtr service_client,
callback.Run(device_manager->GetNumberOfConnectedDevices());
}
+void VRServiceImpl::ConnectDevice(VRDevice* device) {
+ DCHECK(displays_.count(device) == 0);
+ base::Callback<void(mojom::VRDisplayInfoPtr)> on_created =
+ base::Bind(&VRServiceImpl::OnVRDisplayInfoCreated,
+ weak_ptr_factory_.GetWeakPtr(), device);
+ device->CreateVRDisplayInfo(on_created);
+}
+
void VRServiceImpl::SetListeningForActivate(bool listening) {
listening_for_activate_ = listening;
VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
device_manager->ListeningForActivateChanged(listening);
}
+// Creates a VRDisplayPtr unique to this service so that the associated page can
+// communicate with the VRDevice.
+void VRServiceImpl::OnVRDisplayInfoCreated(
+ VRDevice* device,
+ mojom::VRDisplayInfoPtr display_info) {
+ // TODO(crbug/701027): make sure that client_ is never null by initializing it
+ // in the constructor.
+ if (!client_) {
+ DLOG(ERROR) << "Cannot create VR display because connection to render "
+ "process is not established";
+ return;
+ }
+ displays_[device] = base::MakeUnique<VRDisplayImpl>(
+ device, this, client_.get(), std::move(display_info));
+}
+
+VRDisplayImpl* VRServiceImpl::GetVRDisplayImplForTesting(VRDevice* device) {
+ auto it = displays_.find(device);
+ return (it == displays_.end()) ? nullptr : it->second.get();
+}
+
} // namespace device
« no previous file with comments | « device/vr/vr_service_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698