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