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 #include "content/renderer/gamepad_shared_memory_reader.h" | 5 #include "content/renderer/gamepad_shared_memory_reader.h" |
6 | 6 |
7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "content/common/gamepad_hardware_buffer.h" | 9 #include "content/common/gamepad_hardware_buffer.h" |
10 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
11 #include "content/renderer/renderer_blink_platform_impl.h" | 11 #include "content/renderer/renderer_blink_platform_impl.h" |
12 #include "ipc/ipc_sync_message_filter.h" | 12 #include "ipc/ipc_sync_message_filter.h" |
13 #include "services/service_manager/public/cpp/interface_provider.h" | |
13 #include "third_party/WebKit/public/platform/WebGamepadListener.h" | 14 #include "third_party/WebKit/public/platform/WebGamepadListener.h" |
14 #include "third_party/WebKit/public/platform/WebPlatformEventListener.h" | 15 #include "third_party/WebKit/public/platform/WebPlatformEventListener.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 GamepadSharedMemoryReader::GamepadSharedMemoryReader(RenderThread* thread) | 19 GamepadSharedMemoryReader::GamepadSharedMemoryReader(RenderThread* thread) |
19 : RendererGamepadProvider(thread), | 20 : RendererGamepadProvider(thread), |
20 gamepad_hardware_buffer_(NULL), | 21 gamepad_hardware_buffer_(NULL), |
21 ever_interacted_with_(false) { | 22 ever_interacted_with_(false), |
23 binding_(this) { | |
24 if (thread) { | |
25 thread->GetRemoteInterfaces()->GetInterface( | |
26 mojo::GetProxy(&gamepad_monitor_)); | |
27 gamepad_monitor_->SetObserver(binding_.CreateInterfacePtrAndBind()); | |
28 } | |
22 } | 29 } |
23 | 30 |
24 void GamepadSharedMemoryReader::SendStartMessage() { | 31 void GamepadSharedMemoryReader::SendStartMessage() { |
25 CHECK(RenderThread::Get()->Send(new GamepadHostMsg_StartPolling( | 32 if (gamepad_monitor_) { |
26 &renderer_shared_memory_handle_))); | 33 mojo::ScopedSharedBufferHandle buffer_handle; |
34 gamepad_monitor_->GamepadStartPolling(&buffer_handle); | |
35 MojoResult result = mojo::UnwrapSharedMemoryHandle( | |
blundell
2016/12/06 12:26:50
Can you add a TODO and bug for moving the renderer
ke.he
2016/12/07 08:05:10
Yes. we can do it independently in GamepadSharedMe
| |
36 std::move(buffer_handle), &renderer_shared_memory_handle_, nullptr, | |
37 nullptr); | |
38 DCHECK_EQ(MOJO_RESULT_OK, result); | |
blundell
2016/12/06 12:26:50
This should be CHECK_EQ to keep the intent of line
ke.he
2016/12/07 08:05:10
Done.
| |
39 } | |
27 } | 40 } |
28 | 41 |
29 void GamepadSharedMemoryReader::SendStopMessage() { | 42 void GamepadSharedMemoryReader::SendStopMessage() { |
30 RenderThread::Get()->Send(new GamepadHostMsg_StopPolling()); | 43 if (gamepad_monitor_) { |
44 gamepad_monitor_->GamepadStopPolling(); | |
45 } | |
31 } | 46 } |
32 | 47 |
33 void GamepadSharedMemoryReader::Start( | 48 void GamepadSharedMemoryReader::Start( |
34 blink::WebPlatformEventListener* listener) { | 49 blink::WebPlatformEventListener* listener) { |
35 PlatformEventObserver::Start(listener); | 50 PlatformEventObserver::Start(listener); |
36 | 51 |
37 // If we don't get a valid handle from the browser, don't try to Map (we're | 52 // If we don't get a valid handle from the browser, don't try to Map (we're |
38 // probably out of memory or file handles). | 53 // probably out of memory or file handles). |
39 bool valid_handle = base::SharedMemory::IsHandleValid( | 54 bool valid_handle = base::SharedMemory::IsHandleValid( |
40 renderer_shared_memory_handle_); | 55 renderer_shared_memory_handle_); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 // gamepads so this is sufficient. | 115 // gamepads so this is sufficient. |
101 for (unsigned i = 0; i < blink::WebGamepads::itemsLengthCap; i++) | 116 for (unsigned i = 0; i < blink::WebGamepads::itemsLengthCap; i++) |
102 gamepads.items[i].connected = false; | 117 gamepads.items[i].connected = false; |
103 } | 118 } |
104 } | 119 } |
105 | 120 |
106 GamepadSharedMemoryReader::~GamepadSharedMemoryReader() { | 121 GamepadSharedMemoryReader::~GamepadSharedMemoryReader() { |
107 StopIfObserving(); | 122 StopIfObserving(); |
108 } | 123 } |
109 | 124 |
110 bool GamepadSharedMemoryReader::OnControlMessageReceived( | 125 void GamepadSharedMemoryReader::GamepadConnected( |
111 const IPC::Message& message) { | |
112 bool handled = true; | |
113 IPC_BEGIN_MESSAGE_MAP(GamepadSharedMemoryReader, message) | |
114 IPC_MESSAGE_HANDLER(GamepadMsg_GamepadConnected, OnGamepadConnected) | |
115 IPC_MESSAGE_HANDLER(GamepadMsg_GamepadDisconnected, OnGamepadDisconnected) | |
116 IPC_MESSAGE_UNHANDLED(handled = false) | |
117 IPC_END_MESSAGE_MAP() | |
118 return handled; | |
119 } | |
120 | |
121 void GamepadSharedMemoryReader::OnGamepadConnected( | |
122 int index, | 126 int index, |
123 const blink::WebGamepad& gamepad) { | 127 const blink::WebGamepad& gamepad) { |
124 // The browser already checks if the user actually interacted with a device. | 128 // The browser already checks if the user actually interacted with a device. |
125 ever_interacted_with_ = true; | 129 ever_interacted_with_ = true; |
126 | 130 |
127 if (listener()) | 131 if (listener()) |
128 listener()->didConnectGamepad(index, gamepad); | 132 listener()->didConnectGamepad(index, gamepad); |
129 } | 133 } |
130 | 134 |
131 void GamepadSharedMemoryReader::OnGamepadDisconnected( | 135 void GamepadSharedMemoryReader::GamepadDisconnected( |
132 int index, | 136 int index, |
133 const blink::WebGamepad& gamepad) { | 137 const blink::WebGamepad& gamepad) { |
134 if (listener()) | 138 if (listener()) |
135 listener()->didDisconnectGamepad(index, gamepad); | 139 listener()->didDisconnectGamepad(index, gamepad); |
136 } | 140 } |
137 | 141 |
138 } // namespace content | 142 } // namespace content |
OLD | NEW |