Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: device/gamepad/gamepad_provider.h

Issue 2081583002: Migrating majority of gamepad from content/browser/ to device/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Android and Unit tests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 DEVICE_GAMEPAD_GAMEPAD_PROVIDER_H_
6 #define CONTENT_BROWSER_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/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 "device/gamepad/gamepad_export.h"
20 #include "device/gamepad/gamepad_shared_buffer.h"
20 #include "third_party/WebKit/public/platform/WebGamepads.h" 21 #include "third_party/WebKit/public/platform/WebGamepads.h"
21 22
22 namespace base { 23 namespace base {
23 class SingleThreadTaskRunner; 24 class SingleThreadTaskRunner;
24 class Thread; 25 class Thread;
25 } 26 }
26 27
27 namespace content { 28 namespace device {
28 29
29 class GamepadDataFetcher; 30 class GamepadDataFetcher;
30 struct GamepadHardwareBuffer;
31 31
32 class CONTENT_EXPORT GamepadProvider : 32 class DEVICE_GAMEPAD_EXPORT GamepadConnectionChangeClient {
33 public base::SystemMonitor::DevicesChangedObserver {
34 public: 33 public:
35 GamepadProvider(); 34 virtual void OnGamepadConnectionChange(bool connected,
35 int index,
36 const blink::WebGamepad& pad) = 0;
37 };
38
39 class DEVICE_GAMEPAD_EXPORT GamepadProvider
40 : public base::SystemMonitor::DevicesChangedObserver {
41 public:
42 explicit GamepadProvider(
43 std::unique_ptr<GamepadSharedBuffer> buffer,
44 GamepadConnectionChangeClient* connection_change_client);
36 45
37 // Manually specifies the data fetcher. Used for testing. 46 // Manually specifies the data fetcher. Used for testing.
38 explicit GamepadProvider(std::unique_ptr<GamepadDataFetcher> fetcher); 47 explicit GamepadProvider(
48 std::unique_ptr<GamepadSharedBuffer> buffer,
49 GamepadConnectionChangeClient* connection_change_client,
50 std::unique_ptr<GamepadDataFetcher> fetcher);
39 51
40 ~GamepadProvider() override; 52 ~GamepadProvider() override;
41 53
42 // 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
43 // given process. 55 // given process.
44 base::SharedMemoryHandle GetSharedMemoryHandleForProcess( 56 base::SharedMemoryHandle GetSharedMemoryHandleForProcess(
45 base::ProcessHandle renderer_process); 57 base::ProcessHandle renderer_process);
46 58
47 void GetCurrentGamepadData(blink::WebGamepads* data); 59 void GetCurrentGamepadData(blink::WebGamepads* data);
48 60
(...skipping 20 matching lines...) Expand all
69 // polling_thread_. 81 // polling_thread_.
70 void SendPauseHint(bool paused); 82 void SendPauseHint(bool paused);
71 83
72 // Method for polling a GamepadDataFetcher. Runs on the polling_thread_. 84 // Method for polling a GamepadDataFetcher. Runs on the polling_thread_.
73 void DoPoll(); 85 void DoPoll();
74 void ScheduleDoPoll(); 86 void ScheduleDoPoll();
75 87
76 void OnGamepadConnectionChange(bool connected, 88 void OnGamepadConnectionChange(bool connected,
77 int index, 89 int index,
78 const blink::WebGamepad& pad); 90 const blink::WebGamepad& pad);
79 void DispatchGamepadConnectionChange(bool connected, 91 /*void DispatchGamepadConnectionChange(bool connected,
80 int index, 92 int index,
81 const blink::WebGamepad& pad); 93 const blink::WebGamepad& pad);*/
82 94
83 GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer(); 95 // GamepadHardwareBuffer* SharedMemoryAsHardwareBuffer();
84 96
85 // Checks the gamepad state to see if the user has interacted with it. 97 // Checks the gamepad state to see if the user has interacted with it.
86 void CheckForUserGesture(); 98 void CheckForUserGesture();
87 99
88 enum { kDesiredSamplingIntervalMs = 16 }; 100 enum { kDesiredSamplingIntervalMs = 16 };
89 101
90 // Keeps track of when the background thread is paused. Access to is_paused_ 102 // Keeps track of when the background thread is paused. Access to is_paused_
91 // must be guarded by is_paused_lock_. 103 // must be guarded by is_paused_lock_.
92 base::Lock is_paused_lock_; 104 base::Lock is_paused_lock_;
93 bool is_paused_; 105 bool is_paused_;
(...skipping 26 matching lines...) Expand all
120 // to enable it to avoid redundant (and possibly expensive) is-connected 132 // to enable it to avoid redundant (and possibly expensive) is-connected
121 // tests. Access to devices_changed_ must be guarded by 133 // tests. Access to devices_changed_ must be guarded by
122 // devices_changed_lock_. 134 // devices_changed_lock_.
123 base::Lock devices_changed_lock_; 135 base::Lock devices_changed_lock_;
124 bool devices_changed_; 136 bool devices_changed_;
125 137
126 bool ever_had_user_gesture_; 138 bool ever_had_user_gesture_;
127 139
128 class PadState { 140 class PadState {
129 public: 141 public:
130 PadState() { 142 PadState() { SetDisconnected(); }
131 SetDisconnected();
132 }
133 143
134 bool Match(const blink::WebGamepad& pad) const; 144 bool Match(const blink::WebGamepad& pad) const;
135 void SetPad(const blink::WebGamepad& pad); 145 void SetPad(const blink::WebGamepad& pad);
136 void SetDisconnected(); 146 void SetDisconnected();
137 void AsWebGamepad(blink::WebGamepad* pad); 147 void AsWebGamepad(blink::WebGamepad* pad);
138 148
139 bool connected() const { return connected_; } 149 bool connected() const { return connected_; }
140 150
141 private: 151 private:
142 bool connected_; 152 bool connected_;
143 unsigned axes_length_; 153 unsigned axes_length_;
144 unsigned buttons_length_; 154 unsigned buttons_length_;
145 blink::WebUChar id_[blink::WebGamepad::idLengthCap]; 155 blink::WebUChar id_[blink::WebGamepad::idLengthCap];
146 blink::WebUChar mapping_[blink::WebGamepad::mappingLengthCap]; 156 blink::WebUChar mapping_[blink::WebGamepad::mappingLengthCap];
147 }; 157 };
148 158
149 // Used to detect connections and disconnections. 159 // Used to detect connections and disconnections.
150 std::unique_ptr<PadState[]> pad_states_; 160 std::unique_ptr<PadState[]> pad_states_;
151 161
152 // Only used on the polling thread. 162 // Only used on the polling thread.
153 std::unique_ptr<GamepadDataFetcher> data_fetcher_; 163 std::unique_ptr<GamepadDataFetcher> data_fetcher_;
154 164
155 base::Lock shared_memory_lock_; 165 base::Lock shared_memory_lock_;
156 base::SharedMemory gamepad_shared_memory_; 166 // base::SharedMemory gamepad_shared_memory_;
scottmg 2016/06/23 17:27:19 ?
167 std::unique_ptr<GamepadSharedBuffer> gamepad_shared_buffer_;
157 168
158 // Polling is done on this background thread. 169 // Polling is done on this background thread.
159 std::unique_ptr<base::Thread> polling_thread_; 170 std::unique_ptr<base::Thread> polling_thread_;
160 171
172 GamepadConnectionChangeClient* connection_change_client_;
173
161 static GamepadProvider* instance_; 174 static GamepadProvider* instance_;
162 175
163 DISALLOW_COPY_AND_ASSIGN(GamepadProvider); 176 DISALLOW_COPY_AND_ASSIGN(GamepadProvider);
164 }; 177 };
165 178
166 } // namespace content 179 } // namespace device
167 180
168 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PROVIDER_H_ 181 #endif // DEVICE_GAMEPAD_GAMEPAD_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698