Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Unified Diff: device/sensor/sensor_service.h

Issue 1892083002: Generic Sensor API : Ambient Light Sensor API. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: re entrancy fix Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/sensor/sensor_manager_default.cc ('k') | device/sensor/sensor_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..a52b52c34d12e666964b0a48a99f686ceec7f87c
--- /dev/null
+++ b/device/sensor/sensor_service.h
@@ -0,0 +1,63 @@
+// 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/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();
+
+ std::unique_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_;
+ std::unique_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_
« no previous file with comments | « device/sensor/sensor_manager_default.cc ('k') | device/sensor/sensor_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698