OLD | NEW |
(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/generic_sensor/platform_sensor_provider_mac.h" |
| 6 |
| 7 #include <list> |
| 8 |
| 9 #include "base/memory/singleton.h" |
| 10 #include "device/generic_sensor/platform_sensor_ambient_light_mac.h" |
| 11 #include "device/generic_sensor/platform_sensor_polling_mac.h" |
| 12 |
| 13 namespace device { |
| 14 |
| 15 // static |
| 16 PlatformSensorProvider* PlatformSensorProvider::GetInstance() { |
| 17 return PlatformSensorProviderMac::GetInstance(); |
| 18 } |
| 19 |
| 20 // static |
| 21 PlatformSensorProviderMac* PlatformSensorProviderMac::GetInstance() { |
| 22 return base::Singleton< |
| 23 PlatformSensorProviderMac, |
| 24 base::LeakySingletonTraits<PlatformSensorProviderMac>>::get(); |
| 25 } |
| 26 |
| 27 void PlatformSensorProviderMac::BeginPollingSensor( |
| 28 PlatformSensor* sensor, |
| 29 const PlatformSensorConfiguration& configuration) { |
| 30 if (!polling_thread_) { |
| 31 polling_thread_.reset(new SensorsPollingThreadMac("Sensor poller Mac")); |
| 32 if (!polling_thread_->Start()) { |
| 33 LOG(WARNING) << "Couldn't start the polling thread."; |
| 34 return; |
| 35 } |
| 36 } |
| 37 |
| 38 PlatformSensorMac* sensor_mac = static_cast<PlatformSensorMac*>(sensor); |
| 39 polling_thread_->task_runner()->PostTask( |
| 40 FROM_HERE, base::Bind(&SensorsPollingThreadMac::BeginPollingSensor, |
| 41 base::Unretained(polling_thread_.get()), sensor_mac, |
| 42 configuration)); |
| 43 } |
| 44 |
| 45 void PlatformSensorProviderMac::StopPollingSensor(PlatformSensor* sensor) { |
| 46 PlatformSensorMac* sensor_mac = static_cast<PlatformSensorMac*>(sensor); |
| 47 polling_thread_->task_runner()->PostTask( |
| 48 FROM_HERE, |
| 49 base::Bind(&SensorsPollingThreadMac::StopPollingSensor, |
| 50 base::Unretained(polling_thread_.get()), sensor_mac)); |
| 51 } |
| 52 |
| 53 PlatformSensorProviderMac::PlatformSensorProviderMac() {} |
| 54 |
| 55 PlatformSensorProviderMac::~PlatformSensorProviderMac() { |
| 56 if (polling_thread_) |
| 57 polling_thread_->Stop(); |
| 58 } |
| 59 |
| 60 scoped_refptr<PlatformSensor> PlatformSensorProviderMac::CreateSensorInternal( |
| 61 mojom::SensorType type, |
| 62 mojo::ScopedSharedBufferMapping mapping, |
| 63 uint64_t buffer_size) { |
| 64 // Create Sensors here. |
| 65 switch (type) { |
| 66 case mojom::SensorType::AMBIENT_LIGHT: |
| 67 return new PlatformSensorAmbientLightMac(type, std::move(mapping), |
| 68 buffer_size, this); |
| 69 default: |
| 70 NOTIMPLEMENTED(); |
| 71 return nullptr; |
| 72 } |
| 73 } |
| 74 |
| 75 } // namespace device |
OLD | NEW |