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

Side by Side Diff: device/gamepad/gamepad_provider.cc

Issue 2123653003: Remove calls to MessageLoop::current() in content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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 | « content/renderer/render_thread_impl.cc ('k') | 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 "device/gamepad/gamepad_provider.h" 5 #include "device/gamepad/gamepad_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 #include <cmath> 9 #include <cmath>
10 #include <set> 10 #include <set>
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 #endif 152 #endif
153 polling_thread_->StartWithOptions(base::Thread::Options(kMessageLoopType, 0)); 153 polling_thread_->StartWithOptions(base::Thread::Options(kMessageLoopType, 0));
154 154
155 polling_thread_->task_runner()->PostTask( 155 polling_thread_->task_runner()->PostTask(
156 FROM_HERE, base::Bind(&GamepadProvider::DoInitializePollingThread, 156 FROM_HERE, base::Bind(&GamepadProvider::DoInitializePollingThread,
157 base::Unretained(this), base::Passed(&fetcher))); 157 base::Unretained(this), base::Passed(&fetcher)));
158 } 158 }
159 159
160 void GamepadProvider::DoInitializePollingThread( 160 void GamepadProvider::DoInitializePollingThread(
161 std::unique_ptr<GamepadDataFetcher> fetcher) { 161 std::unique_ptr<GamepadDataFetcher> fetcher) {
162 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); 162 DCHECK(polling_thread_->task_runner()->BelongsToCurrentThread());
163 DCHECK(!data_fetcher_.get()); // Should only initialize once. 163 DCHECK(!data_fetcher_.get()); // Should only initialize once.
164 164
165 if (!fetcher) 165 if (!fetcher)
166 fetcher.reset(new GamepadPlatformDataFetcher); 166 fetcher.reset(new GamepadPlatformDataFetcher);
167 data_fetcher_ = std::move(fetcher); 167 data_fetcher_ = std::move(fetcher);
168 } 168 }
169 169
170 void GamepadProvider::SendPauseHint(bool paused) { 170 void GamepadProvider::SendPauseHint(bool paused) {
171 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); 171 DCHECK(polling_thread_->task_runner()->BelongsToCurrentThread());
172 if (data_fetcher_) 172 if (data_fetcher_)
173 data_fetcher_->PauseHint(paused); 173 data_fetcher_->PauseHint(paused);
174 } 174 }
175 175
176 bool GamepadProvider::PadState::Match(const WebGamepad& pad) const { 176 bool GamepadProvider::PadState::Match(const WebGamepad& pad) const {
177 return connected_ == pad.connected && axes_length_ == pad.axesLength && 177 return connected_ == pad.connected && axes_length_ == pad.axesLength &&
178 buttons_length_ == pad.buttonsLength && 178 buttons_length_ == pad.buttonsLength &&
179 memcmp(id_, pad.id, sizeof(id_)) == 0 && 179 memcmp(id_, pad.id, sizeof(id_)) == 0 &&
180 memcmp(mapping_, pad.mapping, sizeof(mapping_)) == 0; 180 memcmp(mapping_, pad.mapping, sizeof(mapping_)) == 0;
181 } 181 }
(...skipping 18 matching lines...) Expand all
200 pad->connected = connected_; 200 pad->connected = connected_;
201 pad->axesLength = axes_length_; 201 pad->axesLength = axes_length_;
202 pad->buttonsLength = buttons_length_; 202 pad->buttonsLength = buttons_length_;
203 memcpy(pad->id, id_, sizeof(id_)); 203 memcpy(pad->id, id_, sizeof(id_));
204 memcpy(pad->mapping, mapping_, sizeof(mapping_)); 204 memcpy(pad->mapping, mapping_, sizeof(mapping_));
205 memset(pad->axes, 0, sizeof(pad->axes)); 205 memset(pad->axes, 0, sizeof(pad->axes));
206 memset(pad->buttons, 0, sizeof(pad->buttons)); 206 memset(pad->buttons, 0, sizeof(pad->buttons));
207 } 207 }
208 208
209 void GamepadProvider::DoPoll() { 209 void GamepadProvider::DoPoll() {
210 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); 210 DCHECK(polling_thread_->task_runner()->BelongsToCurrentThread());
211 DCHECK(have_scheduled_do_poll_); 211 DCHECK(have_scheduled_do_poll_);
212 have_scheduled_do_poll_ = false; 212 have_scheduled_do_poll_ = false;
213 213
214 bool changed; 214 bool changed;
215 215
216 ANNOTATE_BENIGN_RACE_SIZED(gamepad_shared_buffer_->buffer(), 216 ANNOTATE_BENIGN_RACE_SIZED(gamepad_shared_buffer_->buffer(),
217 sizeof(WebGamepads), "Racey reads are discarded"); 217 sizeof(WebGamepads), "Racey reads are discarded");
218 218
219 { 219 {
220 base::AutoLock lock(devices_changed_lock_); 220 base::AutoLock lock(devices_changed_lock_);
(...skipping 28 matching lines...) Expand all
249 } 249 }
250 } 250 }
251 251
252 CheckForUserGesture(); 252 CheckForUserGesture();
253 253
254 // Schedule our next interval of polling. 254 // Schedule our next interval of polling.
255 ScheduleDoPoll(); 255 ScheduleDoPoll();
256 } 256 }
257 257
258 void GamepadProvider::ScheduleDoPoll() { 258 void GamepadProvider::ScheduleDoPoll() {
259 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); 259 DCHECK(polling_thread_->task_runner()->BelongsToCurrentThread());
260 if (have_scheduled_do_poll_) 260 if (have_scheduled_do_poll_)
261 return; 261 return;
262 262
263 { 263 {
264 base::AutoLock lock(is_paused_lock_); 264 base::AutoLock lock(is_paused_lock_);
265 if (is_paused_) 265 if (is_paused_)
266 return; 266 return;
267 } 267 }
268 268
269 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 269 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 302 }
303 if (!had_gesture_before && ever_had_user_gesture_) { 303 if (!had_gesture_before && ever_had_user_gesture_) {
304 // Initialize pad_states_ for the first time. 304 // Initialize pad_states_ for the first time.
305 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) { 305 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) {
306 pad_states_.get()[i].SetPad(pads->items[i]); 306 pad_states_.get()[i].SetPad(pads->items[i]);
307 } 307 }
308 } 308 }
309 } 309 }
310 310
311 } // namespace device 311 } // namespace device
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698