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

Side by Side Diff: content/browser/device_sensors/device_sensor_service.h

Issue 2646093002: Move //content/browser/device_sensor/ into device/sensors (Closed)
Patch Set: gn format & code rebase Created 3 years, 10 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_SENSOR_SERVICE_H_
6 #define CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_SENSOR_SERVICE_H_
7
8 #include <memory>
9
10 #include "base/callback_forward.h"
11 #include "base/macros.h"
12 #include "base/memory/shared_memory.h"
13 #include "base/memory/singleton.h"
14 #include "base/threading/thread_checker.h"
15 #include "content/browser/device_sensors/device_sensors_consts.h"
16 #include "content/common/content_export.h"
17 #include "mojo/public/cpp/system/buffer.h"
18
19 namespace content {
20
21 class DataFetcherSharedMemory;
22
23 // 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 // when there are no consumers.
26 class CONTENT_EXPORT DeviceSensorService {
27 public:
28 // Returns the DeviceSensorService singleton.
29 static DeviceSensorService* GetInstance();
30
31 // 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.
33 // Must be called on the I/O thread.
34 void AddConsumer(ConsumerType consumer_type);
35
36 // Removes a consumer. Should be matched with an AddConsumer call.
37 // Must be called on the I/O thread.
38 void RemoveConsumer(ConsumerType cosumer_type);
39
40 // Returns the shared memory handle of the device motion data.
41 mojo::ScopedSharedBufferHandle GetSharedMemoryHandle(
42 ConsumerType consumer_type);
43
44 // Stop/join with the background polling thread in |provider_|.
45 void Shutdown();
46
47 // Injects a custom data fetcher for testing purposes. This class takes
48 // ownership of the injected object.
49 void SetDataFetcherForTesting(DataFetcherSharedMemory* test_data_fetcher);
50
51 private:
52 friend struct base::DefaultSingletonTraits<DeviceSensorService>;
53
54 DeviceSensorService();
55 virtual ~DeviceSensorService();
56
57 bool ChangeNumberConsumers(ConsumerType consumer_type, int delta);
58 int GetNumberConsumers(ConsumerType consumer_type) const;
59
60 int num_light_readers_;
61 int num_motion_readers_;
62 int num_orientation_readers_;
63 int num_orientation_absolute_readers_;
64 bool is_shutdown_;
65 std::unique_ptr<DataFetcherSharedMemory> data_fetcher_;
66 base::ThreadChecker thread_checker_;
67
68 DISALLOW_COPY_AND_ASSIGN(DeviceSensorService);
69 };
70
71 } // namespace content
72
73 #endif // CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_SENSOR_SERVICE_H_
OLDNEW
« no previous file with comments | « content/browser/device_sensors/device_sensor_host.cc ('k') | content/browser/device_sensors/device_sensor_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698