OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_RENDERER_GAMEPAD_SHARED_MEMORY_READER_H_ | 5 #ifndef CONTENT_RENDERER_GAMEPAD_SHARED_MEMORY_READER_H_ |
6 #define CONTENT_RENDERER_GAMEPAD_SHARED_MEMORY_READER_H_ | 6 #define CONTENT_RENDERER_GAMEPAD_SHARED_MEMORY_READER_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/gamepad_messages.h" |
| 11 #include "ipc/ipc_channel_proxy.h" |
10 #include "third_party/WebKit/public/platform/WebGamepads.h" | 12 #include "third_party/WebKit/public/platform/WebGamepads.h" |
11 | 13 |
| 14 namespace blink { class WebGamepadListener; } |
| 15 |
12 namespace content { | 16 namespace content { |
13 | 17 |
14 struct GamepadHardwareBuffer; | 18 struct GamepadHardwareBuffer; |
15 | 19 |
16 class GamepadSharedMemoryReader { | 20 class GamepadSharedMemoryReader : public IPC::ChannelProxy::MessageFilter { |
17 public: | 21 public: |
18 GamepadSharedMemoryReader(); | 22 GamepadSharedMemoryReader( |
| 23 const scoped_refptr<base::MessageLoopProxy>& io_message_loop); |
| 24 void SampleGamepads(blink::WebGamepads&); |
| 25 void SetGamepadListener(blink::WebGamepadListener* listener); |
| 26 |
| 27 protected: |
19 virtual ~GamepadSharedMemoryReader(); | 28 virtual ~GamepadSharedMemoryReader(); |
20 void SampleGamepads(blink::WebGamepads&); | |
21 | 29 |
22 private: | 30 private: |
| 31 bool StartPollingIfNecessary(); |
| 32 void StopPollingIfNecessary(); |
| 33 |
| 34 // IPC::ChannelProxy::MessageFilter override. Called on |io_message_loop|. |
| 35 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 36 |
| 37 // Called when a gamepad is connected to the system |
| 38 void OnGamepadConnected(const GamepadConnectionEventMessageParams& params); |
| 39 |
| 40 // Called when a gamepad is disconnected from the system |
| 41 void OnGamepadDisconnected(const GamepadConnectionEventMessageParams& params); |
| 42 |
| 43 void DispatchGamepadConnected(int index, const blink::WebGamepad& gamepad); |
| 44 void DispatchGamepadDisconnected(int index, const blink::WebGamepad& gamepad); |
| 45 |
| 46 // Message loop on which IPC calls are driven. |
| 47 const scoped_refptr<base::MessageLoopProxy> io_message_loop_; |
| 48 |
| 49 // Main thread's message loop. |
| 50 scoped_refptr<base::MessageLoopProxy> main_message_loop_; |
| 51 |
23 base::SharedMemoryHandle renderer_shared_memory_handle_; | 52 base::SharedMemoryHandle renderer_shared_memory_handle_; |
24 scoped_ptr<base::SharedMemory> renderer_shared_memory_; | 53 scoped_ptr<base::SharedMemory> renderer_shared_memory_; |
25 GamepadHardwareBuffer* gamepad_hardware_buffer_; | 54 GamepadHardwareBuffer* gamepad_hardware_buffer_; |
| 55 blink::WebGamepadListener* gamepad_listener_; |
26 | 56 |
| 57 bool is_polling_; |
27 bool ever_interacted_with_; | 58 bool ever_interacted_with_; |
28 }; | 59 }; |
29 | 60 |
30 } // namespace content | 61 } // namespace content |
31 | 62 |
32 #endif // CONTENT_RENDERER_GAMEPAD_SHARED_MEMORY_READER_H_ | 63 #endif // CONTENT_RENDERER_GAMEPAD_SHARED_MEMORY_READER_H_ |
OLD | NEW |