OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_ORIENTATION_DEVICE_MOTION_PROVIDER_H_ | 5 #ifndef CONTENT_BROWSER_DEVICE_ORIENTATION_DEVICE_MOTION_PROVIDER_H_ |
6 #define CONTENT_BROWSER_DEVICE_ORIENTATION_DEVICE_MOTION_PROVIDER_H_ | 6 #define CONTENT_BROWSER_DEVICE_ORIENTATION_DEVICE_MOTION_PROVIDER_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
11 #include "content/common/device_motion_hardware_buffer.h" | 11 #include "content/common/device_motion_hardware_buffer.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 class DataFetcherSharedMemory; | 14 class DataFetcherSharedMemory; |
15 | 15 |
| 16 // This class owns the shared memory buffer for Device Motion and makes |
| 17 // sure the data is fetched into that buffer. |
| 18 // When DataFetcherSharedMemory::NeedsPolling() is true, it starts a |
| 19 // background polling thread to make sure the data is fetched at regular |
| 20 // intervals. |
16 class CONTENT_EXPORT DeviceMotionProvider { | 21 class CONTENT_EXPORT DeviceMotionProvider { |
17 public: | 22 public: |
18 DeviceMotionProvider(); | 23 DeviceMotionProvider(); |
| 24 |
| 25 // Creates provider with a custom fetcher. Used for testing. |
| 26 explicit DeviceMotionProvider(scoped_ptr<DataFetcherSharedMemory> fetcher); |
| 27 |
19 virtual ~DeviceMotionProvider(); | 28 virtual ~DeviceMotionProvider(); |
20 | 29 |
21 // Returns the shared memory handle of the device motion data duplicated | 30 // Returns the shared memory handle of the device motion data duplicated |
22 // into the given process. | 31 // into the given process. |
23 base::SharedMemoryHandle GetSharedMemoryHandleForProcess( | 32 base::SharedMemoryHandle GetSharedMemoryHandleForProcess( |
24 base::ProcessHandle renderer_process); | 33 base::ProcessHandle renderer_process); |
25 | 34 |
26 // Pause and resume the background polling thread. Can be called from any | |
27 // thread. | |
28 void StartFetchingDeviceMotionData(); | 35 void StartFetchingDeviceMotionData(); |
29 void StopFetchingDeviceMotionData(); | 36 void StopFetchingDeviceMotionData(); |
30 | 37 |
31 private: | 38 private: |
32 base::SharedMemory device_motion_shared_memory_; | 39 class PollingThread; |
| 40 |
| 41 void Initialize(); |
| 42 void CreateAndStartPollingThread(); |
33 | 43 |
34 DeviceMotionHardwareBuffer* SharedMemoryAsHardwareBuffer(); | 44 DeviceMotionHardwareBuffer* SharedMemoryAsHardwareBuffer(); |
35 | 45 |
| 46 base::SharedMemory device_motion_shared_memory_; |
36 scoped_ptr<DataFetcherSharedMemory> data_fetcher_; | 47 scoped_ptr<DataFetcherSharedMemory> data_fetcher_; |
37 | 48 scoped_ptr<PollingThread> polling_thread_; |
38 bool is_started_; | 49 bool is_started_; |
39 | 50 |
40 DISALLOW_COPY_AND_ASSIGN(DeviceMotionProvider); | 51 DISALLOW_COPY_AND_ASSIGN(DeviceMotionProvider); |
41 }; | 52 }; |
42 | 53 |
43 } // namespace content | 54 } // namespace content |
44 | 55 |
45 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_DEVICE_MOTION_PROVIDER_H_ | 56 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_DEVICE_MOTION_PROVIDER_H_ |
OLD | NEW |