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

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