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

Side by Side Diff: device/sensors/device_sensor_service.h

Issue 2730333002: Make DeviceSensorService implement MainLoop::DestructionObserver (Closed)
Patch Set: code rebase Created 3 years, 9 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 | « content/browser/browser_main_loop.cc ('k') | device/sensors/device_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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DEVICE_SENSORS_DEVICE_SENSOR_SERVICE_H_ 5 #ifndef DEVICE_SENSORS_DEVICE_SENSOR_SERVICE_H_
6 #define DEVICE_SENSORS_DEVICE_SENSOR_SERVICE_H_ 6 #define DEVICE_SENSORS_DEVICE_SENSOR_SERVICE_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback_forward.h" 10 #include "base/callback_forward.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/shared_memory.h" 12 #include "base/memory/shared_memory.h"
13 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "base/message_loop/message_loop.h"
14 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
15 #include "device/sensors/device_sensor_export.h" 16 #include "device/sensors/device_sensor_export.h"
16 #include "device/sensors/device_sensors_consts.h" 17 #include "device/sensors/device_sensors_consts.h"
17 #include "mojo/public/cpp/system/buffer.h" 18 #include "mojo/public/cpp/system/buffer.h"
18 19
19 namespace device { 20 namespace device {
20 21
21 class DataFetcherSharedMemory; 22 class DataFetcherSharedMemory;
22 23
23 // Owns the data fetcher for Device Motion and Orientation and keeps track of 24 // Owns the data fetcher for Device Motion and Orientation and keeps track of
24 // the number of consumers currently using the data. The data fetcher is stopped 25 // the number of consumers currently using the data. The data fetcher is stopped
25 // when there are no consumers. 26 // when there are no consumers.
26 class DEVICE_SENSOR_EXPORT DeviceSensorService { 27 class DEVICE_SENSOR_EXPORT DeviceSensorService
28 : public base::MessageLoop::DestructionObserver {
27 public: 29 public:
28 // Returns the DeviceSensorService singleton. 30 // Returns the DeviceSensorService singleton.
29 static DeviceSensorService* GetInstance(); 31 static DeviceSensorService* GetInstance();
30 32
31 // Increments the number of users of the provider. The Provider is running 33 // Increments the number of users of the provider. The Provider is running
32 // when there's > 0 users, and is paused when the count drops to 0. 34 // when there's > 0 users, and is paused when the count drops to 0.
33 // Must be called on the I/O thread. 35 // Must be called on the I/O thread.
34 void AddConsumer(ConsumerType consumer_type); 36 void AddConsumer(ConsumerType consumer_type);
35 37
36 // Removes a consumer. Should be matched with an AddConsumer call. 38 // Removes a consumer. Should be matched with an AddConsumer call.
37 // Must be called on the I/O thread. 39 // Must be called on the I/O thread.
38 void RemoveConsumer(ConsumerType cosumer_type); 40 void RemoveConsumer(ConsumerType cosumer_type);
39 41
40 // Returns the shared memory handle of the device motion data. 42 // Returns the shared memory handle of the device motion data.
41 mojo::ScopedSharedBufferHandle GetSharedMemoryHandle( 43 mojo::ScopedSharedBufferHandle GetSharedMemoryHandle(
42 ConsumerType consumer_type); 44 ConsumerType consumer_type);
43 45
46 // base::MessageLoop::DestructionObserver:
47 void WillDestroyCurrentMessageLoop() override;
48
44 // Stop/join with the background polling thread in |provider_|. 49 // Stop/join with the background polling thread in |provider_|.
45 void Shutdown(); 50 void Shutdown();
46 51
47 // Injects a custom data fetcher for testing purposes. This class takes 52 // Injects a custom data fetcher for testing purposes. This class takes
48 // ownership of the injected object. 53 // ownership of the injected object.
49 void SetDataFetcherForTesting(DataFetcherSharedMemory* test_data_fetcher); 54 void SetDataFetcherForTesting(DataFetcherSharedMemory* test_data_fetcher);
50 55
51 private: 56 private:
52 friend struct base::DefaultSingletonTraits<DeviceSensorService>; 57 friend struct base::DefaultSingletonTraits<DeviceSensorService>;
53 58
54 DeviceSensorService(); 59 DeviceSensorService();
55 virtual ~DeviceSensorService(); 60 ~DeviceSensorService() override;
56 61
57 bool ChangeNumberConsumers(ConsumerType consumer_type, int delta); 62 bool ChangeNumberConsumers(ConsumerType consumer_type, int delta);
58 int GetNumberConsumers(ConsumerType consumer_type) const; 63 int GetNumberConsumers(ConsumerType consumer_type) const;
59 64
60 int num_light_readers_; 65 int num_light_readers_;
61 int num_motion_readers_; 66 int num_motion_readers_;
62 int num_orientation_readers_; 67 int num_orientation_readers_;
63 int num_orientation_absolute_readers_; 68 int num_orientation_absolute_readers_;
64 bool is_shutdown_; 69 bool is_shutdown_;
65 std::unique_ptr<DataFetcherSharedMemory> data_fetcher_; 70 std::unique_ptr<DataFetcherSharedMemory> data_fetcher_;
66 base::ThreadChecker thread_checker_; 71 base::ThreadChecker thread_checker_;
67 72
68 DISALLOW_COPY_AND_ASSIGN(DeviceSensorService); 73 DISALLOW_COPY_AND_ASSIGN(DeviceSensorService);
69 }; 74 };
70 75
71 } // namespace device 76 } // namespace device
72 77
73 #endif // DEVICE_SENSORS_DEVICE_SENSOR_SERVICE_H_ 78 #endif // DEVICE_SENSORS_DEVICE_SENSOR_SERVICE_H_
OLDNEW
« no previous file with comments | « content/browser/browser_main_loop.cc ('k') | device/sensors/device_sensor_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698