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

Side by Side 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, 4 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
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 "device/vr/vr_service_impl.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "device/vr/vr_device.h"
11 #include "device/vr/vr_device_manager.h"
12
13 namespace device {
14
15 VRServiceImpl::VRServiceImpl() {}
16
17 VRServiceImpl::~VRServiceImpl() {
18 RemoveFromDeviceManager();
19 }
20
21 void VRServiceImpl::BindRequest(mojo::InterfaceRequest<VRService> request) {
22 VRServiceImpl* service = new VRServiceImpl();
23 service->Bind(std::move(request));
24 }
25
26 void VRServiceImpl::Bind(mojo::InterfaceRequest<VRService> request) {
27 binding_.reset(new mojo::Binding<VRService>(this, std::move(request)));
28 binding_->set_connection_error_handler(base::Bind(
29 &VRServiceImpl::RemoveFromDeviceManager, base::Unretained(this)));
30 }
31
32 void VRServiceImpl::RemoveFromDeviceManager() {
33 VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
34 device_manager->RemoveService(this);
35 }
36
37 void VRServiceImpl::SetClient(VRServiceClientPtr client) {
38 DCHECK(!client_.get());
39
40 client_ = std::move(client);
41 VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
42 device_manager->AddService(this);
43 }
44
45 void VRServiceImpl::GetDisplays(const GetDisplaysCallback& callback) {
46 VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
47 callback.Run(device_manager->GetVRDevices());
48 }
49
50 void VRServiceImpl::GetPose(uint32_t index, const GetPoseCallback& callback) {
51 VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
52 VRDevice* device = device_manager->GetDevice(index);
53
54 if (device) {
55 callback.Run(device->GetPose());
56 } else {
57 callback.Run(nullptr);
58 }
59 }
60
61 void VRServiceImpl::ResetPose(uint32_t index) {
62 VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
63 VRDevice* device = device_manager->GetDevice(index);
64 if (device)
65 device->ResetPose();
66 }
67
68 } // namespace device
OLDNEW
« 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