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

Unified Diff: third_party/WebKit/Source/platform/vr/vr_dispatcher.cc

Issue 1808203005: [OnionSoup] Moving VR service from content to Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reworked as per comments! Created 4 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
Index: third_party/WebKit/Source/platform/vr/vr_dispatcher.cc
diff --git a/third_party/WebKit/Source/platform/vr/vr_dispatcher.cc b/third_party/WebKit/Source/platform/vr/vr_dispatcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dc8c51f4ee242dc698224b1c0f0379f532fd380f
--- /dev/null
+++ b/third_party/WebKit/Source/platform/vr/vr_dispatcher.cc
@@ -0,0 +1,88 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "platform/vr/vr_dispatcher.h"
+
+#include "platform/threading/BindForMojo.h"
+#include "platform/vr/vr_type_converters.h"
+#include "public/platform/Platform.h"
+
+namespace blink {
+
+VRGetDevicesRequest::VRGetDevicesRequest(WebVRGetDevicesCallback* callback)
+ : get_devices_callback_(callback) {
+}
+
+VRGetDevicesRequest::~VRGetDevicesRequest() {
+ get_devices_callback_ = nullptr;
+}
+
+WebVRGetDevicesCallback*
+ VRGetDevicesRequest::get_devices_callback() const {
+ return get_devices_callback_;
+}
+
+// static
+WebVRClient* VRDispatcher::create()
+{
+ return new VRDispatcher();
+}
+
+VRDispatcher::VRDispatcher() {
+}
+
+VRDispatcher::~VRDispatcher() {
+}
+
+mojom::VRServicePtr& VRDispatcher::GetVRServicePtr() {
+ if (!vr_service_)
+ Platform::current()->connectToRemoteService(mojo::GetProxy(&vr_service_));
+ return vr_service_;
+}
+
+void VRDispatcher::getDevices(WebVRGetDevicesCallback* callback) {
+ VRGetDevicesRequest* device_request = new VRGetDevicesRequest(callback);
+ GetVRServicePtr()->GetDevices(
+ sameThreadBindForMojoWithBoundArgs(&VRDispatcher::OnGetDevices,
+ this, device_request));
+}
+
+void VRDispatcher::getSensorState(unsigned int index,
+ WebHMDSensorState& state) {
+ GetVRServicePtr()->GetSensorState(
+ index,
+ sameThreadBindForMojoWithBoundArgs(&VRDispatcher::OnGetSensorState,
+ this, &state));
+
+ // This call needs to return results synchronously in order to be useful and
+ // provide the lowest latency results possible.
+ GetVRServicePtr().WaitForIncomingResponse();
+}
+
+void VRDispatcher::resetSensor(unsigned int index) {
+ GetVRServicePtr()->ResetSensor(index);
+}
+
+void VRDispatcher::OnGetDevices(VRGetDevicesRequest* device_request,
+ const mojo::Array<mojom::VRDeviceInfoPtr>& devices) {
+ WebVector<WebVRDevice> web_devices(devices.size());
+
+ WebVRGetDevicesCallback* callback = device_request->get_devices_callback();
+ if (!callback)
+ return;
+
+ for (size_t i = 0; i < devices.size(); ++i) {
+ web_devices[i] = devices[i].To<WebVRDevice>();
+ }
+
+ callback->onSuccess(web_devices);
+ delete device_request;
haraken 2016/03/22 02:39:20 We really want to avoid calling manual delete. Can
RaviKasibhatla 2016/03/23 15:20:50 Done.
+}
+
+void VRDispatcher::OnGetSensorState(WebHMDSensorState* state,
+ const mojom::VRSensorStatePtr& mojo_state) {
+ *state = mojo_state.To<WebHMDSensorState>();
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698