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

Unified Diff: content/renderer/vr/vr_dispatcher.cc

Issue 829803003: Adding Chrome-side WebVR interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated to use Mojo as requested by eng review Created 5 years, 7 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: content/renderer/vr/vr_dispatcher.cc
diff --git a/content/renderer/vr/vr_dispatcher.cc b/content/renderer/vr/vr_dispatcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..28bc4628d0d25bd83879b59f19521377567809f4
--- /dev/null
+++ b/content/renderer/vr/vr_dispatcher.cc
@@ -0,0 +1,74 @@
+// 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 "content/renderer/vr/vr_dispatcher.h"
+
+#include "content/public/common/service_registry.h"
+#include "content/renderer/vr/vr_type_converters.h"
+
+namespace content {
+
+VRDispatcher::VRDispatcher(ServiceRegistry* service_registry)
+ : service_registry_(service_registry) {
+}
+
+VRDispatcher::~VRDispatcher() {
+}
+
+VRServicePtr& VRDispatcher::GetVRServicePtr() {
+ if (!vr_service_.get()) {
Ken Rockot(use gerrit already) 2015/05/31 23:43:47 nit: vr_service_ is testable, no need to get()
+ service_registry_->ConnectToRemoteService(mojo::GetProxy(&vr_service_));
+ }
+ return vr_service_;
+}
+
+void VRDispatcher::getDevices(blink::WebVRGetDevicesCallback* callback) {
+ int request_id = pending_requests_.Add(callback);
+ GetVRServicePtr()->GetDevices(
+ base::Bind(&VRDispatcher::OnGetDevices,
+ base::Unretained(this),
+ request_id));
+}
+
+void VRDispatcher::getSensorState(unsigned int index,
+ blink::WebHMDSensorState& state) {
+ GetVRServicePtr()->GetSensorState(index,
+ base::Bind(&VRDispatcher::OnGetSensorState,
Ken Rockot(use gerrit already) 2015/05/31 23:43:47 nit: OnGetSensorState doesn't actually need |this|
+ base::Unretained(this),
+ base::Unretained(&state)));
+
+ // TODO: Justify this.
Ken Rockot(use gerrit already) 2015/05/31 23:43:47 What do you mean? Justify the call to WaitForIncom
+ GetVRServicePtr().WaitForIncomingResponse();
+}
+
+void VRDispatcher::resetSensor(unsigned int index) {
+ GetVRServicePtr()->ResetSensor(index);
+}
+
+void VRDispatcher::OnGetDevices(
+ int request_id,
+ const mojo::Array<VRDeviceInfoPtr>& devices) {
+ blink::WebVector<blink::WebVRDevice> web_devices(devices.size());
+
+ blink::WebVRGetDevicesCallback* callback =
+ pending_requests_.Lookup(request_id);
+ if (!callback)
+ return;
+
+ for (size_t i = 0; i < devices.size(); ++i) {
+ const VRDeviceInfoPtr& mojo_device = devices[i];
Ken Rockot(use gerrit already) 2015/05/31 23:43:47 nit: maybe just do devices[i].To<blink::WebVRDevic
+ web_devices[i] = mojo_device.To<blink::WebVRDevice>();
+ }
+
+ callback->onSuccess(&web_devices);
+ pending_requests_.Remove(request_id);
+}
+
+void VRDispatcher::OnGetSensorState(
+ blink::WebHMDSensorState* state,
+ const VRSensorStatePtr& mojo_state) {
+ *state = mojo_state.To<blink::WebHMDSensorState>();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698