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

Side by Side Diff: content/browser/gamepad/gamepad_provider.cc

Issue 1028673002: Fix use of arraysize in GamepadProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed to simpler sizeof() Created 5 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <cmath> 5 #include <cmath>
6 #include <set> 6 #include <set>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 void GamepadProvider::SendPauseHint(bool paused) { 164 void GamepadProvider::SendPauseHint(bool paused) {
165 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); 165 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop());
166 if (data_fetcher_) 166 if (data_fetcher_)
167 data_fetcher_->PauseHint(paused); 167 data_fetcher_->PauseHint(paused);
168 } 168 }
169 169
170 bool GamepadProvider::PadState::Match(const WebGamepad& pad) const { 170 bool GamepadProvider::PadState::Match(const WebGamepad& pad) const {
171 return connected_ == pad.connected && 171 return connected_ == pad.connected &&
172 axes_length_ == pad.axesLength && 172 axes_length_ == pad.axesLength &&
173 buttons_length_ == pad.buttonsLength && 173 buttons_length_ == pad.buttonsLength &&
174 memcmp(id_, pad.id, arraysize(id_)) == 0 && 174 memcmp(id_, pad.id, sizeof(id_)) == 0 &&
175 memcmp(mapping_, pad.mapping, arraysize(mapping_)) == 0; 175 memcmp(mapping_, pad.mapping, sizeof(mapping_)) == 0;
176 } 176 }
177 177
178 void GamepadProvider::PadState::SetPad(const WebGamepad& pad) { 178 void GamepadProvider::PadState::SetPad(const WebGamepad& pad) {
179 connected_ = pad.connected; 179 connected_ = pad.connected;
180 axes_length_ = pad.axesLength; 180 axes_length_ = pad.axesLength;
181 buttons_length_ = pad.buttonsLength; 181 buttons_length_ = pad.buttonsLength;
182 memcpy(id_, pad.id, arraysize(id_)); 182 memcpy(id_, pad.id, sizeof(id_));
183 memcpy(mapping_, pad.mapping, arraysize(mapping_)); 183 memcpy(mapping_, pad.mapping, sizeof(mapping_));
184 } 184 }
185 185
186 void GamepadProvider::PadState::SetDisconnected() { 186 void GamepadProvider::PadState::SetDisconnected() {
187 connected_ = false; 187 connected_ = false;
188 axes_length_ = 0; 188 axes_length_ = 0;
189 buttons_length_ = 0; 189 buttons_length_ = 0;
190 memset(id_, 0, arraysize(id_)); 190 memset(id_, 0, sizeof(id_));
191 memset(mapping_, 0, arraysize(mapping_)); 191 memset(mapping_, 0, sizeof(mapping_));
192 } 192 }
193 193
194 void GamepadProvider::PadState::AsWebGamepad(WebGamepad* pad) { 194 void GamepadProvider::PadState::AsWebGamepad(WebGamepad* pad) {
195 pad->connected = connected_; 195 pad->connected = connected_;
196 pad->axesLength = axes_length_; 196 pad->axesLength = axes_length_;
197 pad->buttonsLength = buttons_length_; 197 pad->buttonsLength = buttons_length_;
198 memcpy(pad->id, id_, arraysize(id_)); 198 memcpy(pad->id, id_, sizeof(id_));
199 memcpy(pad->mapping, mapping_, arraysize(mapping_)); 199 memcpy(pad->mapping, mapping_, sizeof(mapping_));
200 memset(pad->axes, 0, arraysize(pad->axes)); 200 memset(pad->axes, 0, sizeof(pad->axes));
201 memset(pad->buttons, 0, arraysize(pad->buttons)); 201 memset(pad->buttons, 0, sizeof(pad->buttons));
202 } 202 }
203 203
204 void GamepadProvider::DoPoll() { 204 void GamepadProvider::DoPoll() {
205 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); 205 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop());
206 DCHECK(have_scheduled_do_poll_); 206 DCHECK(have_scheduled_do_poll_);
207 have_scheduled_do_poll_ = false; 207 have_scheduled_do_poll_ = false;
208 208
209 bool changed; 209 bool changed;
210 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); 210 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer();
211 211
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } 320 }
321 if (!had_gesture_before && ever_had_user_gesture_) { 321 if (!had_gesture_before && ever_had_user_gesture_) {
322 // Initialize pad_states_ for the first time. 322 // Initialize pad_states_ for the first time.
323 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) { 323 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) {
324 pad_states_.get()[i].SetPad(pads.items[i]); 324 pad_states_.get()[i].SetPad(pads.items[i]);
325 } 325 }
326 } 326 }
327 } 327 }
328 328
329 } // namespace content 329 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698