OLD | NEW |
---|---|
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 CONTENT_BROWSER_DEVICE_SENSORS_DATA_FETCHER_SHARED_MEMORY_BASE_H_ | 5 #ifndef CONTENT_BROWSER_DEVICE_SENSORS_DATA_FETCHER_SHARED_MEMORY_BASE_H_ |
6 #define CONTENT_BROWSER_DEVICE_SENSORS_DATA_FETCHER_SHARED_MEMORY_BASE_H_ | 6 #define CONTENT_BROWSER_DEVICE_SENSORS_DATA_FETCHER_SHARED_MEMORY_BASE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
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/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "content/browser/device_sensors/device_sensors_consts.h" | 14 #include "content/browser/device_sensors/device_sensors_consts.h" |
15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
16 #include "mojo/public/cpp/system/buffer.h" | |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 // Sensor data fetchers should derive from this base class and implement | 20 // Sensor data fetchers should derive from this base class and implement |
20 // the abstract Start() and Stop() methods. | 21 // the abstract Start() and Stop() methods. |
21 // If the fetcher requires polling it should also implement IsPolling() | 22 // If the fetcher requires polling it should also implement IsPolling() |
22 // to return true and the Fetch() method which will be called from the | 23 // to return true and the Fetch() method which will be called from the |
23 // polling thread to fetch data at regular intervals. | 24 // polling thread to fetch data at regular intervals. |
24 class CONTENT_EXPORT DataFetcherSharedMemoryBase { | 25 class CONTENT_EXPORT DataFetcherSharedMemoryBase { |
25 public: | 26 public: |
26 // Starts updating the shared memory buffer with sensor data at | 27 // Starts updating the shared memory buffer with sensor data at |
27 // regular intervals. Returns true if the relevant sensors could | 28 // regular intervals. Returns true if the relevant sensors could |
28 // be successfully activated. | 29 // be successfully activated. |
29 bool StartFetchingDeviceData(ConsumerType consumer_type); | 30 bool StartFetchingDeviceData(ConsumerType consumer_type); |
30 | 31 |
31 // Stops updating the shared memory buffer. Returns true if the | 32 // Stops updating the shared memory buffer. Returns true if the |
32 // relevant sensors could be successfully deactivated. | 33 // relevant sensors could be successfully deactivated. |
33 bool StopFetchingDeviceData(ConsumerType consumer_type); | 34 bool StopFetchingDeviceData(ConsumerType consumer_type); |
34 | 35 |
35 // Should be called before destruction to make sure all active | 36 // Should be called before destruction to make sure all active |
36 // sensors are unregistered. | 37 // sensors are unregistered. |
37 virtual void Shutdown(); | 38 virtual void Shutdown(); |
38 | 39 |
39 // Returns the shared memory handle of the device sensor data | 40 // Returns the shared memory handle of the device sensor data. This method |
40 // duplicated into the given process. This method should only be | 41 // should only be called after a call to StartFetchingDeviceData method with |
41 // called after a call to StartFetchingDeviceData method with | |
42 // corresponding |consumer_type| parameter. | 42 // corresponding |consumer_type| parameter. |
43 base::SharedMemoryHandle GetSharedMemoryHandleForProcess( | 43 mojo::ScopedSharedBufferHandle GetSharedMemoryHandle( |
44 ConsumerType consumer_type, base::ProcessHandle process); | 44 ConsumerType consumer_type); |
45 | 45 |
46 enum FetcherType { | 46 enum FetcherType { |
47 // Fetcher runs on the same thread as its creator. | 47 // Fetcher runs on the same thread as its creator. |
48 FETCHER_TYPE_DEFAULT, | 48 FETCHER_TYPE_DEFAULT, |
49 // Fetcher runs on a separate thread calling |Fetch()| at regular intervals. | 49 // Fetcher runs on a separate thread calling |Fetch()| at regular intervals. |
50 FETCHER_TYPE_POLLING_CALLBACK, | 50 FETCHER_TYPE_POLLING_CALLBACK, |
51 // Fetcher runs on a separate thread, but no callbacks are executed. | 51 // Fetcher runs on a separate thread, but no callbacks are executed. |
52 FETCHER_TYPE_SEPARATE_THREAD | 52 FETCHER_TYPE_SEPARATE_THREAD |
53 }; | 53 }; |
54 | 54 |
(...skipping 29 matching lines...) Expand all Loading... | |
84 | 84 |
85 private: | 85 private: |
86 bool InitAndStartPollingThreadIfNecessary(); | 86 bool InitAndStartPollingThreadIfNecessary(); |
87 base::SharedMemory* GetSharedMemory(ConsumerType consumer_type); | 87 base::SharedMemory* GetSharedMemory(ConsumerType consumer_type); |
88 void* GetSharedMemoryBuffer(ConsumerType consumer_type); | 88 void* GetSharedMemoryBuffer(ConsumerType consumer_type); |
89 | 89 |
90 unsigned started_consumers_; | 90 unsigned started_consumers_; |
91 | 91 |
92 std::unique_ptr<PollingThread> polling_thread_; | 92 std::unique_ptr<PollingThread> polling_thread_; |
93 | 93 |
94 // Owning pointers. Objects in the map are deleted in dtor. | 94 typedef std::map<ConsumerType, |
95 typedef std::map<ConsumerType, base::SharedMemory*> SharedMemoryMap; | 95 std::pair<mojo::ScopedSharedBufferHandle, |
96 mojo::ScopedSharedBufferMapping>> | |
97 SharedMemoryMap; | |
dcheng
2016/07/04 03:39:49
Nit: since we're changing this, let's update it to
Sam McNally
2016/07/04 08:31:38
Done.
| |
96 SharedMemoryMap shared_memory_map_; | 98 SharedMemoryMap shared_memory_map_; |
97 | 99 |
98 DISALLOW_COPY_AND_ASSIGN(DataFetcherSharedMemoryBase); | 100 DISALLOW_COPY_AND_ASSIGN(DataFetcherSharedMemoryBase); |
99 }; | 101 }; |
100 | 102 |
101 } // namespace content | 103 } // namespace content |
102 | 104 |
103 #endif // CONTENT_BROWSER_DEVICE_SENSORS_DATA_FETCHER_SHARED_MEMORY_BASE_H_ | 105 #endif // CONTENT_BROWSER_DEVICE_SENSORS_DATA_FETCHER_SHARED_MEMORY_BASE_H_ |
OLD | NEW |