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

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

Issue 2773223002: Fixes crash where the browser crashed when visiting WebVR pages without VR Services installed. (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
51 device->CreateVRDisplayInfo(on_created); 51 device->CreateVRDisplayInfo(on_created);
52 } 52 }
53 53
54 void VRServiceImpl::SetListeningForActivate(bool listening) { 54 void VRServiceImpl::SetListeningForActivate(bool listening) {
55 listening_for_activate_ = listening; 55 listening_for_activate_ = listening;
56 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); 56 VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
57 device_manager->ListeningForActivateChanged(listening); 57 device_manager->ListeningForActivateChanged(listening);
58 } 58 }
59 59
60 // Creates a VRDisplayPtr unique to this service so that the associated page can 60 // Creates a VRDisplayPtr unique to this service so that the associated page can
61 // communicate with the VRDevice. 61 // communicate with the VRDevice.
62 void VRServiceImpl::OnVRDisplayInfoCreated( 62 void VRServiceImpl::OnVRDisplayInfoCreated(
amp 2017/03/24 21:51:09 This might have been something from the previous c
billorr 2017/03/24 22:06:54 Long term (post Windows refactor) the device shoul
tiborg 2017/03/24 22:16:36 Yep, currently this is the workaround to say that
amp 2017/03/24 22:33:31 Ok, I'm fine with addressing this in a future refa
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.
74 DLOG(WARNING)
billorr 2017/03/24 21:46:55 NIT: Warning sounds like this is an invalid state,
tiborg 2017/03/24 22:16:36 Removed the warning.
75 << "Received null display info. Will not instantiate VRDisplayImpl.";
76 return;
77 }
72 displays_[device] = base::MakeUnique<VRDisplayImpl>( 78 displays_[device] = base::MakeUnique<VRDisplayImpl>(
73 device, this, client_.get(), std::move(display_info)); 79 device, this, client_.get(), std::move(display_info));
74 } 80 }
75 81
76 VRDisplayImpl* VRServiceImpl::GetVRDisplayImplForTesting(VRDevice* device) { 82 VRDisplayImpl* VRServiceImpl::GetVRDisplayImplForTesting(VRDevice* device) {
77 auto it = displays_.find(device); 83 auto it = displays_.find(device);
78 return (it == displays_.end()) ? nullptr : it->second.get(); 84 return (it == displays_.end()) ? nullptr : it->second.get();
79 } 85 }
80 86
81 } // namespace device 87 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698