| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_GAMEPAD_GAMEPAD_PROVIDER_H_ | 5 #ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_PROVIDER_H_ |
| 6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_PROVIDER_H_ | 6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_PROVIDER_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 #include "base/shared_memory.h" | 11 #include "base/shared_memory.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "base/system_monitor/system_monitor.h" | 13 #include "base/system_monitor/system_monitor.h" |
| 14 #include "content/browser/gamepad/data_fetcher.h" | |
| 15 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 16 #include "content/common/gamepad_hardware_buffer.h" | |
| 17 | 15 |
| 18 namespace base { | 16 namespace base { |
| 19 class Thread; | 17 class Thread; |
| 20 } | 18 } |
| 21 | 19 |
| 22 struct GamepadMsg_Updated_Params; | |
| 23 | |
| 24 namespace content { | 20 namespace content { |
| 25 | 21 |
| 22 class GamepadDataFetcher; |
| 23 struct GamepadHardwareBuffer; |
| 24 |
| 26 class CONTENT_EXPORT GamepadProvider : | 25 class CONTENT_EXPORT GamepadProvider : |
| 27 public base::RefCountedThreadSafe<GamepadProvider>, | 26 public base::RefCountedThreadSafe<GamepadProvider>, |
| 28 public base::SystemMonitor::DevicesChangedObserver { | 27 public base::SystemMonitor::DevicesChangedObserver { |
| 29 public: | 28 public: |
| 30 explicit GamepadProvider(GamepadDataFetcher* fetcher); | 29 explicit GamepadProvider(GamepadDataFetcher* fetcher); |
| 31 | 30 |
| 32 base::SharedMemoryHandle GetRendererSharedMemoryHandle( | 31 base::SharedMemoryHandle GetRendererSharedMemoryHandle( |
| 33 base::ProcessHandle renderer_process); | 32 base::ProcessHandle renderer_process); |
| 34 | 33 |
| 35 // Pause and resume the background polling thread. Can be called from any | 34 // Pause and resume the background polling thread. Can be called from any |
| 36 // thread. | 35 // thread. |
| 37 void Pause(); | 36 void Pause(); |
| 38 void Resume(); | 37 void Resume(); |
| 39 | 38 |
| 39 // base::SystemMonitor::DevicesChangedObserver implementation. |
| 40 virtual void OnDevicesChanged() OVERRIDE; |
| 41 |
| 40 private: | 42 private: |
| 41 friend class base::RefCountedThreadSafe<GamepadProvider>; | 43 friend class base::RefCountedThreadSafe<GamepadProvider>; |
| 42 | 44 |
| 43 virtual ~GamepadProvider(); | 45 virtual ~GamepadProvider(); |
| 44 | 46 |
| 45 // Method for starting the polling, runs on polling_thread_. | 47 // Method for starting the polling, runs on polling_thread_. |
| 46 void DoInitializePollingThread(); | 48 void DoInitializePollingThread(); |
| 47 | 49 |
| 48 // Method for polling a GamepadDataFetcher. Runs on the polling_thread_. | 50 // Method for polling a GamepadDataFetcher. Runs on the polling_thread_. |
| 49 void DoPoll(); | 51 void DoPoll(); |
| 50 void ScheduleDoPoll(); | 52 void ScheduleDoPoll(); |
| 51 | 53 |
| 52 virtual void OnDevicesChanged() OVERRIDE; | |
| 53 | |
| 54 GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer(); | 54 GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer(); |
| 55 | 55 |
| 56 enum { kDesiredSamplingIntervalMs = 16 }; | 56 enum { kDesiredSamplingIntervalMs = 16 }; |
| 57 | 57 |
| 58 // Keeps track of when the background thread is paused. Access to is_paused_ | 58 // Keeps track of when the background thread is paused. Access to is_paused_ |
| 59 // must be guarded by is_paused_lock_. | 59 // must be guarded by is_paused_lock_. |
| 60 base::Lock is_paused_lock_; | 60 base::Lock is_paused_lock_; |
| 61 bool is_paused_; | 61 bool is_paused_; |
| 62 | 62 |
| 63 // Updated based on notification from SystemMonitor when the system devices | 63 // Updated based on notification from SystemMonitor when the system devices |
| (...skipping 18 matching lines...) Expand all Loading... |
| 82 | 82 |
| 83 static GamepadProvider* instance_; | 83 static GamepadProvider* instance_; |
| 84 base::WeakPtrFactory<GamepadProvider> weak_factory_; | 84 base::WeakPtrFactory<GamepadProvider> weak_factory_; |
| 85 | 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(GamepadProvider); | 86 DISALLOW_COPY_AND_ASSIGN(GamepadProvider); |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 } // namespace content | 89 } // namespace content |
| 90 | 90 |
| 91 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PROVIDER_H_ | 91 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PROVIDER_H_ |
| OLD | NEW |