Chromium Code Reviews| 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..220fb4a5b56e7a4c6c1fab1fd3b45e5476811381 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,12 +16,10 @@ 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); |
| - Supplement<LocalFrame>::provideTo(frame, supplementName(), controller); |
| + Supplement<LocalFrame>::provideTo(frame, supplementName(), registry ? new VRController(frame, registry) : nullptr); |
| } |
| VRController* VRController::from(LocalFrame& frame) |
| @@ -26,10 +27,11 @@ 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()); |
| + registry->connectToRemoteService(mojo::GetProxy(&m_service)); |
| } |
| const char* VRController::supplementName() |
| @@ -37,38 +39,60 @@ const char* VRController::supplementName() |
| return "VRController"; |
| } |
| -void VRController::getDevices(WebVRGetDevicesCallback* callback) |
| +void VRController::getDevices(PassOwnPtr<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); |
| + m_pendingGetDevicesCallbacks.append(std::move(callback)); |
| + m_service->GetDevices(sameThreadBindForMojo(&VRController::OnGetDevices, this)); |
| } |
| 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); |
|
dcheng
2016/04/28 19:59:44
Why is this always 0?
bajones
2016/04/28 20:21:51
I don't see a reason for the call to be there at a
RaviKasibhatla
2016/04/29 14:49:05
Agree. I have removed the resetSensor(0). However,
RaviKasibhatla
2016/05/03 14:34:21
@bajones: Can we take the detaching of service in
|
| +} |
| + |
| +void VRController::OnGetDevices(const mojo::Array<mojom::VRDeviceInfoPtr>& devices) |
| +{ |
| + WebVector<WebVRDevice> webDevices(devices.size()); |
| + |
| + VRGetDevicesCallback* callback = m_pendingGetDevicesCallbacks.takeFirst().get(); |
|
haraken
2016/04/28 14:50:03
OwnPtr<VRGetDevicesCallback> callback = m_pendingG
RaviKasibhatla
2016/04/28 18:08:33
Done. Will make the change.
RaviKasibhatla
2016/04/29 14:49:05
Done.
|
| + if (!callback) |
| + return; |
| + |
| + for (size_t i = 0; i < devices.size(); ++i) { |
| + webDevices[i] = devices[i].To<WebVRDevice>(); |
| + } |
| + |
| + callback->onSuccess(webDevices); |
| +} |
| + |
| +void VRController::OnGetSensorState(const mojom::VRSensorStatePtr& mojoState) |
| +{ |
| + *m_pendingSensorStateRequest = mojoState.To<WebHMDSensorState>(); |
| } |
| DEFINE_TRACE(VRController) |