forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorientation_device_provider.cc
58 lines (45 loc) · 1.76 KB
/
orientation_device_provider.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "device/vr/orientation/orientation_device_provider.h"
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "device/vr/orientation/orientation_device.h"
#include "services/device/public/mojom/sensor_provider.mojom.h"
namespace device {
VROrientationDeviceProvider::VROrientationDeviceProvider(
mojo::PendingRemote<device::mojom::SensorProvider> sensor_provider)
: sensor_provider_(std::move(sensor_provider)) {}
VROrientationDeviceProvider::~VROrientationDeviceProvider() = default;
void VROrientationDeviceProvider::Initialize(VRDeviceProviderClient* client) {
if (device_ && device_->IsAvailable()) {
client->AddRuntime(device_->GetId(), device_->GetDeviceData(),
device_->BindXRRuntime());
return;
}
if (!device_) {
client_ = client;
device_ = std::make_unique<VROrientationDevice>(
sensor_provider_.get(),
base::BindOnce(&VROrientationDeviceProvider::DeviceInitialized,
base::Unretained(this)));
}
}
bool VROrientationDeviceProvider::Initialized() {
return initialized_;
}
void VROrientationDeviceProvider::DeviceInitialized() {
// This should only be called after the device is initialized.
DCHECK(device_);
// This should only be called once.
DCHECK(!initialized_);
// If the device successfully connected to the orientation APIs, provide it.
if (device_->IsAvailable()) {
client_->AddRuntime(device_->GetId(), device_->GetDeviceData(),
device_->BindXRRuntime());
}
initialized_ = true;
client_->OnProviderInitialized();
}
} // namespace device