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

Unified Diff: content/browser/gamepad/gamepad_provider.cc

Issue 362123002: Gamepad: don't notify about connected pads twice (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more build fix (kNumberOfGamepads) Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/gamepad/gamepad_provider_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | content/browser/gamepad/gamepad_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698