| 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 explicit DeviceMotionProvider(scoped_ptr<DataFetcherSharedMemory> fetcher); |
| 25 |
| 19 virtual ~DeviceMotionProvider(); | 26 virtual ~DeviceMotionProvider(); |
| 20 | 27 |
| 21 // Returns the shared memory handle of the device motion data duplicated | 28 // Returns the shared memory handle of the device motion data duplicated |
| 22 // into the given process. | 29 // into the given process. |
| 23 base::SharedMemoryHandle GetSharedMemoryHandleForProcess( | 30 base::SharedMemoryHandle GetSharedMemoryHandleForProcess( |
| 24 base::ProcessHandle renderer_process); | 31 base::ProcessHandle renderer_process); |
| 25 | 32 |
| 26 // Pause and resume the background polling thread. Can be called from any | |
| 27 // thread. | |
| 28 void StartFetchingDeviceMotionData(); | 33 void StartFetchingDeviceMotionData(); |
| 29 void StopFetchingDeviceMotionData(); | 34 void StopFetchingDeviceMotionData(); |
| 30 | 35 |
| 31 private: | 36 private: |
| 32 base::SharedMemory device_motion_shared_memory_; | 37 class PollingThread; |
| 38 |
| 39 void Initialize(); |
| 40 void CreateAndStartPollingThread(); |
| 33 | 41 |
| 34 DeviceMotionHardwareBuffer* SharedMemoryAsHardwareBuffer(); | 42 DeviceMotionHardwareBuffer* SharedMemoryAsHardwareBuffer(); |
| 35 | 43 |
| 44 base::SharedMemory device_motion_shared_memory_; |
| 36 scoped_ptr<DataFetcherSharedMemory> data_fetcher_; | 45 scoped_ptr<DataFetcherSharedMemory> data_fetcher_; |
| 37 | 46 scoped_ptr<PollingThread> polling_thread_; |
| 38 bool is_started_; | 47 bool is_stopped_or_stopping_; |
| 39 | 48 |
| 40 DISALLOW_COPY_AND_ASSIGN(DeviceMotionProvider); | 49 DISALLOW_COPY_AND_ASSIGN(DeviceMotionProvider); |
| 41 }; | 50 }; |
| 42 | 51 |
| 43 } // namespace content | 52 } // namespace content |
| 44 | 53 |
| 45 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_DEVICE_MOTION_PROVIDER_H_ | 54 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_DEVICE_MOTION_PROVIDER_H_ |
| OLD | NEW |