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

Side by Side 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, 6 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/renderer/vr/vr_dispatcher.h"
6
7 #include "content/public/common/service_registry.h"
8 #include "content/renderer/vr/vr_type_converters.h"
9
10 namespace content {
11
12 VRDispatcher::VRDispatcher(ServiceRegistry* service_registry)
13 : service_registry_(service_registry) {
14 }
15
16 VRDispatcher::~VRDispatcher() {
17 }
18
19 VRServicePtr& VRDispatcher::GetVRServicePtr() {
20 if (!vr_service_.get()) {
Ken Rockot(use gerrit already) 2015/05/31 23:43:47 nit: vr_service_ is testable, no need to get()
21 service_registry_->ConnectToRemoteService(mojo::GetProxy(&vr_service_));
22 }
23 return vr_service_;
24 }
25
26 void VRDispatcher::getDevices(blink::WebVRGetDevicesCallback* callback) {
27 int request_id = pending_requests_.Add(callback);
28 GetVRServicePtr()->GetDevices(
29 base::Bind(&VRDispatcher::OnGetDevices,
30 base::Unretained(this),
31 request_id));
32 }
33
34 void VRDispatcher::getSensorState(unsigned int index,
35 blink::WebHMDSensorState& state) {
36 GetVRServicePtr()->GetSensorState(index,
37 base::Bind(&VRDispatcher::OnGetSensorState,
Ken Rockot(use gerrit already) 2015/05/31 23:43:47 nit: OnGetSensorState doesn't actually need |this|
38 base::Unretained(this),
39 base::Unretained(&state)));
40
41 // TODO: Justify this.
Ken Rockot(use gerrit already) 2015/05/31 23:43:47 What do you mean? Justify the call to WaitForIncom
42 GetVRServicePtr().WaitForIncomingResponse();
43 }
44
45 void VRDispatcher::resetSensor(unsigned int index) {
46 GetVRServicePtr()->ResetSensor(index);
47 }
48
49 void VRDispatcher::OnGetDevices(
50 int request_id,
51 const mojo::Array<VRDeviceInfoPtr>& devices) {
52 blink::WebVector<blink::WebVRDevice> web_devices(devices.size());
53
54 blink::WebVRGetDevicesCallback* callback =
55 pending_requests_.Lookup(request_id);
56 if (!callback)
57 return;
58
59 for (size_t i = 0; i < devices.size(); ++i) {
60 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
61 web_devices[i] = mojo_device.To<blink::WebVRDevice>();
62 }
63
64 callback->onSuccess(&web_devices);
65 pending_requests_.Remove(request_id);
66 }
67
68 void VRDispatcher::OnGetSensorState(
69 blink::WebHMDSensorState* state,
70 const VRSensorStatePtr& mojo_state) {
71 *state = mojo_state.To<blink::WebHMDSensorState>();
72 }
73
74 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698