| Index: device/generic_sensor/platform_sensor_provider_mac.cc
|
| diff --git a/device/generic_sensor/platform_sensor_provider_mac.cc b/device/generic_sensor/platform_sensor_provider_mac.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2ef9711721e851d35c19aee16df2ff1457330c2d
|
| --- /dev/null
|
| +++ b/device/generic_sensor/platform_sensor_provider_mac.cc
|
| @@ -0,0 +1,75 @@
|
| +// 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/generic_sensor/platform_sensor_provider_mac.h"
|
| +
|
| +#include <list>
|
| +
|
| +#include "base/memory/singleton.h"
|
| +#include "device/generic_sensor/platform_sensor_ambient_light_mac.h"
|
| +#include "device/generic_sensor/platform_sensor_polling_mac.h"
|
| +
|
| +namespace device {
|
| +
|
| +// static
|
| +PlatformSensorProvider* PlatformSensorProvider::GetInstance() {
|
| + return PlatformSensorProviderMac::GetInstance();
|
| +}
|
| +
|
| +// static
|
| +PlatformSensorProviderMac* PlatformSensorProviderMac::GetInstance() {
|
| + return base::Singleton<
|
| + PlatformSensorProviderMac,
|
| + base::LeakySingletonTraits<PlatformSensorProviderMac>>::get();
|
| +}
|
| +
|
| +void PlatformSensorProviderMac::BeginPollingSensor(
|
| + PlatformSensor* sensor,
|
| + const PlatformSensorConfiguration& configuration) {
|
| + if (!polling_thread_) {
|
| + polling_thread_.reset(new SensorsPollingThreadMac("Sensor poller Mac"));
|
| + if (!polling_thread_->Start()) {
|
| + LOG(WARNING) << "Couldn't start the polling thread.";
|
| + return;
|
| + }
|
| + }
|
| +
|
| + PlatformSensorMac* sensor_mac = static_cast<PlatformSensorMac*>(sensor);
|
| + polling_thread_->task_runner()->PostTask(
|
| + FROM_HERE, base::Bind(&SensorsPollingThreadMac::BeginPollingSensor,
|
| + base::Unretained(polling_thread_.get()), sensor_mac,
|
| + configuration));
|
| +}
|
| +
|
| +void PlatformSensorProviderMac::StopPollingSensor(PlatformSensor* sensor) {
|
| + PlatformSensorMac* sensor_mac = static_cast<PlatformSensorMac*>(sensor);
|
| + polling_thread_->task_runner()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&SensorsPollingThreadMac::StopPollingSensor,
|
| + base::Unretained(polling_thread_.get()), sensor_mac));
|
| +}
|
| +
|
| +PlatformSensorProviderMac::PlatformSensorProviderMac() {}
|
| +
|
| +PlatformSensorProviderMac::~PlatformSensorProviderMac() {
|
| + if (polling_thread_)
|
| + polling_thread_->Stop();
|
| +}
|
| +
|
| +scoped_refptr<PlatformSensor> PlatformSensorProviderMac::CreateSensorInternal(
|
| + mojom::SensorType type,
|
| + mojo::ScopedSharedBufferMapping mapping,
|
| + uint64_t buffer_size) {
|
| + // Create Sensors here.
|
| + switch (type) {
|
| + case mojom::SensorType::AMBIENT_LIGHT:
|
| + return new PlatformSensorAmbientLightMac(type, std::move(mapping),
|
| + buffer_size, this);
|
| + default:
|
| + NOTIMPLEMENTED();
|
| + return nullptr;
|
| + }
|
| +}
|
| +
|
| +} // namespace device
|
|
|