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 <memory> |
8 #include <utility> | 9 #include <utility> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "base/system_monitor/system_monitor.h" | 18 #include "base/system_monitor/system_monitor.h" |
19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
20 #include "third_party/WebKit/public/platform/WebGamepads.h" | 20 #include "third_party/WebKit/public/platform/WebGamepads.h" |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 class SingleThreadTaskRunner; | 23 class SingleThreadTaskRunner; |
24 class Thread; | 24 class Thread; |
25 } | 25 } |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 | 28 |
29 class GamepadDataFetcher; | 29 class GamepadDataFetcher; |
30 struct GamepadHardwareBuffer; | 30 struct GamepadHardwareBuffer; |
31 | 31 |
32 class CONTENT_EXPORT GamepadProvider : | 32 class CONTENT_EXPORT GamepadProvider : |
33 public base::SystemMonitor::DevicesChangedObserver { | 33 public base::SystemMonitor::DevicesChangedObserver { |
34 public: | 34 public: |
35 GamepadProvider(); | 35 GamepadProvider(); |
36 | 36 |
37 // Manually specifies the data fetcher. Used for testing. | 37 // Manually specifies the data fetcher. Used for testing. |
38 explicit GamepadProvider(scoped_ptr<GamepadDataFetcher> fetcher); | 38 explicit GamepadProvider(std::unique_ptr<GamepadDataFetcher> fetcher); |
39 | 39 |
40 ~GamepadProvider() override; | 40 ~GamepadProvider() override; |
41 | 41 |
42 // Returns the shared memory handle of the gamepad data duplicated into the | 42 // Returns the shared memory handle of the gamepad data duplicated into the |
43 // given process. | 43 // given process. |
44 base::SharedMemoryHandle GetSharedMemoryHandleForProcess( | 44 base::SharedMemoryHandle GetSharedMemoryHandleForProcess( |
45 base::ProcessHandle renderer_process); | 45 base::ProcessHandle renderer_process); |
46 | 46 |
47 void GetCurrentGamepadData(blink::WebGamepads* data); | 47 void GetCurrentGamepadData(blink::WebGamepads* data); |
48 | 48 |
49 // Pause and resume the background polling thread. Can be called from any | 49 // Pause and resume the background polling thread. Can be called from any |
50 // thread. | 50 // thread. |
51 void Pause(); | 51 void Pause(); |
52 void Resume(); | 52 void Resume(); |
53 | 53 |
54 // Registers the given closure for calling when the user has interacted with | 54 // Registers the given closure for calling when the user has interacted with |
55 // the device. This callback will only be issued once. | 55 // the device. This callback will only be issued once. |
56 void RegisterForUserGesture(const base::Closure& closure); | 56 void RegisterForUserGesture(const base::Closure& closure); |
57 | 57 |
58 // base::SystemMonitor::DevicesChangedObserver implementation. | 58 // base::SystemMonitor::DevicesChangedObserver implementation. |
59 void OnDevicesChanged(base::SystemMonitor::DeviceType type) override; | 59 void OnDevicesChanged(base::SystemMonitor::DeviceType type) override; |
60 | 60 |
61 private: | 61 private: |
62 void Initialize(scoped_ptr<GamepadDataFetcher> fetcher); | 62 void Initialize(std::unique_ptr<GamepadDataFetcher> fetcher); |
63 | 63 |
64 // Method for setting up the platform-specific data fetcher. Takes ownership | 64 // Method for setting up the platform-specific data fetcher. Takes ownership |
65 // of |fetcher|. | 65 // of |fetcher|. |
66 void DoInitializePollingThread(scoped_ptr<GamepadDataFetcher> fetcher); | 66 void DoInitializePollingThread(std::unique_ptr<GamepadDataFetcher> fetcher); |
67 | 67 |
68 // Method for sending pause hints to the low-level data fetcher. Runs on | 68 // Method for sending pause hints to the low-level data fetcher. Runs on |
69 // polling_thread_. | 69 // polling_thread_. |
70 void SendPauseHint(bool paused); | 70 void SendPauseHint(bool paused); |
71 | 71 |
72 // Method for polling a GamepadDataFetcher. Runs on the polling_thread_. | 72 // Method for polling a GamepadDataFetcher. Runs on the polling_thread_. |
73 void DoPoll(); | 73 void DoPoll(); |
74 void ScheduleDoPoll(); | 74 void ScheduleDoPoll(); |
75 | 75 |
76 void OnGamepadConnectionChange(bool connected, | 76 void OnGamepadConnectionChange(bool connected, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 140 |
141 private: | 141 private: |
142 bool connected_; | 142 bool connected_; |
143 unsigned axes_length_; | 143 unsigned axes_length_; |
144 unsigned buttons_length_; | 144 unsigned buttons_length_; |
145 blink::WebUChar id_[blink::WebGamepad::idLengthCap]; | 145 blink::WebUChar id_[blink::WebGamepad::idLengthCap]; |
146 blink::WebUChar mapping_[blink::WebGamepad::mappingLengthCap]; | 146 blink::WebUChar mapping_[blink::WebGamepad::mappingLengthCap]; |
147 }; | 147 }; |
148 | 148 |
149 // Used to detect connections and disconnections. | 149 // Used to detect connections and disconnections. |
150 scoped_ptr<PadState[]> pad_states_; | 150 std::unique_ptr<PadState[]> pad_states_; |
151 | 151 |
152 // Only used on the polling thread. | 152 // Only used on the polling thread. |
153 scoped_ptr<GamepadDataFetcher> data_fetcher_; | 153 std::unique_ptr<GamepadDataFetcher> data_fetcher_; |
154 | 154 |
155 base::Lock shared_memory_lock_; | 155 base::Lock shared_memory_lock_; |
156 base::SharedMemory gamepad_shared_memory_; | 156 base::SharedMemory gamepad_shared_memory_; |
157 | 157 |
158 // Polling is done on this background thread. | 158 // Polling is done on this background thread. |
159 scoped_ptr<base::Thread> polling_thread_; | 159 std::unique_ptr<base::Thread> polling_thread_; |
160 | 160 |
161 static GamepadProvider* instance_; | 161 static GamepadProvider* instance_; |
162 | 162 |
163 DISALLOW_COPY_AND_ASSIGN(GamepadProvider); | 163 DISALLOW_COPY_AND_ASSIGN(GamepadProvider); |
164 }; | 164 }; |
165 | 165 |
166 } // namespace content | 166 } // namespace content |
167 | 167 |
168 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PROVIDER_H_ | 168 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PROVIDER_H_ |
OLD | NEW |