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 #ifndef DEVICE_SENSOR_SENSOR_SERVICE_H_ |
| 6 #define DEVICE_SENSOR_SENSOR_SERVICE_H_ |
| 7 |
| 8 #include "base/callback_list.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/singleton.h" |
| 12 |
| 13 #include "device/sensor/als_reading.mojom.h" |
| 14 #include "device/sensor/sensor_export.h" |
| 15 |
| 16 namespace base { |
| 17 class SingleThreadTaskRunner; |
| 18 } |
| 19 |
| 20 namespace device { |
| 21 class SensorManager; |
| 22 |
| 23 class DEVICE_SENSOR_EXPORT SensorService { |
| 24 public: |
| 25 typedef base::Callback<void(const AmbientLightSensorReading&)> |
| 26 SensorUpdateCallback; |
| 27 typedef base::CallbackList<void(const AmbientLightSensorReading&)> |
| 28 SensorUpdateCallbackList; |
| 29 typedef SensorUpdateCallbackList::Subscription SensorUpdateSubscription; |
| 30 |
| 31 // Returns the SensorService singleton. |
| 32 static SensorService* GetInstance(); |
| 33 |
| 34 scoped_ptr<SensorUpdateSubscription> AddCallback( |
| 35 const SensorUpdateCallback& callback); |
| 36 |
| 37 void Shutdown(); |
| 38 |
| 39 private: |
| 40 friend struct base::DefaultSingletonTraits<SensorService>; |
| 41 |
| 42 SensorService(); |
| 43 virtual ~SensorService(); |
| 44 |
| 45 // Updates current als_reading and sends new reading to interested |
| 46 // render processes. Can be called on any thread via a callback. |
| 47 void NotifyConsumers(const AmbientLightSensorReading& reading); |
| 48 void NotifyConsumersOnMainThread(const AmbientLightSensorReading& reading); |
| 49 void ConsumersChanged(); |
| 50 |
| 51 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
| 52 scoped_ptr<SensorManager> sensor_fetcher_; |
| 53 SensorUpdateCallbackList callback_list_; |
| 54 SensorUpdateCallback update_callback_; |
| 55 AmbientLightSensorReading reading_; |
| 56 bool reading_updated_; |
| 57 bool is_shutdown_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(SensorService); |
| 60 }; |
| 61 |
| 62 } // namespace device |
| 63 |
| 64 #endif // DEVICE_SENSOR_SENSOR_SERVICE_H_ |
OLD | NEW |