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

Unified Diff: device/vr/vr_device.cc

Issue 2658643003: Refactor GvrDelegate ownership into GvrDelegateProvider and fix more threading violations. (Closed)
Patch Set: Address comments Created 3 years, 11 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_device.h ('k') | device/vr/vr_display_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/vr/vr_device.cc
diff --git a/device/vr/vr_device.cc b/device/vr/vr_device.cc
index b89fc44c267006b7852abe67a2ff5cd26d7c86d8..52d81bc359f184c83ce7d7280e9589ad91a114b7 100644
--- a/device/vr/vr_device.cc
+++ b/device/vr/vr_device.cc
@@ -10,7 +10,8 @@ namespace device {
unsigned int VRDevice::next_id_ = 1;
-VRDevice::VRDevice() : presenting_display_(nullptr), id_(next_id_) {
+VRDevice::VRDevice()
+ : presenting_display_(nullptr), id_(next_id_), weak_ptr_factory_(this) {
// Prevent wraparound. Devices with this ID will be treated as invalid.
if (next_id_ != VR_DEVICE_LAST_ID)
next_id_++;
@@ -43,19 +44,24 @@ bool VRDevice::CheckPresentingDisplay(VRDisplayImpl* display) {
}
void VRDevice::OnChanged() {
- mojom::VRDisplayInfoPtr vr_device_info = GetVRDevice();
+ base::Callback<void(mojom::VRDisplayInfoPtr)> callback = base::Bind(
+ &VRDevice::OnVRDisplayInfoCreated, weak_ptr_factory_.GetWeakPtr());
+ GetVRDevice(callback);
+}
+
+void VRDevice::OnVRDisplayInfoCreated(mojom::VRDisplayInfoPtr vr_device_info) {
if (vr_device_info.is_null())
return;
-
for (const auto& display : displays_)
display->client()->OnChanged(vr_device_info.Clone());
}
void VRDevice::OnExitPresent() {
+ if (!presenting_display_)
+ return;
auto it = displays_.find(presenting_display_);
- if (it != displays_.end())
- (*it)->client()->OnExitPresent();
-
+ CHECK(it != displays_.end());
+ (*it)->client()->OnExitPresent();
SetPresentingDisplay(nullptr);
}
« no previous file with comments | « device/vr/vr_device.h ('k') | device/vr/vr_display_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698