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 "base/threading/thread.h" | |
11 #include "device/generic_sensor/platform_sensor_ambient_light_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 PlatformSensorProviderMac::PlatformSensorProviderMac() = default; | |
28 | |
29 PlatformSensorProviderMac::~PlatformSensorProviderMac() { | |
30 if (polling_thread_) | |
31 polling_thread_->Stop(); | |
32 } | |
33 | |
34 scoped_refptr<PlatformSensor> PlatformSensorProviderMac::CreateSensorInternal( | |
35 mojom::SensorType type, | |
36 mojo::ScopedSharedBufferMapping mapping, | |
37 uint64_t buffer_size) { | |
38 if (!polling_thread_) { | |
39 polling_thread_.reset(new base::Thread("Sensor poller Mac")); | |
Robert Sesek
2016/09/20 14:25:21
If we do use polling polling, does this really nee
| |
40 if (!polling_thread_->Start()) { | |
41 LOG(WARNING) << "Couldn't start the polling thread."; | |
42 return nullptr; | |
43 } | |
44 } | |
45 // Create Sensors here. | |
46 switch (type) { | |
47 case mojom::SensorType::AMBIENT_LIGHT: | |
48 return new PlatformSensorAmbientLightMac(type, std::move(mapping), | |
49 buffer_size, this, | |
50 polling_thread_->task_runner()); | |
51 default: | |
52 NOTIMPLEMENTED(); | |
53 return nullptr; | |
54 } | |
55 } | |
56 | |
57 } // namespace device | |
OLD | NEW |