| Index: device/sensor/sensor_service.h
|
| diff --git a/device/sensor/sensor_service.h b/device/sensor/sensor_service.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..61e46b0fde0508ff3712b5b574a31c2fcc6d5715
|
| --- /dev/null
|
| +++ b/device/sensor/sensor_service.h
|
| @@ -0,0 +1,64 @@
|
| +// 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.
|
| +
|
| +#ifndef DEVICE_SENSOR_SENSOR_SERVICE_H_
|
| +#define DEVICE_SENSOR_SENSOR_SERVICE_H_
|
| +
|
| +#include "base/callback_list.h"
|
| +#include "base/macros.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/memory/singleton.h"
|
| +
|
| +#include "device/sensor/als_reading.mojom.h"
|
| +#include "device/sensor/sensor_export.h"
|
| +
|
| +namespace base {
|
| +class SingleThreadTaskRunner;
|
| +}
|
| +
|
| +namespace device {
|
| +class SensorManager;
|
| +
|
| +class DEVICE_SENSOR_EXPORT SensorService {
|
| + public:
|
| + typedef base::Callback<void(const AmbientLightSensorReading&)>
|
| + SensorUpdateCallback;
|
| + typedef base::CallbackList<void(const AmbientLightSensorReading&)>
|
| + SensorUpdateCallbackList;
|
| + typedef SensorUpdateCallbackList::Subscription SensorUpdateSubscription;
|
| +
|
| + // Returns the SensorService singleton.
|
| + static SensorService* GetInstance();
|
| +
|
| + scoped_ptr<SensorUpdateSubscription> AddCallback(
|
| + const SensorUpdateCallback& callback);
|
| +
|
| + void Shutdown();
|
| +
|
| + private:
|
| + friend struct base::DefaultSingletonTraits<SensorService>;
|
| +
|
| + SensorService();
|
| + virtual ~SensorService();
|
| +
|
| + // Updates current als_reading and sends new reading to interested
|
| + // render processes. Can be called on any thread via a callback.
|
| + void NotifyConsumers(const AmbientLightSensorReading& reading);
|
| + void NotifyConsumersOnMainThread(const AmbientLightSensorReading& reading);
|
| + void ConsumersChanged();
|
| +
|
| + scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
|
| + scoped_ptr<SensorManager> sensor_fetcher_;
|
| + SensorUpdateCallbackList callback_list_;
|
| + SensorUpdateCallback update_callback_;
|
| + AmbientLightSensorReading reading_;
|
| + bool reading_updated_;
|
| + bool is_shutdown_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(SensorService);
|
| +};
|
| +
|
| +} // namespace device
|
| +
|
| +#endif // DEVICE_SENSOR_SENSOR_SERVICE_H_
|
|
|