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

Unified Diff: device/vr/vr_service_impl.cc

Issue 2167643003: Refactored VRService interaction and added VRServiceClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Liberal sprinkling of 'u's Created 4 years, 5 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
« no previous file with comments | « device/vr/vr_service_impl.h ('k') | device/vr/vr_service_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/vr/vr_service_impl.cc
diff --git a/device/vr/vr_service_impl.cc b/device/vr/vr_service_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ebb5bb021b1e250f5b991f4cf0359d0eddb5267a
--- /dev/null
+++ b/device/vr/vr_service_impl.cc
@@ -0,0 +1,68 @@
+// Copyright 2016 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 "device/vr/vr_service_impl.h"
+
+#include <utility>
+
+#include "base/bind.h"
+#include "device/vr/vr_device.h"
+#include "device/vr/vr_device_manager.h"
+
+namespace device {
+
+VRServiceImpl::VRServiceImpl() {}
+
+VRServiceImpl::~VRServiceImpl() {
+ RemoveFromDeviceManager();
+}
+
+void VRServiceImpl::BindRequest(mojo::InterfaceRequest<VRService> request) {
+ VRServiceImpl* service = new VRServiceImpl();
+ service->Bind(std::move(request));
+}
+
+void VRServiceImpl::Bind(mojo::InterfaceRequest<VRService> request) {
+ binding_.reset(new mojo::Binding<VRService>(this, std::move(request)));
+ binding_->set_connection_error_handler(base::Bind(
+ &VRServiceImpl::RemoveFromDeviceManager, base::Unretained(this)));
+}
+
+void VRServiceImpl::RemoveFromDeviceManager() {
+ VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
+ device_manager->RemoveService(this);
+}
+
+void VRServiceImpl::SetClient(VRServiceClientPtr client) {
+ DCHECK(!client_.get());
+
+ client_ = std::move(client);
+ VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
+ device_manager->AddService(this);
+}
+
+void VRServiceImpl::GetDisplays(const GetDisplaysCallback& callback) {
+ VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
+ callback.Run(device_manager->GetVRDevices());
+}
+
+void VRServiceImpl::GetPose(uint32_t index, const GetPoseCallback& callback) {
+ VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
+ VRDevice* device = device_manager->GetDevice(index);
+
+ if (device) {
+ callback.Run(device->GetPose());
+ } else {
+ callback.Run(nullptr);
+ }
+}
+
+void VRServiceImpl::ResetPose(uint32_t index) {
+ VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
+ VRDevice* device = device_manager->GetDevice(index);
+ if (device)
+ device->ResetPose();
+}
+
+} // namespace device
« no previous file with comments | « device/vr/vr_service_impl.h ('k') | device/vr/vr_service_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698