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 DEVICE_GAMEPAD_GAMEPAD_PROVIDER_H_ | 5 #ifndef DEVICE_GAMEPAD_GAMEPAD_PROVIDER_H_ |
6 #define DEVICE_GAMEPAD_GAMEPAD_PROVIDER_H_ | 6 #define DEVICE_GAMEPAD_GAMEPAD_PROVIDER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
17 #include "base/system_monitor/system_monitor.h" | 17 #include "base/system_monitor/system_monitor.h" |
18 #include "device/gamepad/gamepad_export.h" | 18 #include "device/gamepad/gamepad_export.h" |
19 #include "device/gamepad/gamepad_pad_state_provider.h" | 19 #include "device/gamepad/gamepad_pad_state_provider.h" |
20 #include "device/gamepad/gamepad_shared_buffer.h" | 20 #include "device/gamepad/gamepad_shared_buffer.h" |
| 21 #include "device/gamepad/public/cpp/gamepads.h" |
21 #include "mojo/public/cpp/system/buffer.h" | 22 #include "mojo/public/cpp/system/buffer.h" |
22 | 23 |
23 #include "third_party/WebKit/public/platform/WebGamepads.h" | |
24 | |
25 namespace base { | 24 namespace base { |
26 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
27 class Thread; | 26 class Thread; |
28 } | 27 } |
29 | 28 |
30 namespace device { | 29 namespace device { |
31 | 30 |
32 class GamepadDataFetcher; | 31 class GamepadDataFetcher; |
33 | 32 |
34 class DEVICE_GAMEPAD_EXPORT GamepadConnectionChangeClient { | 33 class DEVICE_GAMEPAD_EXPORT GamepadConnectionChangeClient { |
35 public: | 34 public: |
36 virtual void OnGamepadConnectionChange(bool connected, | 35 virtual void OnGamepadConnectionChange(bool connected, |
37 int index, | 36 int index, |
38 const blink::WebGamepad& pad) = 0; | 37 const Gamepad& pad) = 0; |
39 }; | 38 }; |
40 | 39 |
41 class DEVICE_GAMEPAD_EXPORT GamepadProvider | 40 class DEVICE_GAMEPAD_EXPORT GamepadProvider |
42 : public GamepadPadStateProvider, | 41 : public GamepadPadStateProvider, |
43 public base::SystemMonitor::DevicesChangedObserver { | 42 public base::SystemMonitor::DevicesChangedObserver { |
44 public: | 43 public: |
45 explicit GamepadProvider( | 44 explicit GamepadProvider( |
46 GamepadConnectionChangeClient* connection_change_client); | 45 GamepadConnectionChangeClient* connection_change_client); |
47 | 46 |
48 // Manually specifies the data fetcher. Used for testing. | 47 // Manually specifies the data fetcher. Used for testing. |
49 explicit GamepadProvider( | 48 explicit GamepadProvider( |
50 GamepadConnectionChangeClient* connection_change_client, | 49 GamepadConnectionChangeClient* connection_change_client, |
51 std::unique_ptr<GamepadDataFetcher> fetcher); | 50 std::unique_ptr<GamepadDataFetcher> fetcher); |
52 | 51 |
53 ~GamepadProvider() override; | 52 ~GamepadProvider() override; |
54 | 53 |
55 // Returns the shared memory handle of the gamepad data duplicated into the | 54 // Returns the shared memory handle of the gamepad data duplicated into the |
56 // given process. | 55 // given process. |
57 base::SharedMemoryHandle GetSharedMemoryHandleForProcess( | 56 base::SharedMemoryHandle GetSharedMemoryHandleForProcess( |
58 base::ProcessHandle renderer_process); | 57 base::ProcessHandle renderer_process); |
59 | 58 |
60 // Returns a new mojo::ScopedSharedBufferHandle of the gamepad data. | 59 // Returns a new mojo::ScopedSharedBufferHandle of the gamepad data. |
61 mojo::ScopedSharedBufferHandle GetSharedBufferHandle(); | 60 mojo::ScopedSharedBufferHandle GetSharedBufferHandle(); |
62 | 61 |
63 void AddGamepadDataFetcher(GamepadDataFetcher* fetcher); | 62 void AddGamepadDataFetcher(GamepadDataFetcher* fetcher); |
64 void RemoveGamepadDataFetcher(GamepadDataFetcher* fetcher); | 63 void RemoveGamepadDataFetcher(GamepadDataFetcher* fetcher); |
65 | 64 |
66 void GetCurrentGamepadData(blink::WebGamepads* data); | 65 void GetCurrentGamepadData(Gamepads* data); |
67 | 66 |
68 // Pause and resume the background polling thread. Can be called from any | 67 // Pause and resume the background polling thread. Can be called from any |
69 // thread. | 68 // thread. |
70 void Pause(); | 69 void Pause(); |
71 void Resume(); | 70 void Resume(); |
72 | 71 |
73 // Registers the given closure for calling when the user has interacted with | 72 // Registers the given closure for calling when the user has interacted with |
74 // the device. This callback will only be issued once. | 73 // the device. This callback will only be issued once. |
75 void RegisterForUserGesture(const base::Closure& closure); | 74 void RegisterForUserGesture(const base::Closure& closure); |
76 | 75 |
(...skipping 17 matching lines...) Expand all Loading... |
94 void DoRemoveSourceGamepadDataFetcher(GamepadSource source); | 93 void DoRemoveSourceGamepadDataFetcher(GamepadSource source); |
95 | 94 |
96 // Method for sending pause hints to the low-level data fetcher. Runs on | 95 // Method for sending pause hints to the low-level data fetcher. Runs on |
97 // polling_thread_. | 96 // polling_thread_. |
98 void SendPauseHint(bool paused); | 97 void SendPauseHint(bool paused); |
99 | 98 |
100 // Method for polling a GamepadDataFetcher. Runs on the polling_thread_. | 99 // Method for polling a GamepadDataFetcher. Runs on the polling_thread_. |
101 void DoPoll(); | 100 void DoPoll(); |
102 void ScheduleDoPoll(); | 101 void ScheduleDoPoll(); |
103 | 102 |
104 void OnGamepadConnectionChange(bool connected, | 103 void OnGamepadConnectionChange(bool connected, int index, const Gamepad& pad); |
105 int index, | |
106 const blink::WebGamepad& pad); | |
107 | 104 |
108 // Checks the gamepad state to see if the user has interacted with it. | 105 // Checks the gamepad state to see if the user has interacted with it. |
109 void CheckForUserGesture(); | 106 void CheckForUserGesture(); |
110 | 107 |
111 enum { kDesiredSamplingIntervalMs = 16 }; | 108 enum { kDesiredSamplingIntervalMs = 16 }; |
112 | 109 |
113 // Keeps track of when the background thread is paused. Access to is_paused_ | 110 // Keeps track of when the background thread is paused. Access to is_paused_ |
114 // must be guarded by is_paused_lock_. | 111 // must be guarded by is_paused_lock_. |
115 base::Lock is_paused_lock_; | 112 base::Lock is_paused_lock_; |
116 bool is_paused_; | 113 bool is_paused_; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 std::unique_ptr<base::Thread> polling_thread_; | 157 std::unique_ptr<base::Thread> polling_thread_; |
161 | 158 |
162 GamepadConnectionChangeClient* connection_change_client_; | 159 GamepadConnectionChangeClient* connection_change_client_; |
163 | 160 |
164 DISALLOW_COPY_AND_ASSIGN(GamepadProvider); | 161 DISALLOW_COPY_AND_ASSIGN(GamepadProvider); |
165 }; | 162 }; |
166 | 163 |
167 } // namespace device | 164 } // namespace device |
168 | 165 |
169 #endif // DEVICE_GAMEPAD_GAMEPAD_PROVIDER_H_ | 166 #endif // DEVICE_GAMEPAD_GAMEPAD_PROVIDER_H_ |
OLD | NEW |