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

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: Reworked as per new comments. Fixed build errors! 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..941d26e86e3a61cb4fd6bb6e868110cc4e81594d 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,66 @@ const char* VRController::supplementName()
return "VRController";
}
-void VRController::getDevices(WebVRGetDevicesCallback* callback)
+void VRController::getDevices(VRGetDevicesCallback* callback)
{
- // 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);
+ VRGetDevicesRequest* deviceRequest = new VRGetDevicesRequest(callback);
+ m_pendingRequests.add(adoptPtr(deviceRequest));
+ m_service->GetDevices(
+ sameThreadBindForMojoWithBoundArgs(&VRController::OnGetDevices, this, deviceRequest));
}
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_service->GetSensorState(
+ index,
+ sameThreadBindForMojoWithBoundArgs(&VRController::OnGetSensorState, this, &into));
+
+ // 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(VRGetDevicesRequest* deviceRequest, const mojo::Array<mojom::VRDeviceInfoPtr>& devices)
+{
+ WebVector<WebVRDevice> webDevices(devices.size());
+
+ VRGetDevicesCallback* callback = deviceRequest->getDevicesCallback();
+ if (!callback)
+ return;
+
+ for (size_t i = 0; i < devices.size(); ++i) {
+ webDevices[i] = devices[i].To<WebVRDevice>();
+ }
+
+ callback->onSuccess(webDevices);
+ ASSERT(m_pendingRequests.contains(deviceRequest));
+ m_pendingRequests.remove(deviceRequest);
haraken 2016/04/27 06:51:07 BTW, why do you need m_pendingRequests? If it's us
RaviKasibhatla 2016/04/27 14:33:49 I have removed this entire logic. I am now simply
+}
+
+void VRController::OnGetSensorState(WebHMDSensorState* state, const mojom::VRSensorStatePtr& mojoState)
+{
+ *state = mojoState.To<WebHMDSensorState>();
}
DEFINE_TRACE(VRController)
@@ -77,4 +110,19 @@ DEFINE_TRACE(VRController)
LocalFrameLifecycleObserver::trace(visitor);
}
+VRGetDevicesRequest::VRGetDevicesRequest(VRGetDevicesCallback* callback)
+{
+ m_getDevicesCallback = adoptPtr(callback);
haraken 2016/04/27 06:51:07 It's nasty to call adoptPtr for a raw pointer... V
+}
+
+VRGetDevicesRequest::~VRGetDevicesRequest()
+{
+ m_getDevicesCallback.clear();
haraken 2016/04/27 06:51:07 This won't be needed, since the destructor will au
+}
+
+VRGetDevicesCallback* VRGetDevicesRequest::getDevicesCallback() const
+{
+ return m_getDevicesCallback.get();
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698