Index: content/browser/gamepad/gamepad_provider.cc |
diff --git a/content/browser/gamepad/gamepad_provider.cc b/content/browser/gamepad/gamepad_provider.cc |
index 16976d965385f4d7ba005e1779d6a6d36e132b64..caa4cc82c667fb10707360250194af33e9fabbd8 100644 |
--- a/content/browser/gamepad/gamepad_provider.cc |
+++ b/content/browser/gamepad/gamepad_provider.cc |
@@ -175,8 +175,7 @@ bool GamepadProvider::PadState::Match(const WebGamepad& pad) const { |
} |
void GamepadProvider::PadState::SetPad(const WebGamepad& pad) { |
- DCHECK(pad.connected); |
- connected_ = true; |
+ connected_ = pad.connected; |
axes_length_ = pad.axesLength; |
buttons_length_ = pad.buttonsLength; |
memcpy(id_, pad.id, arraysize(id_)); |
@@ -230,8 +229,6 @@ void GamepadProvider::DoPoll() { |
hwbuf->sequence.WriteEnd(); |
} |
- CheckForUserGesture(); |
- |
if (ever_had_user_gesture_) { |
for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
WebGamepad& pad = hwbuf->buffer.items[i]; |
@@ -249,6 +246,8 @@ void GamepadProvider::DoPoll() { |
} |
} |
+ CheckForUserGesture(); |
+ |
// Schedule our next interval of polling. |
ScheduleDoPoll(); |
} |
@@ -308,7 +307,9 @@ void GamepadProvider::CheckForUserGesture() { |
if (user_gesture_observers_.empty() && ever_had_user_gesture_) |
return; |
- if (GamepadsHaveUserGesture(SharedMemoryAsHardwareBuffer()->buffer)) { |
+ bool had_gesture_before = ever_had_user_gesture_; |
+ const WebGamepads& pads = SharedMemoryAsHardwareBuffer()->buffer; |
+ if (GamepadsHaveUserGesture(pads)) { |
ever_had_user_gesture_ = true; |
for (size_t i = 0; i < user_gesture_observers_.size(); i++) { |
user_gesture_observers_[i].message_loop->PostTask(FROM_HERE, |
@@ -316,6 +317,12 @@ void GamepadProvider::CheckForUserGesture() { |
} |
user_gesture_observers_.clear(); |
} |
+ if (!had_gesture_before && ever_had_user_gesture_) { |
+ // Initialize pad_states_ for the first time. |
+ for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
+ pad_states_.get()[i].SetPad(pads.items[i]); |
+ } |
+ } |
} |
} // namespace content |