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

Unified Diff: third_party/WebKit/Source/modules/vr/VRController.cpp

Issue 1808203005: [OnionSoup] Moving VR service from content to Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased to ToT! Created 4 years, 8 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/modules/vr/VRController.cpp
diff --git a/third_party/WebKit/Source/modules/vr/VRController.cpp b/third_party/WebKit/Source/modules/vr/VRController.cpp
index 36aa47c5b8dcc414b32a940ddd4bdb11a5a0442e..689f2f6123d66358e52f801c21ae57493b85f955 100644
--- a/third_party/WebKit/Source/modules/vr/VRController.cpp
+++ b/third_party/WebKit/Source/modules/vr/VRController.cpp
@@ -5,7 +5,10 @@
#include "modules/vr/VRController.h"
#include "core/frame/LocalFrame.h"
+#include "modules/vr/VRGetDevicesCallback.h"
#include "platform/RuntimeEnabledFeatures.h"
+#include "platform/mojo/MojoHelper.h"
+#include "public/platform/ServiceRegistry.h"
namespace blink {
@@ -13,11 +16,11 @@ VRController::~VRController()
{
}
-void VRController::provideTo(LocalFrame& frame, WebVRClient* client)
+void VRController::provideTo(LocalFrame& frame, ServiceRegistry* registry)
{
ASSERT(RuntimeEnabledFeatures::webVREnabled());
- VRController* controller = new VRController(frame, client);
+ VRController* controller = new VRController(frame, registry);
Supplement<LocalFrame>::provideTo(frame, supplementName(), controller);
}
@@ -26,10 +29,12 @@ VRController* VRController::from(LocalFrame& frame)
return static_cast<VRController*>(Supplement<LocalFrame>::from(frame, supplementName()));
}
-VRController::VRController(LocalFrame& frame, WebVRClient* client)
+VRController::VRController(LocalFrame& frame, ServiceRegistry* registry)
: LocalFrameLifecycleObserver(&frame)
- , m_client(client)
{
+ ASSERT(!m_service.is_bound());
+ ASSERT(registry);
+ registry->connectToRemoteService(mojo::GetProxy(&m_service));
}
const char* VRController::supplementName()
@@ -37,38 +42,62 @@ const char* VRController::supplementName()
return "VRController";
}
-void VRController::getDevices(WebVRGetDevicesCallback* callback)
+void VRController::getDevices(VRGetDevicesCallback* callback)
haraken 2016/04/27 15:52:12 getDevices() should take PassOwnPtr. See my below
RaviKasibhatla 2016/04/28 14:34:15 Done.
{
- // When detached, the client is no longer valid.
- if (!m_client) {
+ if (!m_service) {
callback->onError();
delete callback;
return;
}
- // Client is expected to take ownership of the callback
- m_client->getDevices(callback);
+ m_pendingGetDevicesCallbacks.append(callback);
+ m_service->GetDevices(sameThreadBindForMojo(&VRController::OnGetDevices, this));
bajones 2016/04/27 18:09:28 If multiple getDevices requests are made while one
RaviKasibhatla 2016/04/28 06:05:13 Isn't the current code doing the same? We are queu
}
void VRController::getSensorState(unsigned index, WebHMDSensorState& into)
{
- // When detached, the client is no longer valid.
- if (!m_client)
+ if (!m_service)
return;
- m_client->getSensorState(index, into);
+
+ m_pendingSensorStateRequest = &into;
+ m_service->GetSensorState(index, sameThreadBindForMojo(&VRController::OnGetSensorState, this));
+
+ // This call needs to return results synchronously in order to be useful and
+ // provide the lowest latency results possible.
+ m_service.WaitForIncomingResponse();
}
void VRController::resetSensor(unsigned index)
{
- // When detached, the client is no longer valid.
- if (!m_client)
+ if (!m_service)
return;
- m_client->resetSensor(index);
+ m_service->ResetSensor(index);
}
void VRController::willDetachFrameHost()
{
- m_client = nullptr;
+ resetSensor(0);
+}
+
+void VRController::OnGetDevices(const mojo::Array<mojom::VRDeviceInfoPtr>& devices)
+{
+ WebVector<WebVRDevice> webDevices(devices.size());
+
+ VRGetDevicesCallback* callback = m_pendingGetDevicesCallbacks.takeFirst();
+ if (!callback)
+ return;
+
+ for (size_t i = 0; i < devices.size(); ++i) {
+ webDevices[i] = devices[i].To<WebVRDevice>();
+ }
bajones 2016/04/27 18:09:28 Non-critical idea: Seems like this could benefit f
RaviKasibhatla 2016/04/28 06:05:13 Yes, currently it uses the converter added in VRTy
+
+ callback->onSuccess(webDevices);
+ delete callback;
haraken 2016/04/27 15:52:12 We should avoid calling manual delete. Can we mak
RaviKasibhatla 2016/04/28 06:05:13 Since we were already calling manual delete in VRC
RaviKasibhatla 2016/04/28 14:34:15 Done.
+}
+
+void VRController::OnGetSensorState(const mojom::VRSensorStatePtr& mojoState)
+{
+ *m_pendingSensorStateRequest = mojoState.To<WebHMDSensorState>();
}
DEFINE_TRACE(VRController)

Powered by Google App Engine
This is Rietveld 408576698