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 "device/gamepad/gamepad_service.h" | 5 #include "device/gamepad/gamepad_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 101 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
102 provider_->RegisterForUserGesture(closure); | 102 provider_->RegisterForUserGesture(closure); |
103 } | 103 } |
104 | 104 |
105 void GamepadService::Terminate() { | 105 void GamepadService::Terminate() { |
106 provider_.reset(); | 106 provider_.reset(); |
107 } | 107 } |
108 | 108 |
109 void GamepadService::OnGamepadConnectionChange(bool connected, | 109 void GamepadService::OnGamepadConnectionChange(bool connected, |
110 int index, | 110 int index, |
111 const blink::WebGamepad& pad) { | 111 const Gamepad& pad) { |
112 if (connected) { | 112 if (connected) { |
113 main_thread_task_runner_->PostTask( | 113 main_thread_task_runner_->PostTask( |
114 FROM_HERE, base::Bind(&GamepadService::OnGamepadConnected, | 114 FROM_HERE, base::Bind(&GamepadService::OnGamepadConnected, |
115 base::Unretained(this), index, pad)); | 115 base::Unretained(this), index, pad)); |
116 } else { | 116 } else { |
117 main_thread_task_runner_->PostTask( | 117 main_thread_task_runner_->PostTask( |
118 FROM_HERE, base::Bind(&GamepadService::OnGamepadDisconnected, | 118 FROM_HERE, base::Bind(&GamepadService::OnGamepadDisconnected, |
119 base::Unretained(this), index, pad)); | 119 base::Unretained(this), index, pad)); |
120 } | 120 } |
121 } | 121 } |
122 | 122 |
123 void GamepadService::OnGamepadConnected(int index, | 123 void GamepadService::OnGamepadConnected(int index, const Gamepad& pad) { |
124 const blink::WebGamepad& pad) { | |
125 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 124 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
126 | 125 |
127 for (ConsumerSet::iterator it = consumers_.begin(); it != consumers_.end(); | 126 for (ConsumerSet::iterator it = consumers_.begin(); it != consumers_.end(); |
128 ++it) { | 127 ++it) { |
129 if (it->did_observe_user_gesture && it->is_active) | 128 if (it->did_observe_user_gesture && it->is_active) |
130 it->consumer->OnGamepadConnected(index, pad); | 129 it->consumer->OnGamepadConnected(index, pad); |
131 } | 130 } |
132 } | 131 } |
133 | 132 |
134 void GamepadService::OnGamepadDisconnected(int index, | 133 void GamepadService::OnGamepadDisconnected(int index, const Gamepad& pad) { |
135 const blink::WebGamepad& pad) { | |
136 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 134 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
137 | 135 |
138 for (ConsumerSet::iterator it = consumers_.begin(); it != consumers_.end(); | 136 for (ConsumerSet::iterator it = consumers_.begin(); it != consumers_.end(); |
139 ++it) { | 137 ++it) { |
140 if (it->did_observe_user_gesture && it->is_active) | 138 if (it->did_observe_user_gesture && it->is_active) |
141 it->consumer->OnGamepadDisconnected(index, pad); | 139 it->consumer->OnGamepadDisconnected(index, pad); |
142 } | 140 } |
143 } | 141 } |
144 | 142 |
145 base::SharedMemoryHandle GamepadService::GetSharedMemoryHandleForProcess( | 143 base::SharedMemoryHandle GamepadService::GetSharedMemoryHandleForProcess( |
(...skipping 13 matching lines...) Expand all Loading... |
159 gesture_callback_pending_ = false; | 157 gesture_callback_pending_ = false; |
160 | 158 |
161 if (!provider_ || num_active_consumers_ == 0) | 159 if (!provider_ || num_active_consumers_ == 0) |
162 return; | 160 return; |
163 | 161 |
164 for (ConsumerSet::iterator it = consumers_.begin(); it != consumers_.end(); | 162 for (ConsumerSet::iterator it = consumers_.begin(); it != consumers_.end(); |
165 ++it) { | 163 ++it) { |
166 if (!it->did_observe_user_gesture && it->is_active) { | 164 if (!it->did_observe_user_gesture && it->is_active) { |
167 const ConsumerInfo& info = *it; | 165 const ConsumerInfo& info = *it; |
168 info.did_observe_user_gesture = true; | 166 info.did_observe_user_gesture = true; |
169 blink::WebGamepads gamepads; | 167 Gamepads gamepads; |
170 provider_->GetCurrentGamepadData(&gamepads); | 168 provider_->GetCurrentGamepadData(&gamepads); |
171 for (unsigned i = 0; i < blink::WebGamepads::kItemsLengthCap; ++i) { | 169 for (unsigned i = 0; i < Gamepads::kItemsLengthCap; ++i) { |
172 const blink::WebGamepad& pad = gamepads.items[i]; | 170 const Gamepad& pad = gamepads.items[i]; |
173 if (pad.connected) | 171 if (pad.connected) |
174 info.consumer->OnGamepadConnected(i, pad); | 172 info.consumer->OnGamepadConnected(i, pad); |
175 } | 173 } |
176 } | 174 } |
177 } | 175 } |
178 } | 176 } |
179 | 177 |
180 void GamepadService::SetSanitizationEnabled(bool sanitize) { | 178 void GamepadService::SetSanitizationEnabled(bool sanitize) { |
181 provider_->SetSanitizationEnabled(sanitize); | 179 provider_->SetSanitizationEnabled(sanitize); |
182 } | 180 } |
183 | 181 |
184 } // namespace device | 182 } // namespace device |
OLD | NEW |